android.content.ActivityNotFoundException:未找到可处理Intent的活动-an



我正试图通过我的应用程序从系统设置打开屏幕。所以我在安卓设置中找到了活动的名称,并试图启动它。

活动地址为com.android.settings/com.android.settings.SubSettings

所以用这个代码我试图发送一个意向

val intent = Intent("com.android.settings/com.android.settings.SubSettings")
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(intent)

但是得到了这个例外

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.settings/com.android.settings.SubSettings flg=0x10000000 }

也许可以试试这个:

val intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.android.settings","com.android.settings.SubSettings"));
startActivity(intent);

Intent类、方法和常量总是有可用的文档。另外,看看这个答案

最新更新