about Launcher android - android

I have 2 questions about launcher below:
I have 3-4 launchers on device, how can i know which launcher has been set default on my device (with code).(Done)
I have own custom launcher app, I want clear default launcher on my app and without use:
Intent uninstallIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI);
uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(uninstallIntent);
as some app as: Kid's Shell or Kids Place. I have try follow Clearing and setting the default home application but nothing change.
Please show me how to solve 2 things.
Thanks for any advise.

getPackageManager().clearPackagePreferredActivities(defaultLauncherPackgeName);
Added:
If you want to set your launcher as default, try:
ComponentName cN = new ComponentName(mContext, FakeHome.class);
p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Intent selector = new Intent(Intent.ACTION_MAIN);
selector.addCategory(Intent.CATEGORY_HOME);
mContext.startActivity(selector);
p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
And in AndroidManifest.xml:
<activity
android:name="com.test.FakeHome"
android:enabled="false" >
<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>

Related

Android App Getting Killed on Intent Launch

I have an app which is kept hidden from the launcher. Now I want to open the app from the dialer. So I have a BroadcastReceiver where I am handling things.
1) First I show the app,
ComponentName componentName = new ComponentName(context,
SplashActivity.class);
context.getPackageManager().setComponentEnabledSetting(
componentName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
2) Then launch an Intent,
Intent launcher = new Intent(context, SplashActivity.class);
launcher.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(launcher);
3) Then I am hiding the app again,
ComponentName componentName2 = new ComponentName(context,
SplashActivity.class);
context.getPackageManager().setComponentEnabledSetting(
componentName2,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
The Problem
The Intent launch is successful but the app is getting killed after a few seconds. But the problem doesn't occur if I launch any other activity other than the SplashActivity. What is the problem and how can it be solved?
You can use <activity-alias> tag in Android manifest for launcher activity. change in your manifest for launcher activity like as below:-
<activity-alias
android:name="com.watever.SplashActivityAlias"
android:targetActivity="com.watever.SplashActivity"
android:icon="#drawable/ic_launcher"
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.DEFAULT" />
<category android:name="android.intent.category.MONKEY" />
</intent-filter>
</activity-alias>
and in code where where you are showing and hiding app just use Alias Name which is used in manifest like in above manifest alias name is SplashActivityAlias so use SplashActivityAlias instead of SplashActivity in both conditions where you are showing and hiding app.
By doing above thing you can able to hide your app icon with
setComponent EnabledSetting method using Alias name and you can launch your main activity which is splash activity by using dialer
For hiding app
ComponentName componentName2 = new ComponentName("com.packagename",
"com.packagename.HideAppActivity");
context.getPackageManager().setComponentEnabledSetting(
componentName2,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);

Removed App Icon After That New package not yet registered with the system Message Encountered

In my application i have removed the application icon programatically like
PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
after that the application installs and works fine but when i try to re-install the application after some changes it gives following
New package not yet registered with the system
any thing im doing worng ...
Regards.
The error accures because you disabled that Activity completly in the Android Package Manager. In the first run it´s fine because I think you have defined activity-alias in your Manifest with a new shortcut. But when you update your App, the App tries to start the disabled Launcher and boom you can´t start it cause disabled. A (not perfect) workaround would be the following:
<activity
android:name="com.example.Your_Launchscreen"
android:icon="#drawable/your_alternative_icon"
android:label="NotRealAppname"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity-alias
android:name=".Launchscreen_2"
android:enabled="true"
android:icon="#drawable/ic_launcher"
android:label="#string/real_app_name"
android:targetActivity=".Your_Launchscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
Now in your Activity:
getPackageManager().
setComponentEnabledSetting(newComponentName(
activity,Your_Launchscreen.class.getName()+"_2"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Toast.makeText(activity, "Real Appicon hidden...", Toast.LENGTH_LONG).show();
and for showing it again:
PackageManager p = getPackageManager();
ComponentName componentName =
new ComponentName(activity,Your_Launchscreen.class.getName()+"_2");
p.setComponentEnabledSetting(componentName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Toast.makeText(activity, "Real Appicon visible again...", Toast.LENGTH_LONG).show();
This solution is not perfect, because after App installation you have 2 App icons. The real icon and the hidden one. But you can now hide the real icon and update your App without problems.
You could also simply ignore this message.
It will only appear after reinstall with adb trying to start the activity which is not registered anymore. You should start the app manually.

how to make the Launcher-Pick-Up popup window showing?

I have an Launcher app installed. And user has choose another launcher as default, that means when pressing HOME the default launcher will come to front.
I wanna supply user with an convenience of reseting default launcher. Such as a button clicking in my launcher's UI will make Launcher-Pick-Up popup window showing.
Go Launcher can do that(in Go's setting view). it seems Go Launcher does something like "PackageManager.clearPackagePreferredActivities("com.android.launcher")" to clear the prefered launcher activity!
how to achive that ?
launcher can only clear its own prefered settings for security issue.
here is a work around:
register a mockup activity in Manifest.xml:
<activity
android:name="MockupLauncher"
android:enabled="false"
android:exported="false"
android:excludeFromRecents="true"
android:launchMode="singleTask" >
<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>
use "PackageManager.setComponentEnabledSetting" to trigger OS clear current prefered launcher:
private void resetPreferedLauncher() {
PackageManager pm = mContext.getPackageManager();
ComponentName mockupComponent = new ComponentName(MockupLauncher.class.getPackage().getName(), MockupLauncher.class.getName());
pm.setComponentEnabledSetting(mockupComponent, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(startMain);
pm.setComponentEnabledSetting(mockupComponent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);
// or
//pm.setComponentEnabledSetting(mockupComponent, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
that is how I make it! enjoy!

Launch home screen in android

I'm trying to build an android app which needs to disable a home key in android version 4+ ,
<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>
My problem is when i want to return to android launcher "default home screen" using this code :
PackageManager p = getPackageManager();
ComponentName cN = new ComponentName(MainActivity.this, MainActivity.class);
p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
p.setComponentEnabledSetting(cN, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
the default home screen lunched but the application is killed .
How I can lunch the home screen without killing the application.
I tried it just now and its working for me. My application is not killed at any point. I am using android 4.1
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

detecting default launcher, android

Is it possible to detect what the default launcher app is on a device from within your app?
I am poking around with PackageManager but don't seem to see what i am looking for, i would like my app of launcher type to behave differently when set as the default launcher so i am trying to programmatically detect whether the use has set it to be the default launcher or not
the code i tried below returns Android System no matter what i set as the default launcher:
pm = getApplicationContext().getPackageManager();
Intent i = (new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER));
final ResolveInfo mInfo = pm.resolveActivity(i, 0);
Log.v("curent default launcher",":::::::::"+ pm.getApplicationLabel(mInfo.activityInfo.applicationInfo));
In the example that Google provides for a launcher replacement the activity has the following definition in the manifest:
<activity android:name="Home"
android:theme="#style/Theme"
android:launchMode="singleInstance"
android:stateNotNeeded="true">
<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>
Based on that you should add the following categories for querying for the launcher
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
i.addCategory(Intent.CATEGORY_DEFAULT);

Categories

Resources