Image not save in the device when click the button

前端 未结 1 671
一整个雨季
一整个雨季 2021-01-24 03:46

Currently, I am using the Picasso library to download images and save it in the device when I press the button. the problem is when I press the button the image not download and

1条回答
  •  醉话见心
    2021-01-24 04:06

    Inside,

    onCreate(){
           setContentView(..);
           // requestPermission. ask for permission when app starts.
    }    
    
            @Override
            public void onClick(View v) {
                if (checkPermission()) {
                    String URL = intent.getStringExtra("imageUrl");
                    SaveImage (URL);
                }
            }
    

    // kind of this, add this block to your existing code.

      private void requestPermission() {
          if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
             Toast.makeText(MainActivity.this, "Write External Storage permission allows us to save files. Please allow this permission in App Settings.", Toast.LENGTH_LONG).show();
          } else {
             ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
          }
       }
    

    // make sure Manifest has all the permission defined

    0 讨论(0)
提交回复
热议问题