I have a problem with an app of mine. I use this code to uninstall a package, fired from a Service:
Uri packageUri = Uri.parse("package:"+packageName);
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(uninstallIntent);
The problem is, I've heard from someone who is using this app that there is no uninstall dialog opening on a Sony Xperia Z. It works on my Samsung phones, one with Touchwiz and one with Cyanogenmod and also on my Nexus 7.
I tried to change the intent to:
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageUri);
This also works on my devices but not his. Anyone who has an idea why?
Try this:
Intent deleteIntent = new Intent(Intent.ACTION_DELETE, Uri.fromParts("com.the.package",
getPackageManager().getPackageArchiveInfo(apkUri.getPath(), 0).packageName,null));
startActivity(deleteIntent);
hope it helps
Related
Background
In my Android App, users can share generated images to other apps. It's working nicely using the ACTION_SEND Intent.
Many users have asked why they can't share to Instagram stories directly.
Initially I thought Instagram doesn't support receiving Intents for stories (correct to some extent). I searched for it today, and according to this documentation, to share to Instagram Stories, a separate intent com.instagram.share.ADD_TO_STORY has to be used. I tried it, and it works fine.
The problem:
How do I keep both the options available?
I thought about it a lot, and came up with the following options:
1) Have two separate buttons. It will work, but it will look/feel bad.
2) Have my app accept ACTION_SEND intent, name it as Share to Instagram Story, and redirect the intent to the com.instagram.share.ADD_TO_STORY intent. In principle, make a proxy intent.
It will work, and look/feel great, but I don't know if its allowed (legal, etc) and can I disable the intent if the user doesn't have Instagram installed.
3) Add the 'com.instagram.share.ADD_TO_STORY' to the app chooser launched by ACTION_SEND. This would be ideal, but I don't know how to do it.
If you want to add multiple actions to Intent and create a chooser look at this example:
Intent viewIntent = new Intent(Intent.ACTION_VIEW);
Intent editIntent = new Intent(Intent.ACTION_EDIT);
viewIntent.setDataAndType(uri, type);
editIntent.setDataAndType(uri, type);
Intent chooserIntent = Intent.createChooser(editIntent, "Open in...");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { viewIntent });
startActivity(chooserIntent);
UPDATE: Here is good solution to your answer. How to make an intent with multiple actions
I tried the same approach as on Facebook's official documentation then tested on Huawai P9 Lite, Huawai P20 Lite and on Samsung S8 - it only worked on Samsung S8 for not known reason (to me). I gave up on it since, obviously, it's not working on most of the phones.
// Define image asset URI
Uri stickerAssetUri = Uri.parse("your-image-asset-uri-goes-here");
String sourceApplication = "com.my.app";
// Instantiate implicit intent with ADD_TO_STORY action,
// sticker asset, and background colors
Intent intent = new Intent("com.instagram.share.ADD_TO_STORY");
intent.putExtra("source_application", sourceApplication);
intent.setType(MEDIA_TYPE_JPEG);
intent.putExtra("interactive_asset_uri", stickerAssetUri);
intent.putExtra("top_background_color", "#33FF33");
intent.putExtra("bottom_background_color", "#FF00FF");
// Instantiate activity and verify it will resolve implicit intent
Activity activity = getActivity();
activity.grantUriPermission("com.instagram.android", stickerAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (activity.getPackageManager().resolveActivity(intent, 0) != null) { activity.startActivityForResult(intent, 0);}
I have just updated the new Uber app (January 8, 2018) and the deep linking is not working.
Could you explain more?
Below is my code:
formattedUrl = String.format("uber://action=setPickup&client_id=%s&dropoff[latitude]=%f&dropoff[longitude]=%f",
mClientId, http://to.lat , to.lng);
Uri uri = Uri.parse(formattedUrl);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(uri);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(i);
With the old version of Uber app, my code works well. It shows the correct the pickup & drop off location but in the new app, it doesn't work.
May be they have updated things on this in their application.
You can generate deep link using this link.
I tried do the below for a phone call intent and I still keep getting the "#" removed from the number been called. Please see code below... The # at the end get translated into a %23 on printing out the contents of the string to a console. I am testing on a Samsung S4 phone which then generates a USSD code error running. Is there something wrong with the phone or the code below
Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
phoneCallIntent.setData(Uri.parse("tel:" + Uri.encode("*222*"+ rechargeNumber + "#");));
startActivity(phoneCallIntent);
don't use Uri.encode().
Use the following code. I think it will help you.
String uri = "tel:" +"*222*"+ rechargeNumber + "#" ;
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
startActivity(intent);
Intent you're looking for is android.intent.action.CALL_PRIVILEGED.
This might be helpful to you
using android dialer in 3rd party app
Suppose there are two different Android apps: A and B.
App A is a system admin. Is there any way for it to uninstall app B or make it non-functional?
Yes, it is possible, you need to use Intent.ACTION_DELETE have a look at following code,
Uri packageUri = Uri.parse("package:com.mypackgage");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE,packageUri);
startActivity(uninstallIntent);
when you run the above code, it will ask for uninstall application as follows, image
try below code for uninstall apk...
Uri packageURI = Uri.parse("package:com.example.uninstall"); // replace with your package name
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(uninstallIntent);
By using the below code snippet you can uninstall an installed application on your ANDROID phone.It redirected you to the uninstall confirmation...
Create an intent object with an action and data as the package name
and start with the ACTION_DELETE.
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:com.pack.Applicationname"));
startActivity(intent);
I'm encountering a strange error when I try to open a local HTML - file in the android browser. The error that occurs is an activity not found exception:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.browser/com.android.browser.BrowserActivity}; have you declared this activity in your AndroidManifest.xml?
What's really strange to me ist the fact that this error does not occur on all devices. It only comes up on the following devices:
Samsung Galaxy Nexus I (4.1.1)
Samsung Galaxy Nexus II (4.1.1)
Sony Tablet S (4.0.3)
I have tested my Code successfully on the following devices:
Samsung Galaxy S I (4.1.1)
Samsung Galaxy S III
HTC One X
HTC Desire S
Samsung Galaxy S Plus (2.3.3)
Samsung Galaxy Tab 10.1N
AVDs with Android Versions ranging from 2.3.3 to 4.1.0
Finally this is the Code I'm using to open my HTML - file with the Android - browser. I have tested several permutations of this code, leaving out some lines, but they do all have the same effect. As soon as I set component or class I getting the above exception.
Uri uri = Uri.parse(filePath);
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
browserIntent.setDataAndType(uri, "text/html");
browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
context.startActivity(browserIntent);
I have also tried
browserIntent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
instead of
browserIntent.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
But with the same effect...
Has someone an idea why this is happening, am I missing something? I have searched for days on this but couldn't find anything that solved my problem...
Thanks a lot in advance,
cheers
Possible because may be there is no any activity like com.android.browser.BrowserActivity in those devices, Its depends on device manufacturer How they implement the native Browser Application (Activity Name and Package name).
So the possible solution is,
Using PackageManger and Intent you can check for specific intent category like, Intent.CATEGORY_BROWSABLE is available for any application if available then set that application to ComponentName.
Or, You don't specify component name, like,
browserIntent.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
let user have to choose, which Activity will open this page,
So just code is,
Uri uri = Uri.parse(filePath);
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setDataAndType(uri, "text/html");
browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
context.startActivity(browserIntent);
in some scenario you might want to use the native browser instead of letting user chose one,
this is how I did to avoid ActivityNotFoundException by different package name, hope this would help :)
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
PackageManager packageManager = currentActivity.getPackageManager();
Uri uri = Uri.parse(url);
browserIntent.setDataAndType(uri, "text/html");
List<ResolveInfo> list = packageManager.queryIntentActivities(browserIntent, 0);
for (ResolveInfo resolveInfo : list) {
String activityName = resolveInfo.activityInfo.name;
if (activityName.contains("BrowserActivity")) {
browserIntent =
packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
ComponentName comp =
new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
browserIntent.setAction(Intent.ACTION_VIEW);
browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
browserIntent.setComponent(comp);
browserIntent.setData(uri);
}
}
Why not leave it to the system to determine which app to use?
If I have (for example) Chrome installed and perfer to use Chrome, I'll be a bit pissed that you forced the default browser on me.
This should work:
final Uri uri = Uri.parse(filePath);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
context.startActivity(browserIntent);
Why are you specifying a component? leave it outside of your Intent and you should be fine; the action, category and data/type are enough.
New devices can come with Chrome instead of native browser, so you should use for this
browserIntent.setComponent(new ComponentName("com.android.chrome", "com.google.android.apps.chrome.IntentDispatcher"));