Get continuous package name in service - android

I want to get continuously package name of launch app its working fine but when no one apps open then i want to get default launcher package name,So launcher package name get like below code:
PackageManager localPackageManager = getPackageManager();
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory(Intent.CATEGORY_HOME);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
launcher_pkgname = localPackageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY).activityInfo.packageName;
Its working fine but in some device when i directly press home key then its get last open app package name not launcher package name
what can i do?
Help me please

Related

How To Open Homescreen Activity for Selecting Launcher in OPPO or Other Phones

Hello Friend I'm working on Launcher Application. for select my launcher as Home app a popup is showing in samsung. by using this code.
private void launchAppChooser() {
PackageManager packageManager = getPackageManager();
// get dummyActivity
ComponentName componentName = new ComponentName(context, DummyActivity.class);
// enable dummyActivity (it starts disabled in the manifest.xml)
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
// create a new (implicit) intent with MAIN action
Intent intent = new Intent(Intent.ACTION_MAIN);
// add HOME category to it
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// launch intent
startActivity(intent);
// disable dummyActivity once again
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
but this code is not working on OPPO and HUAWEI. I'm using following line for showing same popup to select home launcher
startActivity(Intent.createChooser(intent,"Select Launcher App"));
This code is showing popup with launcher Apps but when i clicked on any app its not set as default.
Can i open homescreen Activity from setting in OPPO for choosing default launcher like this(please open image). because CM Launcher app is opening this activity
Clicke here to open image
Now i Want To Open This Activity Programetically. and Need Yours help for doing this.
For checking in oppo devices, you have to check if the current default home app package name contains "oppo.launcher".
After that, use this code using it. You can open the default home apps settings in "oppo devices"
Intent intent = new Intent();
intent.setAction(Settings.ACTION_HOME_SETTINGS);
startActivity(intent);
This is an alternative solution for changing the current home app to your launcher app. This intent redirect user to default launcher app list in oppo devices.

How to launch a mobile app from another app?

Is there any way to launch for one mobile app to launch another mobile app, e.g. via a button click?
Example: the org.apache.cordova.camera plugin allows direct access to the camera on a button click. In the same way, how can one app launch another app?
You can use this java code:
Intent LaunchIntent = this.cordova.getActivity().getPackageManager().getLaunchIntentForPackage("appPackage");
this.cordova.getActivity().startActivity(LaunchIntent);
or try any of these 2 plugins for launching apps:
https://github.com/lampaa/com.lampa.startapp
https://github.com/dmedvinsky/cordova-startapp
Try this
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("package name here");
startActivity( LaunchIntent );
If you don't know the package name of application that you want to launch then try this
PackageManager pm;
pm = getPackageManager();
// get a list of all installed apps then launch by pakagename.
packages = pm.getInstalledApplications(0);
String packagename = packages.get(position).packageName.toString()
Refer this android-package-manager
You need to find out full name of application, and then start it as activity via intent like this:
Intent myIntent = new Intent(getApplicationContext(), "full name of activity you are starting");
startActivity(myIntent);
You can even receive result from that activity check this. Hope this helps!

Opening application from current application

I have an Android app that can open another app I have using:
Intent intent = new Intent();
PackageManager manager = getPackageManager();
intent = manager.getLaunchIntentForPackage("myOtherAppPackageName");
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);
Which works perfectly, the only thing is the app force closes when I don't have the other app installed, which makes perfect sense. My question is how do I get my app to open the Play Store to the specific app for someone to download if they do not already have the other app? I would assume do the exact same thing except I don't have the package name for the Play Store.
if you have the package name you can just do this
Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
"market://details?id=" + "packagename"));
startActivity(marketIntent);
that will launch the play store on the page for that application
If you know package lets use this example code:
public void offerApp(Activity activity) {
Log.d("Launching Market");
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=<PACKAGE>"));
activity.startActivity(i);
}

Get the launcher activity name

Hello i wan't to keep home activity name for launch it from my app.
I know we can launch the launcher without know is package name but.
I'm making a custom home and i will set it as default so this will launch my custom home.
I wan't to keep the launcher activity name on a shared preference the first time i launch my custom home and then i will be able to go on the default home from my personal home(without delete my home preference i will keep it as default and launch default home just for some debug test)
Don't know if i'm clear; i have difficult to understood myself in this subject so for resume
I need at the first launch of my activity get the name of the default launcher(because it's not com.android.launcher for every device) and keep it to be able to launch it after some time
Any idea?
Finaly i don't keep the name i don't care of it i just use the following code to launch a launcher who is not mine :P
PackageManager pm = getPackageManager();
Intent i = new Intent("android.intent.action.MAIN");
i.addCategory("android.intent.category.HOME");
List<ResolveInfo> lst = pm.queryIntentActivities(i, 0);
if (lst != null)
{
for (ResolveInfo resolveInfo : lst) {
if (resolveInfo.activityInfo.packageName != getPackageName()){
Intent res = new Intent();
String mPackage = resolveInfo.activityInfo.packageName;
String mClass = resolveInfo.activityInfo.name;
res.setComponent(new ComponentName(mPackage,mClass));
startActivity(res);
}
}
}
you can get application registered with intent action android.intent.category.HOME, and you can get package list for aplication registered with this intent.
May be this can also help

Launching the Settings/Market from a widget

How would I go about launching the Settings menu/the Market from a widget. Ive tried using a code and using the Settings/Market package name, but neither of them will open. Heres the code I'm using:
String packageName = "com.package";
String className = "com.package.MainActivity";
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(packageName, className));
startActivity(intent);
Also, the phone I'm testing on runs HTC Sense, if that matters.
I have no idea how to start the Market app (I'm not even sure if it's possible) but to launch the Settings Activity, try...
Intent i = new Intent(Settings.ACTION_SETTINGS);
startActivity(i);
You'll need the following import...
import android.provider.Settings;

Categories

Resources