Find class to use with ComponentName class in Android - android

I have a single widget that call another application, here is the most important part of the code:
final Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
final ComponentName cn = new ComponentName("com.android.settings",
"com.android.settings.wifi.WifiSettings");
intent.setComponent(cn);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctxt.startActivity( intent);
The important part is
final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.wifi.WifiSettings");
This call the wifi settings in android, but I found this code in a web site, I want to know how I can call the data roaming and other settings in the system, where I can see this?

com.android.settings is the name of the package. If you go here you can find all the settings available in this package. The roaming settings are in package com.android.phone - see here.
EDIT : it appears that using package names is not portable. Your best bet is to use :
startActivity(new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS));
The list of intents is in the Settings class
You may also need to add FLAG_ACTIVITY_NEW_TASK to your intent

Related

How to finish my custom launcher Programmatically in android

I am developing an application my requirement is to finish my custom launcher and switch to default launcher. How can I achieve that?
follow the following steps:
By using Package Manager get the intents which is having launcher and category home. By using queryIntents method.
Use the 0th indexed intent and get the class name and package name. store some where else like sharedPreferences.
whenever you want to launch the default launcher just create intent with class name and packager name.
Then start that activity when it is required.
Following code may help you:
PackageManager packageManager = getPackageManager();
Intent i = new Intent();
i.addCategory(Intent.CATEGORY_HOME);
i.setAction(Intent.ACTION_MAIN);
List<ResolveInfo> queryIntentActivities = packageManager
.queryIntentActivities(i, 0);
ResolveInfo resolveInfo = queryIntentActivities.get(0);
String packageName = resolveInfo.resolvePackageName;
String className = resolveInfo.activityInfo.targetActivity;

Launch another App within an App for android

I am new to Android. Say, I open an app and I would like to open another App after clicking a button. How can I accomplish this task? Would appreciate if you can provide me some tutorial on this.
Intent intent = new Intent();
intent.setClassName("**package.name**", "**package.name.LauncherActivityName**");
startActivityForResult(intent,REQUEST_CODE);
You need to know the package and class names of the activity to call
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("app package name");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
Use this code:
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.package");
startActivity(launchIntent);
The app you want to launch must be on the device.
Intent appIntent = getPackageManager().getLaunchIntentForPackage("your app package name ");
startActivity(appIntent );
If the other application is a pre-packaged application mean, this tutorial may help you.
If the other application is going to be your application, then you need to learn Implicit Intent tutorials.
Also include the activity of the other application which you are planning to call in the Manifest file of the calling package also.

launching gps setting screen in android

The following code is launching gps setting screen in samsung device but in htc device it is launching security screen of setting.How can i write code so that it will launch gps screen independent of the devices.Please help is there any alternative solution
final ComponentName toLaunch = new ComponentName("com.android.settings","com.android.settings.SecuritySettings");
final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(toLaunch);
startActivity(intent);
Get rid of the setComponent() and addCategory() calls and see if that helps. You should not be using those in any case, particularly the ComponentName that hard-wires in invalid package and class names.
I think this code is helpful for you
Intent intent1 = new Intent();
intent1.setClassName("com.android.settings",
"com.android.settings.SecuritySettings");
context.startActivity(intent1);

Android Launch foreign application from my own

I am trying to get the following code to execute:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setComponent(new ComponentName(" **Home package** "," **Home class** "));
startActivity(intent);
Essentially I am looking for a way to specifically target and load the exact, original, home application.
Technically, you have no way of always knowing "the exact, original, home application".
You can use PackageManager and queryIntentActivities() to find find who all responds to MAIN/HOME Intents. If there are two answers, and yours is one (which I am guessing is your situation), then the other is "the exact, original, home application" pretty much by definition. You can further verify this by getting to the ApplicationInfo object associated with the resolved activity and checking for FLAG_SYSTEM to see if it is installed in the system image. This approach is probably not completely bulletproof, but it may be close enough for your needs.
Yet another option is for you to simply record the current default MAIN/HOME activity when you are run for the first time. Odds are decent that your application will be run before the user elects to make you the default. Again, this has holes (e.g., they make you the default before running you for the first time).
EDIT: SOLUTION:
PackageManager pm=getPackageManager();
Intent main=new Intent(Intent.ACTION_MAIN, null);
main.addCategory(Intent.CATEGORY_HOME);
List<ResolveInfo> launchables=pm.queryIntentActivities(main, 0);
Collections.sort(launchables,
new ResolveInfo.DisplayNameComparator(pm));
int launcher_flag = findLauncherApp(launchables);
ResolveInfo launchable = launchables.get(launcher_flag);
ActivityInfo activity=launchable.activityInfo;
ComponentName name=new ComponentName(activity.applicationInfo.packageName,
activity.name);
Intent i=new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
i.setComponent(name);
startActivity(i);
Where findLaucherApp() turns the List into an array of strings and interrogates each one to see if it contains "com.android.launcher2" and then returns its id.

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