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);
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章