-1

I have added to the manifest files these permissions

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-feature android:name="android.hardware.location.gps" />

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

But when the user installs the app the only permission he is being asked and allows is location.

I also want to ask the user for storage permission.How is this possible?

Alex
  • 1,816
  • 5
  • 23
  • 39

3 Answers3

0

Use runtime permission code where you add the data inside the internal storage. You can use dexture or easy permission lib for this.

0

Have you tried what the Android documentation points out:

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

    // Permission is not granted
    // Should we show an explanation?
    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
            Manifest.permission.READ_CONTACTS)) {
        // 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.READ_CONTACTS},
                MY_PERMISSIONS_REQUEST_READ_CONTACTS);

        // 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
}

https://developer.android.com/training/permissions/requesting#java

beastlyCoder
  • 2,349
  • 4
  • 25
  • 52
0

For "dangerous" permissions (includes Storage, Location, Camera, Calendar and more), you need to request the user for their permission not at installation, but when it's required. It's important that you check every time the permission is required, because the user can revoke the permission anytime.

To check for permission (in Kotlin) (in this example it's FINE_LOCATION, change it to whatever permission you need to request):

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
        != PackageManager.PERMISSION_GRANTED
    ) {
//if permission not granted, start function to request permission
//MY_PERMISSIONS_REQUEST is the requestCode, an int > 0
        ActivityCompat.requestPermissions(
            this,
            arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
            MY_PERMISSIONS_REQUEST
        )
    }

and then then override the onRequestPermissionsResult function:

    override fun onRequestPermissionsResult(
    requestCode: Int,
    permissions: Array<String>, grantResults: IntArray
) {
    when (requestCode) {
        MY_PERMISSIONS_REQUEST -> {
            // If request is cancelled, the result arrays are empty.
            if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
                //granted - you are not able to use Location Functionality

            } else {
                // permission denied
                Toast.makeText(this, "Location Functionality Disabled.", Toast.LENGTH_LONG).show()
            }
            return
        }

        // Add other 'when' lines to check for other
        // permissions this app might request.
        else -> {
            // Ignore all other requests.
        }
    }

}

You can also request multiple permissions at once. Android 6.0 multiple permissions

tizi4n
  • 76
  • 4