2

我正在尝试在拨出呼叫屏幕上添加按钮或选项菜单我已经尝试过此代码,但它显示致命错误请验证代码

public class CustomOutgoingCallActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    IntentFilter filter = new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL);
    filter.addAction(Intent.ACTION_NEW_OUTGOING_CALL);
    BroadcastReceiver mReceiver = new OutgoingReciver();
    registerReceiver(mReceiver, filter);

}

公共类 OutgoingReciver 扩展 BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    if (bundle == null)
        return;
    String phoneNumber = null;

    // Incoming call
    String state = bundle.getString(TelephonyManager.EXTRA_STATE);
    if ((state != null)
            && (state
                    .equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))) {
        phoneNumber = bundle
                .getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
        System.out.println("in coming number :-" + phoneNumber);
        LinearLayout ll = new LinearLayout(context);

        Button btnTag = new Button(context);
        btnTag.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        btnTag.setText("phone No " + phoneNumber);
        btnTag.setId(1);
        ll.addView(btnTag);

    }
    // Outgoing call
    else if (state == null) {
        phoneNumber = bundle.getString(Intent.EXTRA_PHONE_NUMBER);
        System.out.println(" out going number :-" + phoneNumber);
          LinearLayout ll = new LinearLayout(context);

          Button btnTag = new Button(context); btnTag.setLayoutParams(new
          LayoutParams(LayoutParams.WRAP_CONTENT,
          LayoutParams.WRAP_CONTENT)); btnTag.setText("phone No " +
          phoneNumber); btnTag.setId(111111);
        ll.addView(btnTag);

    }
}

堆栈跟踪

09-26 10:46:20.255: I/System.out(274):  out going number :-7875851207
09-26 10:46:57.076: E/ActivityThread(274): Activity com.cssl.core.CustomOutgoingCallActivity has leaked IntentReceiver com.cssl.core.OutgoingReciver@44ee7610 that was originally registered here. Are you missing a call to unregisterReceiver()?
09-26 10:46:57.076: E/ActivityThread(274): android.app.IntentReceiverLeaked: Activity com.cssl.core.CustomOutgoingCallActivity has leaked IntentReceiver com.cssl.core.OutgoingReciver@44ee7610 that was originally registered here. Are you missing a call to unregisterReceiver()?
09-26 10:46:57.076: E/ActivityThread(274):     at android.app.ActivityThread$PackageInfo$ReceiverDispatcher.<init>(ActivityThread.java:939)
09-26 10:46:57.076: E/ActivityThread(274):     at android.app.ActivityThread$PackageInfo.getReceiverDispatcher(ActivityThread.java:734)
09-26 10:46:57.076: E/ActivityThread(274):     at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:791)
09-26 10:46:57.076: E/ActivityThread(274):     at android.app.ContextImpl.registerReceiver(ContextImpl.java:778)
09-26 10:46:57.076: E/ActivityThread(274):     at android.app.ContextImpl.registerReceiver(ContextImpl.java:772)
09-26 10:46:57.076: E/ActivityThread(274):     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:318)
09-26 10:46:57.076: E/ActivityThread(274):     at com.cssl.core.CustomOutgoingCallActivity.onCreate(CustomOutgoingCallActivity.java:18)
09-26 10:46:57.076: E/ActivityThread(274):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-26 10:46:57.076: E/ActivityThread(274):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-26 10:46:57.076: E/ActivityThread(274):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-26 10:46:57.076: E/ActivityThread(274):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-26 10:46:57.076: E/ActivityThread(274):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-26 10:46:57.076: E/ActivityThread(274):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 10:46:57.076: E/ActivityThread(274):     at android.os.Looper.loop(Looper.java:123)
09-26 10:46:57.076: E/ActivityThread(274):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-26 10:46:57.076: E/ActivityThread(274):     at java.lang.reflect.Method.invokeNative(Native Method)
09-26 10:46:57.076: E/ActivityThread(274):     at java.lang.reflect.Method.invoke(Method.java:521)
09-26 10:46:57.076: E/ActivityThread(274):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-26 10:46:57.076: E/ActivityThread(274):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-26 10:46:57.076: E/ActivityThread(274):     at dalvik.system.NativeStart.main(Native Method)
09-26 10:47:02.566: W/IInputConnectionWrapper(274): showStatusIcon on inactive InputConnection
09-26 10:47:08.676: I/System.out(274):  out going number :-0377778888
09-26 10:47:25.496: D/dalvikvm(274): GC_EXPLICIT freed 1681 objects / 127448 bytes in 210ms
4

0 回答 0