Tharindu Wanninayake
Tharindu Wanninayake

Reputation: 353

RequestPermissions not showing dialog box xamarin c#

I'm new to xamarin. I found lot of similar topics and i tried them. but non of them work for xamarin.

I added the permission in the AndroidManifest for OS below Android M

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

and I used This document and implemented the code below.

string[] permissions ={Manifest.Permission.ReadExternalStorage};
ActivityCompat.RequestPermissions(Activity, permissions, STORAGE_REQUEST_CODE);

ActivityCompat.RequestPermissions doesn't show the dialog box.

Upvotes: 5

Views: 1365

Answers (2)

Tharindu Wanninayake
Tharindu Wanninayake

Reputation: 353

I found the solution for my problem

RequestPermissions(new String[] { Manifest.Permission.ReadExternalStorage }, STORAGE_REQUEST_CODE);

Upvotes: 4

Kaj
Kaj

Reputation: 814

EDIT : Or u can use AlertDialog to ask for Permissions

Like :

string[] permissions ={Manifest.Permission.ReadExternalStorage};


AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.SetTitle("Asking for permisstions");
builder.SetMessage("This app needs this permission to continue");
builder.SetPositiveButton("Request Permissions",(senderAlert,args)=>
{
  RequestPermissions(permissions,0);
});

builder.SetNegativeButton("Cancel",(senderAlert,args)=>
{
 Toast.MakeText(this,"Canceled",ToastLength.Short).Show();
});

Dialog dialog = builder.Create();
dialog.Show();

NOTE : this will work on android 6.0 and above.

Upvotes: 0

Related Questions