1

So i have an app i am working on and i need various permissions. I have these permissions in my AndroidManifest.xml and i am requesting them when i need them. But nothing happens when i call the ActivityCompat.RequestPermissions() method.

My test device is a OnePlus 3 running Android 7.1 API 25 here is my manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.henryapps.mortyfyingsoundboard" android:installLocation="internalOnly" android:versionCode="12" android:versionName="12">
 <uses-sdk android:minSdkVersion="14" />
 <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
 <uses-permission android:name="android.permission.WRITE_SETTINGS" />
 <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
 <application android:label="Mortyfying Sounboard">
  <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
  <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

 </application>
</manifest>

and here is my method to check if i have the correct permissions and request them if i do not.

                if (CheckSelfPermission(Manifest.Permission.WriteSettings) != Permission.Granted || CheckSelfPermission(Manifest.Permission.ChangeConfiguration) != Permission.Granted ||
                CheckSelfPermission(Manifest.Permission.ModifyAudioSettings) != Permission.Granted || CheckSelfPermission(Manifest.Permission.WriteExternalStorage) != Permission.Granted)
            {

                string[] permissions =
                {
                    Manifest.Permission.WriteSettings,
                    Manifest.Permission.ChangeConfiguration,
                    Manifest.Permission.ModifyAudioSettings,
                    Manifest.Permission.WriteExternalStorage,
                    Manifest.Permission.ReadExternalStorage,

                };

                ActivityCompat.RequestPermissions(this, permissions, 105);

                if(CheckSelfPermission(Manifest.Permission.WriteSettings) != Permission.Granted || CheckSelfPermission(Manifest.Permission.ChangeConfiguration) != Permission.Granted ||
                CheckSelfPermission(Manifest.Permission.ModifyAudioSettings) != Permission.Granted || CheckSelfPermission(Manifest.Permission.WriteExternalStorage) != Permission.Granted)
                {
                    Toast toast = Toast.MakeText(this, "Request of permissions failed...", ToastLength.Short);
                    toast.Show();
                }

            }

I have been looking at examples of this for a week now and have had no luck in getting this working and am getting very frustrated. Being a newer Android developer (1 year now) it is difficult to make sense of what little documentation Xamarin provides on this.

  • Remove the `Manifest.` from the `name` of each `` element in the manifest. They should all start with just `android.permission.`; e.g., `"android.permission.CHANGE_CONFIGURATION"`. – Mike M. Aug 12 '17 at 03:13
  • Alright i made that change. Ran a quick test and it is still not bringing up the popup to allow permissions. It is also probably important to note my test device is a oneplus 3 on Android 7.1 API 25. I will add that to the description. – Dylan Henry Aug 12 '17 at 03:20
  • The `WRITE_SETTINGS` permission is an oddball, starting with Marshmallow. Have a look at [this post](https://stackoverflow.com/questions/32083410/cant-get-write-settings-permission). Also, while you're trying to get this working, I'd suggest you pare down the requested permissions to just one, temporarily; e.g., request just `ReadExternalStorage` for the moment. – Mike M. Aug 12 '17 at 03:29
  • Oh wow, interesting, i commented out WRITE_SETTINGS and all of my other permissions are showing up as granted! – Dylan Henry Aug 12 '17 at 03:40
  • 1
    And it seems to be working now! well, i'm getting a filenotfound exception but i can work through that. Thank you! – Dylan Henry Aug 12 '17 at 03:40

0 Answers0