Android:拨出电话时的 Toast
我正在尝试在互联网上找到的这段代码...它应该使用 BroadcastReceiver 显示呼出呼叫事件的祝酒词,但在我的 Android 1.6 的 htc 纹身上它不起作用(它不显示任何祝酒词)
public class HFBroadcastOutComingRecevier extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Phone Event", Toast.LENGTH_SHORT).show();
Bundle bundle = intent.getExtras();
if(null == bundle)
return;
String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
String info = "Detect Calls sample application\nOutgoing number: " + phonenumber;
Toast.makeText(context, info, Toast.LENGTH_LONG).show();
}
}
自然我已经在我的清单上将 BroadcastReceiver 注册为:
<receiver android:name=".HFBroadcastIncomingRecevier">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
并具有以下权限:
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
有什么想法吗?
i'm trying this code found on internet...it should show a toast for OutComing call event using a BroadcastReceiver but on my htc tattoo with Android 1.6 it doesn't works (it don't show any toast)
public class HFBroadcastOutComingRecevier extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Phone Event", Toast.LENGTH_SHORT).show();
Bundle bundle = intent.getExtras();
if(null == bundle)
return;
String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
String info = "Detect Calls sample application\nOutgoing number: " + phonenumber;
Toast.makeText(context, info, Toast.LENGTH_LONG).show();
}
}
Naturally i've registered the BroadcastReceiver on my Manifest as:
<receiver android:name=".HFBroadcastIncomingRecevier">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
and with this permissions:
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将意图过滤器更改为 ACTION_NEW_OUTGOING_CALL
如果这不起作用,还可以在您的 onReceive 中实现一个 Intent 过滤器
}
这是针对传入的消息进行相应的更改,并且 这里是示例
Change intent filter to ACTION_NEW_OUTGOING_CALL
And if this doesnt work also implement an intent filter in your onReceive
}
This is for incoming msg change it accordingly and an example here