【发布时间】:2017-03-12 01:43:30
【问题描述】:
我已经构建了一个小应用程序。它唯一能做的就是接听一个拨出电话并在它发生时显示一些活动。只有一个Activity 和一个BroadcastReceiver。
我想将我的代码与另一个应用程序集成,我从 Manifest.xml 中删除了 BroadcastReceiver,并从主要活动中动态创建(并注册)它。我的接收器开火良好,但没有显示活动。
这两种方法有什么区别?
如何让活动显示出来?
来自MainActivity.java:
callInterceptor = new InterceptOutgoingCall();
IntentFilter callInterceptorIntentFilter = new IntentFilter("android.intent.action.NEW_OUTGOING_CALL");
callInterceptorIntentFilter.setPriority(100);
registerReceiver(callInterceptor, callInterceptorIntentFilter);
从函数receiver.onReceive(Context,Intent):
Intent alertIntent = new Intent(context, AlertActivity.class);
alertIntent.putExtra("callnumber", phonenbr);
alertIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(alertIntent);
我的活动在manifest 中声明如下:
<activity android:name=".AlertActivity"
android:screenOrientation="portrait"/>
【问题讨论】:
标签: android android-activity broadcastreceiver