【问题标题】:Android: A Toast when OutComing callAndroid:来电时祝酒
【发布时间】:2010-12-28 11:43:03
【问题描述】:

我正在尝试在互联网上找到此代码...它应该使用 BroadcastReceiver 显示 OutComing 呼叫事件的祝酒词,但在我的 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();
 }
}

当然,我已经在我的 Manifest 上注册了 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"/>

有什么想法吗?

【问题讨论】:

  • 据我所知,我的问题缺少部分,所以这是清单中的接收器: 这是权限:
  • 已编辑。他们现在在这里。不要忘记在编辑字段上方使用花括号图标来改进代码的格式。
  • 你调用 registerreceiver() 了吗?

标签: android call broadcastreceiver


【解决方案1】:

将意图过滤器更改为 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 中实现一个意图过滤器

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();

}

这是为传入的消息相应地更改它和example here

【讨论】:

  • 是的,这是我的原始来源
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-27
  • 2023-03-07
相关资源
最近更新 更多