三星Galaxy S上未调用NEW_OUTGOING_CALL

5

尝试拦截外拨电话,已经在以下设备上成功实现:

  • nexus 1,安卓2.2系统
  • HTC desire,2.2系统
  • Moto defy,2.1系统

但是在运行2.1系统的三星Galaxy S上无法实现,有人遇到过这个问题吗?

 <receiver  android:name="com.mypackge.OutGoingCallDetection" 
    android:exported="true"> 
 <intent-filter>   
  <action
    android:name="android.intent.action.NEW_OUTGOING_CALL"
    android:priority="0" /> 
</intent-filter> 
</receiver>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> 

更新:已添加 PROCESS_OUTGOING_CALLS。
接收器:
public class OutGoingCallDetection extends BroadcastReceiver {

    private static final String TAG = "OutGoingCallDetection";


    @Override
    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();
        Log.d(TAG, "onReceive, Action:" +intent.getAction());
    }
}
4个回答

5

您需要添加用户权限:

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> 

请参考这篇博客文章,了解如何设置和使用NEW_OUTGOING_CALL。

同时,请参考这篇博客文章,了解如何设置android:priority


我拥有PROCESS_OUTGOING_CALLS权限(否则它在其他设备上不起作用)。在阅读Android博客文章后,我使用优先级0,但我会尝试不同的优先级并发布结果。谢谢。 - scottyab
很奇怪...我在许多三星Galaxy S设备上运行NEW_OUTGOING_CALL都没有问题,包括那些运行Android 2.1的设备也没有任何问题。 - Shane Powell
我的猜测是你的设备上安装了某些中止广播的程序,因此优先级较低的广播无法显示?所以,提高优先级并观察结果吧。 - Shane Powell

5
尝试按照Google Dev建议的顺序对清单进行排序:Manifest.xml 像这样:
<uses-permission />
...
<receiver>
    <intent-filter> . . . </intent-filter>
    <meta-data />
</receiver>

一些设备可能存在解析清单文件的问题,导致无法正确注册接收器。

编辑:从ADT 16开始,Lint会告诉您权限放错了位置,因此我认为这个问题比以前想象的更严重。

谢谢!


0

我通过编程方式创建了广播监听器。它可以正常工作。供您参考。

IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.NEW_OUTGOING_CALL");

receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.d(TAG, "onReceive, Action:" +intent.getAction());
    }
};
registerReceiver(receiver, filter);

0

你尝试过增加android:priority吗?比如说增加到10000。

我正在拦截传入的短信,并且增加android:priority属性是有帮助的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接