微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 从侦听传出呼叫的广播接收器启动活动

我试图从收听5556的传出呼叫的广播接收器发起一个活动.问题是,活动没有启动但是正在调用拨号内置活动,我已将意图的优先级更改为100但是无济于事.如何让活动在拨号时启动而不是内置的呼叫活动?
这是代码
package com.messageHider;

import android.content.broadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class launchReceiver extends broadcastReceiver {
    @Override
    public void onReceive(Context context,Intent intent) {
        String number=intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        String compare_num="5556";
        if(number.equals(compare_num))
        {
            Intent myintent=new Intent(context,messageHider.class);
            myintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(myintent);
            abortbroadcast();
        }
    }

}

清单文件

<receiver android:name=".launchReceiver">
    <intent-filter android:priority="0">
        <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
    </intent-filter>
</receiver>

解决方法

在您的清单中,您需要一个权限(根据文档):

You must hold the PROCESS_OUTGOING_CALLS permission to receive this
Intent.

那就是

"android.permission.PROCESS_OUTGOING_CALLS"

也直接来自文档:

Any broadcastReceiver receiving this Intent must not abort the broadcast.

以下是我获取信息页面链接

http://developer.android.com/reference/android/content/Intent.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐