Android 设置开放隐性启动Intent

开放“恢复出厂设置”的隐性启动Intent

在Settings的AndroidManifest.xml中开放了很多供开发者直接使用的action标签的intent-filter,可以调用一些常用的设置界面,如显示,Wi-Fi,位置信息和存储等,格式如下:

        
            
                
                
                
                
                
            
            
            
        

在应用中,可以直接调用:

startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS));


但是并不是所有的设置界面都可以直接调用,比如说恢复出厂设置的二级界面(packages/apps/Settings/src/com/android/settings/MasterClear.java)。


通过“android.settings.BACKUP_AND_RESET_SETTINGS”调用的只是“备份和重置”一级界面,并不是我需要的恢复出厂。


不过有源码就是任性,完全可以自己开放一个隐性Intent出来,步骤如下:

1.将MasterClear的集成类由Fragment更改为SettingsPreferenceFragment:

--- a/packages/apps/Settings/src/com/android/settings/MasterClear.java
+++ b/packages/apps/Settings/src/com/android/settings/MasterClear.java
@@ -44,6 +44,7 @@ import android.widget.CheckBox;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
+import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.Utils;
 import com.mediatek.settings.ext.IFactoryExt;
 import com.mediatek.xlog.Xlog;
@@ -61,7 +62,7 @@ import java.util.Locale;
  *
  * This is the initial screen.
  */
-public class MasterClear extends Fragment {
+public class MasterClear extends SettingsPreferenceFragment {
     private static final String TAG = "MasterClear";
 
     private static final int KEYGUARD_REQUEST = 55;

2.在Settings.java中添加MasterClearActivity,对应步骤1中的MasterClear:

--- a/packages/apps/Settings/src/com/android/settings/Settings.java
+++ b/packages/apps/Settings/src/com/android/settings/Settings.java
@@ -455,6 +455,7 @@ public class Settings extends PreferenceActivity
+        MasterClear.class.getName() // add by zms
     };
 
     @Override
@@ -1370,4 +1371,5 @@ public class Settings extends PreferenceActivity
     public static class PrintSettingsActivity extends Settings { /* empty */ }
     public static class PrintJobSettingsActivity extends Settings { /* empty */ }
+    public static class MasterClearActivity extends Settings { /* empty */ }
 }

3.在AndroidManifest.xml中添加接口:

--- a/packages/apps/Settings/AndroidManifest.xml
+++ b/packages/apps/Settings/AndroidManifest.xml
@@ -1010,6 +1010,20 @@
                android:resource="@id/privacy_settings" />
         
 
+               
+            
+                
+                
+                
+            
+                       
+        

Done!





你可能感兴趣的:(Android)