问题
I want to launch the "dual sim settings" page from an android widget using xamarin android ui. So far I'm able to launch (for an example) DisplaySettings with
var pN=Android.Provider.Settings.ActionDisplaySettings;
var launchInt=new Intent(pN);
launchInt.AddFlags(ActivityFlags.NewTask);
context.StartActivity(launchInt);
My phone offers dual sim settings. I can even add a widget for it on the home screen. Further using the App "Shortcut Creator" I managed to create a shortcut and the information says: Action: android.intent.action.Main Flags: new_task, clear_top, receiver_foreground Component: com.android.settings/.DualCardSettings
But I have no idea how to call / launch this page.
回答1:
07-18 08:09:55.681 1218 1229 I ActivityManager: START u0 {act=android.intent.action.MAIN cat=[com.android.settings.SHORTCUT] flg=0x14000000 hwFlg=0x10 cmp=com.android.settings/.DualCardSettings bnds=[852,1632][1060,1941]} from uid 10087 07-18 08:09:55.681 1218 1229 I ActivityManager: ActivityRecord info: ActivityInfo{65e8a5a com.android.settings.DualCardSettings}
From shared log, package name is com.android.settings, com.android.settings.DualCardSettings is the activity name , if android exposed this activity, you can open it as follow way:
Intent intent = new Intent(Intent.ActionMain);
ComponentName componentName = new ComponentName("com.android.settings", "com.android.settings.DualCardSettings ");
intent.SetComponent(componentName);
StartActivity(intent);
回答2:
Just in the case someone else has this (or a similar) problem I post my working code - Created with the help of @Junior Jiang - MSFT
private void StartDualCardSettings(Context pContext) {
try {
/*
07-18 08:09:55.681 1218 1229 I ActivityManager: START u0 {act=android.intent.action.MAIN cat=[com.android.settings.SHORTCUT] flg=0x14000000 hwFlg=0x10 cmp=com.android.settings/.DualCardSettings bnds=[852,1632][1060,1941]} from uid 10087
07-18 08:09:55.681 1218 1229 I ActivityManager: ActivityRecord info: ActivityInfo{65e8a5a com.android.settings.DualCardSettings}
*/
var settingsIntent = new Intent("android.intent.action.MAIN");
settingsIntent.AddCategory("com.android.settings.SHORTCUT");
settingsIntent.SetComponent(new ComponentName("com.android.settings", "com.android.settings.DualCardSettings"));
settingsIntent.AddFlags(ActivityFlags.NewTask);
pContext.StartActivity(settingsIntent);
return;
}
catch(Exception eX) {
// Something went wrong :)
}
}
Thank you very much - works like a charm.
来源:https://stackoverflow.com/questions/57040048/start-dual-sim-settings-page-in-xamarin-android-ui