当我的主屏幕从默认设置中清除时,我可以发出此意图来触发"启动器选择器对话框",在那里我可以选择哪个启动器是默认的。
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(i, 1);
问题是,当用户选择了一个启动器时,我的当前活动被带回来,新的启动器出现在前台。
我试图通过以下方式启动意图选择:
startActivity(Intent.createChooser(i, "Choose one"));
但那不会起作用。
在设置新的启动器时,有没有办法让我的当前活动可见?
答案 0 :(得分:1)
好的,Nova Launcher使用了这个(我想)。这是他们的 HomeReset 类。
public class HomeReset
extends Activity
{
public static ComponentName D(PackageManager paramPackageManager)
{
ComponentName localComponentName = null;
try
{
Intent localIntent = new Intent("android.intent.action.MAIN", null);
localIntent.addCategory("android.intent.category.HOME");
localIntent.addFlags(270532608);
localComponentName = localIntent.resolveActivity(paramPackageManager);
if (("android".equals(localComponentName.getPackageName())) && ("com.android.internal.app.ResolverActivity".equals(localComponentName.getClassName()))) {
return null;
}
return localComponentName;
}
catch (Exception localException)
{
Log.e("HomeReseter", "Exception when trying to find default home", localException);
}
return localComponentName;
}
public static Intent D()
{
Intent localIntent = new Intent("android.intent.action.MAIN", null);
localIntent.addCategory("android.intent.category.HOME");
localIntent.addFlags(270532608);
return localIntent;
}
public static void D(Activity paramActivity)
{
PackageManager localPackageManager = paramActivity.getPackageManager();
localPackageManager.setComponentEnabledSetting(new ComponentName(paramActivity.getPackageName(), "com.teslacoilsw.launcher.homereset.HomeReset"), 1, 1);
Intent localIntent = new Intent("android.intent.action.MAIN", null);
localIntent.addCategory("android.intent.category.HOME");
localIntent.addFlags(270532608);
localIntent.addFlags(268435456);
localIntent.putExtra("homereset_return_to_settings", true);
paramActivity.startActivity(localIntent);
localPackageManager.setComponentEnabledSetting(new ComponentName(paramActivity.getPackageName(), "com.teslacoilsw.launcher.homereset.HomeReset"), 2, 1);
paramActivity.startActivity(localIntent);
}
public void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
Context localContext = getApplicationContext();
PackageManager localPackageManager = getPackageManager();
localPackageManager.setComponentEnabledSetting(new ComponentName(localContext.getPackageName(), "com.teslacoilsw.launcher.homereset.HomeReset"), 1, 1);
Intent localIntent1 = new Intent("android.intent.action.MAIN", null);
localIntent1.addCategory("android.intent.category.HOME");
localIntent1.addFlags(270532608);
localIntent1.setFlags(268435456);
localContext.startActivity(localIntent1);
localPackageManager.setComponentEnabledSetting(new ComponentName(localContext.getPackageName(), "com.teslacoilsw.launcher.homereset.HomeReset"), 2, 1);
Intent localIntent2 = new Intent("android.intent.action.MAIN", null);
localIntent2.addCategory("android.intent.category.HOME");
localIntent2.addFlags(270532608);
localIntent2.setFlags(402653184);
localContext.startActivity(localIntent2);
}
}
这有帮助吗?我找不到它的R.Java文件导致它被混淆,所以我不能告诉你ID引用。
编辑:我认为这就是上述活动的推出方式。这来自 SettingsActivity :
...
Preference localPreference = findPreference("select_home");
if (localPreference == null) {
return;
}
Object localObject = null;
PackageManager localPackageManager = getActivity().getPackageManager();
ComponentName localComponentName = HomeReset.D(localPackageManager);
if (localComponentName != null) {}
try
{
localObject = localPackageManager.getActivityInfo(localComponentName, 0).loadLabel(localPackageManager);
}
catch
...