Android APP 代码实现恢复出厂设置

Android APP 代码实现恢复出厂设置
与重启一样,需要APP有系统权限,具体签名打包方法自己
manifest下一样少不了

android:sharedUserId="android.uid.system"

实现方法,参照系统源码广播形式:

 /**
     * 恢复出厂设置,需要系统权限,以及系统签名
     */
    public void resetSystem() {
        Intent intent = new Intent("android.intent.action.FACTORY_RESET");
        //8.0
        // intent = new Intent("android.intent.action.MASTER_CLEAR");
		//9.0
         intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
         intent.setPackage("android");
         
        //以上区分不同系统
        intent.putExtra("android.intent.extra.REASON", "FactoryMode");
        //是否擦除SdCard
        intent.putExtra("android.intent.extra.WIPE_EXTERNAL_STORAGE", true);
        intent.putExtra("android.intent.extra.EXTRA_WIPE_ESIMS", true);
        sendBroadcast(intent);
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章