通过Dialer拨号盘输暗码启动某个apk

通过拨号暗码 启动某个apk

首先\packages\apps\Dialer\src\com\android\dialer\SpecialCharSequenceMgr.java 定义了这个方法

/**
     * Handles secret codes to launch arbitrary activities in the form of *#*#<code>#*#*.
     * If a secret code is encountered an Intent is started with the android_secret_code://<code>
     * URI.
     *
     * @param context the context to use
     * @param input the text to check for a secret code in
     * @return true if a secret code was encountered
     */
    static boolean handleSecretCode(Context context, String input) {
        // Secret codes are in the form *#*#<code>#*#*
        int len = input.length();
        if (len > 8 && input.startsWith("*#*#") && input.endsWith("#*#*")) {
            final Intent intent = new Intent(SECRET_CODE_ACTION,
                    Uri.parse("android_secret_code://" + input.substring(4, len - 4)));
            context.sendBroadcast(intent);
            return true;
        }


        return false;
    }

构建一个EMStartReceiver 在AndroidManifest.xml中定义 <intent-filter> 对应暗码

<receiver android:name="EMStartReceiver" >
    <intent-filter>
        <action android:name="android.provider.Telephony.SECRET_CODE" />
        <data
            android:host="xxxxx"
            android:scheme="android_secret_code" />
    </intent-filter>


    <intent-filter>
        <action android:name="android.provider.Telephony.SECRET_CODE" />
        <data android:scheme="android_secret_code" android:host="xxxxx" />
    </intent-filter>


</receiver>

EMStartReceiver 代码如下 放在源码中编译

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import java.lang.String;
import com.android.internal.telephony.TelephonyIntents;
import android.os.SystemProperties;


public class  EMStartReceiver extends BroadcastReceiver {


    private static final String TAG = "EMStartReceiver";


    public EMStartReceiver() {
    }


    @Override
    public void onReceive(Context context, Intent intent) {
        String host = null;
        Uri uri = intent.getData();
        if (uri != null) {
            host = uri.getHost();
        } else {
            Log.d(TAG,"uri is null");
            return;
        }
        Intent i = new Intent(Intent.ACTION_MAIN);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);


        if("xxxxx".equals(host) || "xxxxx".equals(host)){
            i.setClass(context, EngineerModeActivity.class);
            context.startActivity(i);
        } 
    }
}



发布了9 篇原创文章 · 获赞 2 · 访问量 7006
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览