16

我想在通话过程中在该屏幕上显示一些信息,例如天气信息或类似的 Facebook 更新,任何人都可以帮助我。

请参阅下面我想要的更新的屏幕截图。

在此处输入图像描述

4

1 回答 1

21

检查此堆栈溢出答案。在该答案中,您可以看到一个显示不同调用状态的 toast。而不是那个 toast 制作一个自定义 toast 并通过该自定义 toast 显示您的更新。

如果您想显示活动而不是 toast,请在您的 CustomPhoneStateListener 中尝试此代码

 public class CustomPhoneStateListener extends PhoneStateListener {

      ActivityManager activityManager;
      Intent i1;
      public CustomPhoneStateListener(Context context) {
          super();
          this.context = context;
          i1 = new Intent(context, TelephoneyWithoutToastActivity.class);
          i1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      }

      @Override
      public void onCallStateChanged(int state, String incomingNumber) {
          super.onCallStateChanged(state, incomingNumber);

          switch (state) {
          case TelephonyManager.CALL_STATE_IDLE:
              //when Idle i.e no call
              Toast.makeText(context, "Phone state Idle", Toast.LENGTH_LONG).show();

              break;
          case TelephonyManager.CALL_STATE_OFFHOOK:

              //when Off hook i.e in call
              //Make intent and start your service here
              Toast.makeText(context, "Phone state Off hook", Toast.LENGTH_LONG).show();

              break;
          case TelephonyManager.CALL_STATE_RINGING:

              ActivityManager localActivityManager = (ActivityManager) this.context.getSystemService("activity");
              for (String str = ((ActivityManager.RunningTaskInfo) localActivityManager.getRunningTasks(1).get(0)).topActivity.flattenToString();; str = ((ActivityManager.RunningTaskInfo) localActivityManager.getRunningTasks(1).get(0)).topActivity.flattenToString()) {
                  if ((!str.contains("com.android.phone.InCallScreen")))
                      continue;
                  Log.d("IncomingCallPlus", "*****************************************************");   
                  context.startActivity(i1);
                  return;
              }    

          default:
              break;
          }
      }    
  }

将此添加到您的活动中以激活默认呼叫屏幕上的触摸。

getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);

此功能将触摸来电屏幕和弹出窗口

public void addInvitePopup(final String number, Context c) {

    //check if pref is ok with invite in call
    // if(!Preferences.getInstance(c.getInviteInCall())){return ; }
    // sets the WindowManager

    WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        LayoutParams.WRAP_CONTENT,
        LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_SYSTEM_ALERT |
        WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
        PixelFormat.TRANSLUCENT);
    params.x = 250;
    params.height = LayoutParams.WRAP_CONTENT;
    params.width = LayoutParams.WRAP_CONTENT;
    params.format = PixelFormat.TRANSLUCENT;
    final Context ct = c;

    params.gravity = Gravity.TOP;
    params.setTitle("Testing");

    LinearLayout ly = new LinearLayout(c);
    ly.setOrientation(LinearLayout.VERTICAL);

    Button inviteButton = new Button(c);
    inviteButton.setClickable(true);
    inviteButton.setBackgroundDrawable(c.getResources().getDrawable(R.drawable.ic_launcher));

    inviteButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(v.getContext(), "adding to blacklist..", Toast.LENGTH_LONG).show();
            v.setBackgroundDrawable(ct.getResources().getDrawable(R.drawable.images));
            v.setClickable(false);
            // sendMessage(v, number);

            //Track this event:
            //MixPanelTracking.setPropKeyValue(getApplicationContext(), null, null, "Add friend - During Call");
        }
    });

    inviteButton.setWidth(30);
    inviteButton.setHeight(30);
    //   inviteButton.setLayoutParams(WindowManager.LayoutParams.WRAP_CONTENT,
    //   WindowManager.LayoutParams.WRAP_CONTENT);


    ly.addView(inviteButton);

    wm.addView(ly, params);
    // wm.addView( inviteButton, params);
    Log.i("TTT", "after add view");
}

在清单文件中添加此权限

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
于 2012-05-21T11:00:42.540 回答