Why Does Play-Services-Location Need the Android.Permission.Write_External_Storage and Android.Permission.Read_External_Storage Permissions

Why does play-services-location need the android.permission.WRITE_EXTERNAL_STORAGE and android.permission.READ_EXTERNAL_STORAGE permissions?

Short answer: I don't believe play-services-location does need those permissions. Neither does it seem to need android.permission.ACCESS_NETWORK_STATE or android.permission.INTERNET, which are also being added.

Longer answer:
Looking at my manifest merger log, it appears that all four of these permissions are being included at the request of play-services-maps, which -location is linking in of its own accord. My app isn't using -maps, just -location.

Further, I've found that this behavior just appeared in version 7.5.0 of play-services-location; prior versions didn't include -maps, and don't add those permissions.

I actually suspect that this connection to play-services-maps is accidental, and will be removed in a future release of GMS.

Following up on the link given by Mark Murphy (CommonsWare), you can remove these permissions from your app by adding the following lines to your manifest:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" tools:node="remove" />
<uses-permission android:name="android.permission.INTERNET" tools:node="remove" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:node="remove" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove" />

Note that you'll also need xmlns:tools="http://schemas.android.com/tools" in your opening <manifest ... > element to make these work. And the usual caveats apply: my app worked fine after taking this step, but YMMV.


Update 10 Sep 2015: Mark Murphy (@commonsware) has done an excellent writeup on this issue on his blog, including a discussion of the risks of my solution.

PlayServices ads library 7.5.0 need WRITE_EXTERNAL_STORAGE permission

This was fixed as part of Google Play services 8.3 - the Maps API (which location relies on) no longer requires the storage permission and no longer adds it via manifest merger.

Remove WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions from Android Project

@Sergey Comment: They can be merged from the dependent library. You can check if any library you are using have those permissions in their Manifest file.

I looked into it and found this article How Libraries can silently add permissions to your Android App and the Fix. It Worked.

But I'm using camera, and I was storing these pictures in the Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData). Which requires WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions.

So, I replace the path with FileSystem.CacheDirectory and it worked (Intenral Storage doesn't requires Read and Write Permissions in Manifest file).

Why are permissions being automatically added to my AndroidManifest when including Google Play Services library

When you use

compile 'com.google.android.gms:play-services:7.5.0'

This implies you are using every feature of Google Play Services, including location services. If you only need a particular API, you should be using the selective APIs.

In the case of ads, you can use solely:

compile 'com.google.android.gms:play-services-ads:7.5.0'

READ_EXTERNAL_STORAGE permission for Android

You have two solutions for your problem. The quick one is to lower targetApi to 22 (build.gradle file).
Second is to use new and wonderful ask-for-permission model:

if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {

// Should we show an explanation?
if (shouldShowRequestPermissionRationale(
Manifest.permission.READ_EXTERNAL_STORAGE)) {
// Explain to the user why we need to read the contacts
}

requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);

// MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE is an
// app-defined int constant that should be quite unique

return;
}

Sniplet found here: https://developer.android.com/training/permissions/requesting.html

Solutions 2: If it does not work try this:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
REQUEST_PERMISSION);

return;

}

and then in callback

@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_PERMISSION) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Permission granted.
} else {
// User refused to grant permission.
}
}
}

that is from comments. thanks

READ or WRITE EXTERNAL STORAGE permission : WHY NO ERROR?

Here I found answer in documentation:

Beginning with Android 4.4 (API level 19), reading or writing files
in your app's private external storage directory — accessed using
getExternalFilesDir() — does not require the
READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE permissions.

Its not required for my project because my minimum API level is 19.

So if your app supports Android 4.3 (API level 18) and lower, and
you want to access only the private external storage directory, you
should declare that the permission be requested only on the lower
versions of Android by adding the maxSdkVersion attribute:

<manifest ...>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
...
</manifest>

Thank you.

Read and Write external storage permission isn't working

in android API >= 23 you need to request permission at runtime. Take a look here

Something like this

        // Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {

// Permission is not granted
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed; request the permission
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MY_PERMISSIONS_WRITE_EXTERNAL_STORAGE);

// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
} else {
// Permission has already been granted
}

however, Ted permission library is a gread lib to avoid such boilerplate code.

//call back after permission granted
PermissionListener permissionlistener = new PermissionListener() {
@Override
public void onPermissionGranted() {
Toast.makeText(MainActivity.this, "Permission Granted", Toast.LENGTH_SHORT).show();
}

@Override
public void onPermissionDenied(List<String> deniedPermissions) {
Toast.makeText(MainActivity.this, "Permission Denied\n" + deniedPermissions.toString(), Toast.LENGTH_SHORT).show();
}

};

//check all needed permissions together
TedPermission.with(this)
.setPermissionListener(permissionlistener)
.setDeniedMessage("If you reject permission,you can not use this service\n\nPlease turn on permissions at [Setting] > [Permission]")
.setPermissions(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE)
.check();


Related Topics



Leave a reply



Submit