我正在尝试在用户使用标准 android 拨号器调用电话时显示一条消息。
我的 Activity 中有以下代码
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTestButtonListener();
Log.i(LOG_TAG, "Activity started...");
}
private void setTestButtonListener()
{
Button testButton = (Button)this.findViewById(R.id.testButton);
testButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Log.i(LOG_TAG, "Clicked on test...");
Toast.makeText(getApplicationContext(), (CharSequence)"You clicked on the test button" ,Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+150));
MainActivity.this.sendOrderedBroadcast(intent, null);
MainActivity.this.startActivity(intent);
Log.i(LOG_TAG, "intent broadcasted... I think... ");
}
});
}
然后在 BroadcastReceiver(以及派生自它的类)中:
public class OnMakingCallReceiver extends BroadcastReceiver
{
private static final String LOG_TAG = OnMakingCallReceiver.class.getSimpleName() + "_LOG";
@Override
public void onReceive(Context context,Intent intent)
{
Log.i(LOG_TAG, " got here!");
}
}
然后在AndroidManifest.xml
<uses-permission android:name="android.permission.CALL_PHONE" />
<receiver android:name=".OnMakingCallReceiver" android:priority="999">
<intent-filter>
<action android:name="android.intent.action.CALL"/>
</intent-filter>
</receiver>
我点击测试按钮,我看到了这个输出。
点击测试... Intent 广播...我认为...
仅此而已。我希望看到“到了这里!”。
我为什么不这样做有什么想法吗?
最佳答案
您是否在 AndroidManifest.xml 中定义了接收器?
此外,当您点击直接转到拨号器的内容时,会发送 ACTION_CALL_BUTTON。你确定你正在这样做吗?
关于java - 广播接收器未收到 Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13502210/