Guest User

Untitled

a guest
Dec 16th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. protected void onCreate(Bundle savedInstanceState) {
  2.  
  3. super.onCreate(savedInstanceState);
  4. setContentView(R.layout.activity_home);
  5.  
  6.  
  7. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
  8. requestStoragePermission();
  9. }
  10.  
  11. dirPath = Environment.getExternalStorageDirectory().getPath() + "/GACI";
  12.  
  13. File projDir = new File(dirPath);
  14. if (!projDir.exists())
  15. projDir.mkdirs();
  16. ...
  17. }
  18.  
  19. private void requestStoragePermission() {
  20. if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)
  21. return;
  22.  
  23. if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
  24. //If the user has denied the permission previously your code will come to this block
  25. //Here you can explain why you need this permission
  26. //Explain here why you need this permission
  27. }
  28. //And finally ask for the permission
  29. ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, STORAGE_PERMISSION_CODE);
  30. }
  31.  
  32. <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  33. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Add Comment
Please, Sign In to add comment