Android恢复出厂设置

作者: GitCode8 | 来源:发表于2019-05-29 08:35 被阅读10次

    一般只有在开发Launcher和Setting一般才会用到恢复出厂设置,恢复出厂设置在应用层开发相对来说比较简单,就是发送广播。

    Android 9.0之前

    Intent intent = new Intent(Intent.ACTION_MASTER_CLEAR);
    sendBroadcast(intent);
    

    Android 9.0

    Intent resetIntent = new Intent("android.intent.action.FACTORY_RESET");
    resetIntent.setPackage("android");
    sendBroadcast(resetIntent);
    

    当然,要恢复出厂设置,当前APK需要具有系统属性。在AndroidManifest.xml的标签manifest添加android:sharedUserId="android.uid.system"

    <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" >
    

    相关文章

      网友评论

        本文标题:Android恢复出厂设置

        本文链接:https://www.haomeiwen.com/subject/siastctx.html