Android:拨出电话时的 Toast

发布于 2024-10-09 07:01:58 字数 1086 浏览 2 评论 0原文

我正在尝试在互联网上找到的这段代码...它应该使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷到爆炸 2024-10-16 07:01:58

将意图过滤器更改为 ACTION_NEW_OUTGOING_CALL

<receiver android:name=".YourClassName" android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
    </intent-filter>
</receiver>

如果这不起作用,还可以在您的 onReceive 中实现一个 Intent 过滤器

public void onReceive(Context context, Intent intent) 
{
    String mAction = intent.getAction();
    if(!mAction.equals("android.provider.Telephony.SMS_RECEIVED"))
        return;
    Toast.makeText(context, "Intent Received", Toast.LENGTH_LONG).show();

}

这是针对传入的消息进行相应的更改,并且 这里是示例

Change intent filter to ACTION_NEW_OUTGOING_CALL

<receiver android:name=".YourClassName" android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
    </intent-filter>
</receiver>

And if this doesnt work also implement an intent filter in your onReceive

public void onReceive(Context context, Intent intent) 
{
    String mAction = intent.getAction();
    if(!mAction.equals("android.provider.Telephony.SMS_RECEIVED"))
        return;
    Toast.makeText(context, "Intent Received", Toast.LENGTH_LONG).show();

}

This is for incoming msg change it accordingly and an example here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文