拨号键接收广播特殊使用用法

拨号键使用暗码进行相关调试用例:
1 在AndroidManifest.xml中添加:

<receiver android:name="com.android.settings.MyReceiver" >
    <intent-filter>
        <action android:name="android.provider.Telephony.SECRET_CODE" />
        <data
            android:host="2846000"
            android:scheme="android_secret_code" />
    </intent-filter>
</receiver>

其中android:host=“2846000” 设置暗码

2 新建一个广播接收的类

public class MyReceiver extends BroadcastReceiver {
    private final String TAG = "MyReceiver";
    Uri engineerUri = Uri.parse("android_secret_code://2846000");
    @Override
    public void onReceive(Context context, Intent intent) {
        try {
            if (intent.getAction().equals("android.provider.Telephony.SECRET_CODE")) {
                Uri uri = intent.getData();
                if (uri.equals(engineerUri)) {
                    // TODO 这里处理相关事情,可以打开一个app界面什么的,或者其他
                }
            }
        }
    }
}
发布了70 篇原创文章 · 获赞 24 · 访问量 8250

猜你喜欢

转载自blog.csdn.net/angelsmiling/article/details/104714827
今日推荐