我想通过Android 5.0中的应用程序打开设置屏幕,即Lollipop。 当我使用下面提到的代码时,app崩溃了:
Intent mSettingIntent = new Intent(Settings.ACTION_SETTINGS);
mSettingIntent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(mSettingIntent);
logcat的:
01-21 17:28:39.110: E/AndroidRuntime(13210): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.SETTINGS cat=[android.intent.category.LAUNCHER] }
01-21 17:28:39.110: E/AndroidRuntime(13210): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1771)
01-21 17:28:39.110: E/AndroidRuntime(13210): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1491)
01-21 17:28:39.110: E/AndroidRuntime(13210): at android.app.Activity.startActivityForResult(Activity.java:3769)
01-21 17:28:39.110: E/AndroidRuntime(13210): at android.app.Activity.startActivityForResult(Activity.java:3730)
01-21 17:28:39.110: E/AndroidRuntime(13210): at android.app.Activity.startActivity(Activity.java:4040)
01-21 17:28:39.110: E/AndroidRuntime(13210): at android.app.Activity.startActivity(Activity.java:4008)
01-21 17:28:39.110: E/AndroidRuntime(13210): at com.example.settingoption.MainActivity$1.onClick(MainActivity.java:28)
01-21 17:28:39.110: E/AndroidRuntime(13210): at android.view.View.performClick(View.java:4802)
01-21 17:28:39.110: E/AndroidRuntime(13210): at android.view.View$PerformClick.run(View.java:20101)
01-21 17:28:39.110: E/AndroidRuntime(13210): at android.os.Handler.handleCallback(Handler.java:810)
01-21 17:28:39.110: E/AndroidRuntime(13210): at android.os.Handler.dispatchMessage(Handler.java:99)
01-21 17:28:39.110: E/AndroidRuntime(13210): at android.os.Looper.loop(Looper.java:189)
01-21 17:28:39.110: E/AndroidRuntime(13210): at android.app.ActivityThread.main(ActivityThread.java:5532)
01-21 17:28:39.110: E/AndroidRuntime(13210): at java.lang.reflect.Method.invoke(Native Method)
01-21 17:28:39.110: E/AndroidRuntime(13210): at java.lang.reflect.Method.invoke(Method.java:372)
01-21 17:28:39.110: E/AndroidRuntime(13210): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
01-21 17:28:39.110: E/AndroidRuntime(13210): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
答案 0 :(得分:1)
试试这个,
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
答案 1 :(得分:1)
如果您只是想打开"设置"应用程序然后尝试folling:
startActivity(new Intent(Settings.ACTION_SETTINGS));