我试图从收听5556的传出呼叫的广播接收器发起一个活动.问题是,活动没有启动但是正在调用拨号内置活动,我已将意图的优先级更改为100但是无济于事.如何让活动在拨号时启动而不是内置的呼叫活动?
这是代码:
这是代码:
package com.messageHider; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.widget.Toast; public class launchReceiver extends BroadcastReceiver { @Override public void onReceive(Context context,Intent intent) { String number=intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); String compare_num="5556"; if(number.equals(compare_num)) { Intent myintent=new Intent(context,messageHider.class); myintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(myintent); abortBroadcast(); } } }
清单文件:
<receiver android:name=".launchReceiver"> <intent-filter android:priority="0"> <action android:name="android.intent.action.NEW_OUTGOING_CALL"/> </intent-filter> </receiver>
解决方法
在您的清单中,您需要一个权限(根据文档):
You must hold the PROCESS_OUTGOING_CALLS permission to receive this
Intent.
那就是
"android.permission.PROCESS_OUTGOING_CALLS"
也直接来自文档:
Any BroadcastReceiver receiving this Intent must not abort the broadcast.
http://developer.android.com/reference/android/content/Intent.html