仅以下代码生成的app在android 4.0无法工作,app需要至少一个activity,或者如上添加 <category >,而在android2.2可以工作。
1.声明在manifest.xml里面声明receiver:
<receiver android:name=".StartSettings">
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE" />
<data android:host="0556" android:scheme="android_secret_code" />
<data android:host="0557" android:scheme="android_secret_code" /> //可以有多个data
</intent-filter>
</receiver>
2.JAVA代码:
public class startSettings extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String host;
if (intent.getData() != null) {
host = intent.getData().getHost();
} else return;
if (host.equals("0556")) {
//TODO,启动一个程序,如下启动RootExplorer
Intent it = new Intent("android.intent.action.MAIN");
it.setClassName("com.speedsoftware.rootexplorer","com.speedsoftware.rootexplorer.RootExplorer");
context.startActivity(it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));//必须要FLAG_ACTIVITY_NEW_TASK
} else {
//TODO
}
}
}
3.键盘拨号启动:*#*#0557#*#* ,0556就是manifest.xml里面的android:host="0556"