I am developing an application which will uninstall itself after a button click. The following code works for the uninstallation of application running in Android.
Uri uri = Uri.fromParts("package", getClass().getPackage().getName(), null);
Intent uninst_intent = new Intent(Intent.ACTION_DELETE, uri);
startActivityForResult(uninst_intent, EXIT_REQUEST);
But this is not working for the new versions of android such as Android 9 and 10. This Action intent is not deprecated in the newer APIs. What am i missing here?
There is permission missing in Manifest please add this permission in manifest...
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES"></uses-permission>
this will work...!!!
Related
On android pie, I want to call the package manager to uninstall my own app. Here is what I am trying:
val uri = Uri.parse("package:$packageName")
val uIntent = Intent(Intent.ACTION_UNINSTALL_PACKAGE, uri)
startActivity(uIntent)
Oddly this is not working. Nothing is being shown in the logcat as well.
I have also tried ACTION_DELETE
val uri = Uri.parse("package:$packageName")
val uIntent = Intent(Intent.ACTION_DELETE, uri)
startActivity(uIntent)
Please tell me what I am doing wrong. This seems a pretty straightforward job. Am I missing any permission or something I need to declare in manifest?
Thanks.
I was missing manifest permission.
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES"/>
This is probably required for Android 6.0 and above. The code in the question now works perfectly. Tested on Android 9 and Android 10.
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:com.example.myapplication"));
startActivity(intent);
I'm using the following code for picking photos:
Intent intent =new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 100);
and return the result with following:
InputStream inputStream = getContentResolver().openInputStream(data.getData());
Bitmap bmp1 = BitmapFactory.decodeStream(inputStream);
This works good on pre-lollipop but it says "Unfortunately the app has stopped" on lollipop and above. Do I need any permissions on lollipop and above? Has something changed since lollipop? Please guide me/ Suggest a simple method to pick photos on lollipop and above.
Use following way
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(intent, Const.PICK_IMAGE_REQUEST);
OR use custom layout and activity
I have developed it.Please check below link working in all android version 4.0 or above. you dont need to ask for permission as its target version is 22.
https://github.com/rajscet/Photo_Picker_Git
Do I need any permissions on lollipop and above?
You should hold READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE. Note that on Android 6.0+, if your targetSdkVersion is 23 or higher, you need to use runtime permissions to request this permission from the user, as these permissions are dangerous.
I have implemented a code to select a video from gallery and play it in videoview. It works very well in lollipop version. But today when I checked it on Marshmallow, It is not working. There is no exception in logcat too.
Is it due to some security that is added in Marshmallow that is not allowing me to select the video or are any runtime permission needed?
I have this permissions in my manifest file:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Following is my code:
Intent pickVideoImage= new Intent(Intent.ACTION_GET_CONTENT);
pickVideoImage.setType("*/*");
String[] mimetypes = {"image/*", "video/*"};
pickVideoImage.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(pickVideoImage,SELECT_PICTURE_VIDEO);
And this is the code inside onActivityResult :
path = data.getData().toString();
vid.setVideoPath(path);
vid.start();
you should allow permissions on Runtime for Android Marshmallow Version 6.0
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 am using the following code to open android defaults add contact activity to add contact in phone.
Intent intentInsert = new Intent(Contacts.Intents.Insert.ACTION);
intentInsert.setData(People.CONTENT_URI);
startActivity(intentInsert);
But its showing deprecated when using in android sdk 2.1 and above.
how to show add contact activity in new contacts contract api.
Thanks
try this
Intent i = new Intent(Intent.ACTION_INSERT_OR_EDIT);
i.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
i.putExtra(Insert.NAME,"Name");
i.putExtra(Insert.PHONE,"Number");
startActivity(i);
yes above method got deprecated after 2.1 or above try to use
intentInsert.setData(ContactsContract.CONTENT_URI);
for sdk 2.1 or above