No Such File Or Diectory Error In Image File Upload Using Retrofit In Android
I am developing an Android app. In my app, I am using Retrofit to upload image and pdf files to server in multipart/form-data request. I am new to Retrofit. I uploaded pdf file an
Solution 1:
If your device Version Is more then Api Level 22, then ask for permission at runtime, I also face the same problem, try to check permission at run time.
private static final int REQUEST_EXTERNAL_STORAGE = 3;
private static String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
};
public void checkStoragePermissions(Activity activity,Intent intent) {
// Check if we have write permission
int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(
activity,
PERMISSIONS_STORAGE,
REQUEST_EXTERNAL_STORAGE
);
} else {
activity.startActivity(intent);
}
}
Post a Comment for "No Such File Or Diectory Error In Image File Upload Using Retrofit In Android"