我将我的活动设置为默认启动器来拦截主页按钮点击,如下所示:
<activity
android:name=".ExampleActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
When my activity, ExampleActivity
is launched, if i click the home key, I get prompted to choose. If I select make this my default and chose my activity, I am stuck In my activity as desired.
问题是,当我离开活动时,我尝试从默认启动器中删除我的活动,但没有成功。
我努力了:
ComponentName componentName = new ComponentName(
"com.example.exampleactivity",
"com.example.exampleactivity.class");
pm.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);
And:
PackageManager pm = getActivity().getPackageManager();
ComponentName name = new ComponentName(this, "com.example.exampleactivity.class");
pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
But my designation for the home is never removed.
有人有解决上述问题的工作方法吗?
我只希望主页按钮成为特定活动的默认按钮,而不是整个应用程序的默认按钮。当我离开活动时,它应该被删除并恢复为默认值。