Guest User

Untitled

a guest
Jun 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. public static String saveToInternalStorage(Context ctx,Bitmap bitmapImage){
  2. Date date = new Date();
  3. File mypath = new File(ctx.getFilesDir(), "ATM_"+date.getTime()+".jpg");
  4. FileOutputStream fos = null;
  5. try {
  6. fos = new FileOutputStream(mypath);
  7. bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
  8. } catch (Exception e) {
  9. e.printStackTrace();
  10. } finally {
  11. try {
  12. if (fos != null) {
  13. fos.close();
  14. }
  15. } catch (IOException e) {
  16. e.printStackTrace();
  17. }
  18. }
  19. return mypath.getAbsolutePath();
  20. }
  21.  
  22. Intent intent = new Intent();
  23. // set flag to give temporary permission to external app to use your FileProvider
  24. intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  25. intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
  26. // generate URI, I defined authority as the application ID in the Manifest, the last param is file I want to open
  27. File file = new File(path);
  28. if(file.exists() && file.isFile()) {
  29. Uri uri = FileProvider.getUriForFile(getApplicationContext(), BuildConfig.APPLICATION_ID, file);
  30. intent.setType("image/*");
  31. intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
  32. startActivityForResult(intent, 1);
  33. }
  34.  
  35. <provider
  36. android:name="android.support.v4.content.FileProvider"
  37. android:authorities="${applicationId}"
  38. android:exported="false"
  39. android:grantUriPermissions="true">
  40. <meta-data
  41. android:name="android.support.FILE_PROVIDER_PATHS"
  42. android:resource="@xml/file_provider_paths"/>
  43.  
  44. </provider>
  45.  
  46. <paths xmlns:android="http://schemas.android.com/apk/res/android">
  47. <files-path name="files" path="/"/>
Add Comment
Please, Sign In to add comment