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);
Related
I have tried many intents from class android.provider.settings but not able to open this Screen Directly.
You can get the activity's package name and class name from the manifest.xml of Settings,so you can do it like this :
Intent intent = new Intent();
ComponentName componentName = new ComponentName("com.android.settings","com.android.settings.Settings$NotificationAppListActivity");
intent.setComponent(componentName);
startActivity(intent);
And I tested it on Anroid 8.1.0 nexus 6p.
Any idea what would be intent to launch application specific Data usage settings to enable/disable Restrict Background Data.
To launch general setting screen following is the post i referred and it worked also
Which Intent for Settings - Data usage
But I need to launch for specific package id.
Please check this launch screen
This screen is for Gmail
Looking for an intent with parameters to launch this screen programmatically.
Any help is appreciated.
Try using this:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.android.settings",
"com.android.settings.Settings$DataUsageSummaryActivity"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Basically I'd like to start the current phone call ui from a button in one of my activities.
So far, I've been able to start a new call using
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:000000"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
or to move to the phonebook using:
Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
I've also tried to use that code, but it seems not to be working on HTC devices and some Huawei (ri is null).
Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
intentToResolve.setPackage("com.android.phone");
ResolveInfo ri = getPackageManager().resolveActivity(intentToResolve, 0);
if (ri != null)
{
Intent intent = new Intent(intentToResolve);
intent.setClassName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
What I'd like to get is move directly to the call ui. The behaviour is the same as in this procedure:
Be in a phone call
Go back to the Home screen
Expand the notification bar
Click on the call row
I don't know how to achievve and how to make it works on all devices.
Thanks for your precious help.
you have to do as suggested on this answer: android.permission.CALL_PHONE for tablets
add the call phone permission:
<uses-permission android:name="android.permission.CALL_PHONE"/>
and then call with Intent.ACTION_CALL.
Intent intentcall = new Intent(
Intent.ACTION_CALL,
Uri.parse("tel:" + phonenumber));
startActivity(intentcall);
edit:
there's a way you could do, but it won't work in Lollipop and forward, as it's been deprecated due to security reasons.
You could use the ActivityManager to get the running tasks and then analyse the content of each RunningTaskInfo to determine which one is the "phone" and then use the task ID to call moveTaskToFront. It possibly work, but as I said, it will not work with Lollipop and future versions.
I have a situation in my current app where on tapping on a dialog fragment I have to restart the current app in background (or take to home activity) and open calendar app at the same time. I tried firing 2 intents at the same time but it didn't work. I also tried to use AsyncTask's executeOnExecutor but the order is not always guaranteed. Can someone please explain me how to handle situation like these?
you have write following code to launch activity first and calendar intent after that:
public void openCalendar(Context mCtx){
Intent activityIntent = new Intent(mCtx, HomeActivity.class);
startActivity(activityIntent );
Intent i = new Intent();
//Froyo or greater (mind you I just tested this on CM7 and the less than froyo one worked so it depends on the phone...)
cn = new ComponentName("com.google.android.calendar", "com.android.calendar.LaunchActivity");
//less than Froyo
cn = new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity");
i.setComponent(cn);
startActivity(i);
}
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;