"Settings > Connected Devices > Connection Preferences" 页面的意图

Intent for "Settings > Connected Devices > Connection Preferences" page

我想知道 AdvancedConnectedDeviceDashboardFragmentIntent。在 API 28 上,可以通过以下方式访问此页面:Settings > Connected Devices > Connection Preferences.

This fragment contains all the advanced connection preferences(i.e, Bluetooth, NFC, USB..)

手动交互的logcat:

D/SettingsActivity: Switching to fragment com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment
D/SubSettings: Launching fragment com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment

通过 SubSettings 启动它不起作用:

try {
    Intent intent = new Intent();
    intent.setClassName("com.android.settings", "com.android.settings.SubSettings");
    getActivity().startActivity(intent);
} catch (ActivityNotFoundException e) {
    Log.e(LOG_TAG, e.getMessage());
}

因为它没有设置 exported="true" 它给了我:

.SecurityException: Permission Denial: starting Intent { cmp=com.android.settings/.SubSettings (has extras) } from ProcessRecord{75bbdbc 11970:com.acme.application.debug/u0a460} (pid=11970, uid=10460) not exported from uid 1000

是否有机会通过父 SettingsActivityIntent 额外启动它?

在浏览 com.android.settings.Settings 时,我找到了 SettingsActivity 的名称:

ConnectedDeviceDashboardActivity extends SettingsActivity
AdvancedConnectedDeviceActivity extends SettingsActivity

所以我写了一个简单的包装方法,它仍然 throws:

public void showSettings(@NonNull String activityName) throws ActivityNotFoundException {
    Intent intent = new Intent();
    intent.setClassName("com.android.settings", "com.android.settings.Settings$" + activityName);
    getActivity().startActivity(intent);
}

可以这样使用:

try {
    showSettings("AdvancedConnectedDeviceActivity");
} catch (ActivityNotFoundException e) {
    Log.e(LOG_TAG, e.getMessage());
}

有关要使用的更多 SettingsActivity 名称,请参阅 Settings.java