Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void writeByteArraysToFile(String fileName, byte[] content) {
- try {
- File sciezka = this.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
- File file=new File(sciezka,fileName);
- file.setReadable(true);
- file.setExecutable(true);
- FileOutputStream fos = new FileOutputStream(file);
- fos.write(content);
- fos.close();
- }
- catch (Exception e)
- {
- Tools.toastMessage(getApplicationContext(), "Wystąpił problem: " + e.getMessage());
- }
- }
- public void getPermission(){
- if(ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)!=PackageManager.PERMISSION_GRANTED){
- if(ActivityCompat.shouldShowRequestPermissionRationale(this,Manifest.permission.WRITE_EXTERNAL_STORAGE))
- {
- }
- else
- {
- ActivityCompat.requestPermissions(this,new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE},MY_PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
- }
- }
- else
- {
- if(ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)!=PackageManager.PERMISSION_GRANTED){
- if(ActivityCompat.shouldShowRequestPermissionRationale(this,Manifest.permission.READ_EXTERNAL_STORAGE))
- {
- }
- else
- {
- ActivityCompat.requestPermissions(this,new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},MY_PERMISSION_REQUEST_READ_EXTERNAL_STORAGE);
- }
- }
- }
- }
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- switch (requestCode){
- case -1:
- //hello
- break;
- case MY_PERMISSION_REQUEST_READ_EXTERNAL_STORAGE:
- if(grantResults.length>0 && grantResults[0]== PackageManager.PERMISSION_GRANTED)
- {
- getPermission();
- }
- else
- {
- Toast.makeText(this,"You've denied permission",Toast.LENGTH_LONG).show();
- }
- return;
- case MY_PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE:
- if(grantResults.length>0 && grantResults[0]== PackageManager.PERMISSION_GRANTED)
- {
- getPermission();
- }
- else
- {
- Toast.makeText(this,"You've denied permission",Toast.LENGTH_LONG).show();
- }
- return;
- default:
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement