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.
Related
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...!!!
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 am checking user permissions allowance on Android API >=23 using this way.
#RequiresApi(api = Build.VERSION_CODES.M)
private void requestPermissions() throws RuntimeException {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, 1234); //TODO: MOVE TO CONST
}
Problem is that snippet mentioned above displays separated intent without the possibility to Explain why the app needs permissions (see attached image please). So I am using the modal window for displaying explanation why the app needs permissions and when the user clicked on the O.K button, intent with permission request is displayed.
This is not user-friendly at all and I would like to do the same thing (permission check + allowance) in the standard permission requesting way for Android API >= 23 like on:
https://developer.android.com/training/permissions/requesting.html
Is it possible please or is this permission unique with something and have to be processed only this way?
Many thanks for any advice.
I'm getting: android.os.FileUriExposedException.
When targeting Android N, file:// URIs are not allowed anymore. I know
We should use content:// URIs instead. However, my app needs file for
both image and video. Any ideas?
mMediaUri = Uri.fromFile(new File(AppHelper.getDirectoryPath(),AppHelper.getFileName() + ".jpeg"));
Intent iCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
iCamera.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
startActivityForResult(iCamera, Constants.INTENT_CALL.CAPTURE_IMAGE);
and onActivityResult
case Constants.INTENT_CALL.CAPTURE_IMAGE:
String filePath=SiliCompressor.with(getActivity()).compress(mMediaUri.toString(), true);
Please add sample code...if Available.
After some research finally got relevant answer to my question just set min target sdk version to 23.
I am trying to open gallery on Nexus 7 with Android 6.0. It does not have in built gallery, but it does have the Google Photos app.
I am using the following code to open the gallery :
Intent i = new intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Always show the chooser (if there are multiple options available)
startActivityForResult(Intent.createChooser(i, "Select Picture"), PICK_IMAGE_REQUEST);
The above code works well in all the versions below 6.0. And Please note that I am already using RUN TIME PERMISSIONS for accessing gallery and have given the permission to access gallery / or externa storage.
Now when the code is executed, I get a transparent screen with heading "Select Picture" and in the middle a text No Apps can perform this action.
Now what do I do to pick or choose image and use in my app.
Any help is appreciated.
Thanks
I am using the following code to open the gallery
That code has nothing to do with a "gallery". That code is requesting to pick a piece of content from a particular collection of content. There may be zero, one, or several activities on the device that offer to support that Intent structure.
The above code works well in all the versions below 6.0
Only on devices that happen to have one or more activities that satisfies that Intent structure.
Now what do I do to pick or choose image and use in my app.
Intent i = new intent(Intent.ACTION_GET_CONTENT).setType("image/*");
// use PackageManager to see if there is anything that supports this
// Intent structure, or just blindly make the following call and handle
// the ActivityNotFoundException
startActivityForResult(i, PICK_IMAGE_REQUEST);
I am using this code , so that only gallery opens and not any other option to pick image
There is nothing in your code that limits it to just a "gallery".
Not allowed to comment because I don't have enough points. But here's just a suggestion, how about if you just passed the intent directly? Like this:
startActivityForResult(i, PICK_IMAGE_REQUEST);
Use this line of code rather than what you have done
Intent i = new intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, PICK_IMAGE_REQUEST);