Android:恢復出廠設置

只有在開發Launcher和Setting通常纔會用到恢復出廠設置,恢復出廠設置在應用層開發相對來講比較簡單,就是發送廣播。android

Android 9.0以前git

Intent intent = new Intent(Intent.ACTION_MASTER_CLEAR);
sendBroadcast(intent);
複製代碼

Android 9.0bash

Intent resetIntent = new Intent("android.intent.action.FACTORY_RESET");
resetIntent.setPackage("android");
sendBroadcast(resetIntent);
複製代碼

固然,要恢復出廠設置,當前APK須要具備系統屬性。在AndroidManifest.xml的標籤manifest添加android:sharedUserId="android.uid.system"ui

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gitcode.settings"
    android:sharedUserId="android.uid.system"
    android:versionCode="16"
    android:versionName="1.6" >
複製代碼
相關文章
相關標籤/搜索