Runtime.getRuntime().exec 未在 Android 上启动所需的应用程序

Runtime.getRuntime().exec not launching desired app on Android

我正在尝试从我的示例应用程序中打开设置应用程序。 onCreate 中的代码片段:

    Process process;
    try {
        process = Runtime.getRuntime().exec("am start -a android.intent.action.MAIN -n com.android.settings/.Settings");
        process.waitFor();
        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String s = reader.readLine();
        Toast.makeText(this, s, Toast.LENGTH_LONG).show();
    }
     catch(Exception e) {
        e.printStackTrace();
    }

当我 运行 这样做时,我的应用程序会打开,但设置应用程序不会启动(我尝试的任何其他应用程序也不会启动)。为调试插入的 toast 显示“Starting: Intent { act=android.intent.action.MAIN cmp=com.android.settings/.Settings } 但实际上并没有启动。logcat 中也没有任何有用的可见内容(除非我漏掉了里面的东西)。

同样的命令正在使用 adb (adb shell am start -a android.intent.action.MAIN -n com.android.settings/.Settings)

我正在使用 Android Studio 和 Android 4.4 设备(如果有的话)。我一直在网上搜索以找出我可能做错了什么,但上面的代码似乎是正确的。有人可以帮忙吗?

更新: 抱歉没有提供更多细节,但设置不是我最终计划在这个应用程序的实际版本中启动的应用程序,设置只是一个测试。这是另一个没有 android:exported="true" 并采用参数的应用程序。准确地说,它打开某个扩展名的文件,它作为参数,如 "adb shell am start -W -a android.intent.action.VIEW -d ..."

在 Android 中 运行 另一个应用程序的正确方法是 According to this answer

 Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.android.settings");
 startActivity(launchIntent);

为什么不通过 Intent 打开“设置”?像这样:

startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);