Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String saveToInternalStorage(Context ctx,Bitmap bitmapImage){
- Date date = new Date();
- File mypath = new File(ctx.getFilesDir(), "ATM_"+date.getTime()+".jpg");
- FileOutputStream fos = null;
- try {
- fos = new FileOutputStream(mypath);
- bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- if (fos != null) {
- fos.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return mypath.getAbsolutePath();
- }
- Intent intent = new Intent();
- // set flag to give temporary permission to external app to use your FileProvider
- intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
- // generate URI, I defined authority as the application ID in the Manifest, the last param is file I want to open
- File file = new File(path);
- if(file.exists() && file.isFile()) {
- Uri uri = FileProvider.getUriForFile(getApplicationContext(), BuildConfig.APPLICATION_ID, file);
- intent.setType("image/*");
- intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
- startActivityForResult(intent, 1);
- }
- <provider
- android:name="android.support.v4.content.FileProvider"
- android:authorities="${applicationId}"
- android:exported="false"
- android:grantUriPermissions="true">
- <meta-data
- android:name="android.support.FILE_PROVIDER_PATHS"
- android:resource="@xml/file_provider_paths"/>
- </provider>
- <paths xmlns:android="http://schemas.android.com/apk/res/android">
- <files-path name="files" path="/"/>
Add Comment
Please, Sign In to add comment