request storage permissions at runtime in Android 6
This commit is contained in:
parent
d0879bfe39
commit
edb4779039
|
@ -1,5 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Android;
|
||||||
using Android.App;
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using Android.Content.PM;
|
using Android.Content.PM;
|
||||||
|
@ -26,6 +28,7 @@ namespace keepass2android
|
||||||
private readonly ActivityDesign _design;
|
private readonly ActivityDesign _design;
|
||||||
|
|
||||||
private FileStorageAdapter _fileStorageAdapter;
|
private FileStorageAdapter _fileStorageAdapter;
|
||||||
|
private const int RequestExternalStoragePermission = 1;
|
||||||
|
|
||||||
public FileStorageSelectionActivity()
|
public FileStorageSelectionActivity()
|
||||||
{
|
{
|
||||||
|
@ -183,12 +186,26 @@ namespace keepass2android
|
||||||
|
|
||||||
private void ReturnProtocol(string protocolId)
|
private void ReturnProtocol(string protocolId)
|
||||||
{
|
{
|
||||||
|
if ((protocolId == "androidget") && ((int) Build.VERSION.SdkInt >= 23) &&
|
||||||
|
( CheckSelfPermission(Manifest.Permission.WriteExternalStorage) != Permission.Granted))
|
||||||
|
{
|
||||||
|
RequestPermissions(new string[]{Manifest.Permission.ReadExternalStorage, Manifest.Permission.WriteExternalStorage},RequestExternalStoragePermission);
|
||||||
|
return;
|
||||||
|
}
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.PutExtra("protocolId", protocolId);
|
intent.PutExtra("protocolId", protocolId);
|
||||||
SetResult(KeePass.ExitFileStorageSelectionOk, intent);
|
SetResult(KeePass.ExitFileStorageSelectionOk, intent);
|
||||||
Finish();
|
Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
|
||||||
|
{
|
||||||
|
if ((requestCode == RequestExternalStoragePermission) && (grantResults[0] == Permission.Granted))
|
||||||
|
{
|
||||||
|
ReturnProtocol("androidget");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnCreate(Bundle bundle)
|
protected override void OnCreate(Bundle bundle)
|
||||||
{
|
{
|
||||||
_design.ApplyTheme();
|
_design.ApplyTheme();
|
||||||
|
|
Loading…
Reference in New Issue