1.创建广播接收器MemoryReceiver
public class MemoryReceiver extends BroadcastReceiver {
public static final String MY_SECRET_CODE = "1313";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d("MemoryReceiver" , "action==>"+action);
if ("android.provider.Telephony.SECRET_CODE".equals(action)){
String host = intent.getData() == null ? null : intent.getData().getHost();
if (MY_SECRET_CODE.equals(host)){
//这是启动一个activity
Intent target = new Intent();
target.setClassName(context.getPackageName(), context.getPackageName()+".development.memory.SetMemoryActivity");
target.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
context.startActivity(target);
} catch (Exception e){
Log.d("MemoryReceiver" , ""+e);
e.printStackTrace();
}
}
}
}
}
2.注册这个广播
AndroidManifest.xml
<receiver android:name="com.android.settings.development.memory.MemoryReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE" />
<data android:scheme="android_secret_code" android:host="1313" />
</intent-filter>
</receiver>
网友评论