Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_home);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- requestStoragePermission();
- }
- dirPath = Environment.getExternalStorageDirectory().getPath() + "/GACI";
- File projDir = new File(dirPath);
- if (!projDir.exists())
- projDir.mkdirs();
- ...
- }
- private void requestStoragePermission() {
- if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)
- return;
- if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
- //If the user has denied the permission previously your code will come to this block
- //Here you can explain why you need this permission
- //Explain here why you need this permission
- }
- //And finally ask for the permission
- ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, STORAGE_PERMISSION_CODE);
- }
- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Add Comment
Please, Sign In to add comment