=================================
=================================
=================================
When the user clicks Home he is given the choice of launcher and he can also choose whether to set it as default. The problem is that afterwards it's hard to change it again.
To fix this I added a "Reset preferred launcher" that triggers this:
getPackageManager().clearPackagePreferredActivities(getPackageName());
However this line only resets the preferred launcher if he has chosen my launcher. I need a snippet that clears the preferred launcher whatever it is, so next time the user clicks home he is given the options again.
-------------------------------------------------------------------------------------------------------------------------------------------------
It's not directly possible, and Android developers have stated that they do not want any app changing the user's preferences. However, there is a workaround based on how Android maintains these preferences.
Make your manifest look like this:
<activity android:name="MyLauncherActivity" android:exported="true" /> <activity-alias android:name="LauncherAlias1" android:targetActivity="MyLauncherActivity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.HOME" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity-alias> <activity-alias android:name="LauncherAlias2" android:enabled="false" android:targetActivity="MyLauncherActivity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.HOME" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity-alias>
For the sake of simplicity, I've left out additional attributes that aren't relevant to the task at hand.
Anyway once your manifest looks like this, you can clear the default launcher using code like this:
PackageManager pm = getPackageManager(); ComponentName cn1 = new ComponentName("com.mypackage", "com.mypackage.LauncherAlias1"); ComponentName cn2 = new ComponentName("com.mypackage", "com.mypackage.LauncherAlias2"); int dis = PackageManager.COMPONENT_ENABLED_STATE_DISABLED; if(pm.getComponentEnabledSetting(cn1) == dis) dis = 3 - dis; pm.setComponentEnabledSetting(cn1, dis, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(cn2, 3 - dis, PackageManager.DONT_KILL_APP);
By enabling one alias and disabling the other, you cause Android to perceive the user's options as having changed, as if you installed one launcher and uninstalled another. Thus, the user will be asked to choose again the next time they press the home button. This approach works no matter whose launcher is the current default.
=================================
=================================
=================================
'스마트기기개발관련 > 안드로이드 개발' 카테고리의 다른 글
[android] 안드로이드 android 내 Account 조회, 추가, 안드로이드 Authenticator Service 만들기 관련 (0) | 2016.07.14 |
---|---|
[android] 안드로이드 android 여러업체들의 결제 모듈 관련 (0) | 2016.07.13 |
안드로이드 android 기본 런쳐 확인 및 런쳐 기본 설정 해제 방법 (0) | 2016.07.12 |
안드로이드 android 다양한 앱 종료 방법 관련 (0) | 2016.07.11 |
안드로이드[Android] EditText 자동 포커스 제거 (0) | 2016.07.08 |
댓글 영역