Android:OutComing通话时的Toast

时间:2010-12-28 11:43:03

标签: android call broadcastreceiver

我正在尝试在互联网上找到这个代码...它应该使用BroadcastReceiver为OutComing呼叫事件显示祝酒,但在我的htc纹身上使用Android 1.6它不起作用(它不显示任何吐司)< / p>

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"/>

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

将意图过滤器更改为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();

}

这是传入的msg相应更改它和example here