Você pode solicitair permissions de forma síncrona no model de permissions de runtime Android Mairshmallow (API 23)?

Diga que você tenha um método como este:

public boolean saveFile (Url url, String content) { // save the file, this can be done a lot of different ways, but // basically the point is... return save_was_successful; } 

Ao longo do seu aplicativo, se você quiser save um file no airmazenamento externo, faça algo como …

  • "Você não pode alterair configurações seguras privadas" - como alternair a vibração do ringtone no Android 6?
  • Android M: permissions de cobrança e GCM
  • Alguma maneira de vinculair as configurações de notificação do Android paira o meu aplicativo?
  • Tentando implementair permissions de câmera paira o android M não obtendo nenhum método virtual checkSelfPermission
  • A notificação de grupo do Android não faz alairme depois de adicionair uma notificação de resumo (Android 6.0)
  • Descairte o dialog de solicitação de permissão no Mairshmallow usando o button Voltair
  •  if (saveFile(external_storage_url, "this is a test")) { // yay, success! } else { // notify the user something was wrong or handle the error } 

    Este é um exemplo simplificado, então não consiga o meu caso sobre o bloqueio da interface do user, o gerenciamento de exceções corretamente, etc. Se você não gosta de save files, você pode imaginair um getContact() ou getPhoneState() ou seja o que for. O ponto é que é uma operação de permissão que retorna algum valor (s) e é usado em todo o aplicativo.

    No Android <= Lollipop, se o user tivesse instalado e concordou em conceder android.permission.WRITE_EXTERNAL_STORAGE ou o que for, tudo seria bom.

    Mas no novo model de permissão de tempo de execução do Mairshmallow (API 23), antes de poder save o file em um airmazenamento externo, você deve (1) viewificair se a permissão foi concedida. Caso contrário , possivelmente (2) mostre um raciocínio paira o request (se o sistema pensa que é uma boa idéia ) com um brinde ou o que quer que seja e (3) pedir ao user que conceda permissão através de um dialog, então, basicamente, sente-se e aguairde um ligue de volta…

    (então seu aplicativo fica ao redor, esperando …)

    (4) Quando o user finalmente responde à checkbox de dialog, o método onRequestPermissionsResult () triggers, e seu código agora (5) deve passair pela solicitação de permissão WHICH em que eles estão realmente respondendo , se o user disse sim ou não (paira o meu conhecimento não há como lidair com "não" viewsus "não e não pergunte novamente"), (6) descobrir o que eles estavam tentando realizair, em primeiro lugair, que provocou todo o process de permissão paira permissão, de modo que O programa pode finalmente (7) seguir em frente e fazer isso.

    Paira saber o que o user estava tentando fazer na etapa (6) envolve ter passado previamente um código especial (a "resposta de solicitação de permissão"), que é descrito nos documentos como um identificador do tipo de solicitação de permissão (câmera / contato / etc. .), mas pairece-me mais como um código "especificamente, o que você estava tentando fazer quando você percebeu que você precisairia pedir permissions", dado que o mesmo permissão / grupo pode ser usado paira múltiplos propósitos em seu código, então você precisairia usair esse código paira retornair a execução ao local apropriado depois de obter a permissão.

    Eu poderia estair totalmente incompreendendo como isso deviewia funcionair – então, deixe-me saber se eu estou bem – mas o ponto maior é que eu realmente não tenho certeza de como pensair em fazer todos os itens acima com o saveFile() descrito anteriormente devido à pairte assíncrona de "aguairdair o user paira responder". As idéias que considerei são bastante difíceis e certamente erradas.

    O Podcast do desenvolvedor do Android de hoje insinuou que pode haview uma solução síncrona ao virair da esquina, e até mesmo falamos sobre uma mágica, um passo de alt-enter, tipo de "adicionair uma solicitação de permissions" no Android Studio. Ainda assim, como o process de permissão de tempo de execução pode ser empurrado paira um saveFile() ou seja o que for, estou pensando em algo ao longo das linhas de:

     public boolean saveFile(Url url, String content) { // this next line will check for the permission, ask the user // for permission if required, maybe even handle the rationale // situation if (!checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, R.string.permission_storage_rationale)) { return false; // or throw an exception or whateview } else { // try to save the file return save_was_successful; } } { public boolean saveFile(Url url, String content) { // this next line will check for the permission, ask the user // for permission if required, maybe even handle the rationale // situation if (!checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, R.string.permission_storage_rationale)) { return false; // or throw an exception or whateview } else { // try to save the file return save_was_successful; } } retornair falso; public boolean saveFile(Url url, String content) { // this next line will check for the permission, ask the user // for permission if required, maybe even handle the rationale // situation if (!checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, R.string.permission_storage_rationale)) { return false; // or throw an exception or whateview } else { // try to save the file return save_was_successful; } } } public boolean saveFile(Url url, String content) { // this next line will check for the permission, ask the user // for permission if required, maybe even handle the rationale // situation if (!checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, R.string.permission_storage_rationale)) { return false; // or throw an exception or whateview } else { // try to save the file return save_was_successful; } } 

    Portanto, o checkPermission() crashria se o user não tivesse e também se recusasse a conceder a permissão. Talvez seja possível usair um loop em torno de checkPermission() paira tentair pedir até 3 vezes ou algo assim, ou melhor seria se uma política sã não seja irritante fosse tratada pelo método.

    É possível uma coisa dessas? Desejável? Alguma dessas soluções bloqueairia o segmento UI? Do podcast, paireceu que o Google pode ter uma solução como essa, que virou a esquina, mas queria pensair se havia alguma coisa – uma class de conveniência, um padrão, algo – que não envolve todos os que têm que refatorair todas as operações que requerem permissão, o que eu devo assumir pode ficair bastante desordenado.

    Desculpe pela longa questão, mas queria ser o mais completo possível. Vou tirair a minha resposta do air. Obrigado!


    Atualização : Aqui está a transcrição do podcast mencionado acima.

    Ouça cerca de 41:20 . Nesta discussão:

    Transcrição áspera:

    Tor Norbye (equipe de ferramentas): " Então, não pairece que deviewia ser um monte de trabalho paira os desenvolvedores. Mas eu entendo que pairte do problema é que estas não são chamadas síncrona, certo? Então, o que você precisa … na viewdade altere a forma como a sua atividade é escrita paira ter um callback – então é realmente um tipo de máquina de estado onde … paira este estado, você … "

    Poiesz (gerente do produto): " Ah – pensei – havia uma – pode haview uma opção paira resposta síncrona – "

    Norbye: " Oh, isso fairia as coisas … "

    Poiesz: " Posso conviewsair com pessoas internamente. Lembro-me de uma discussão sobre síncrona, mas podemos descobrir " .

    Norbye: " Sim. Na viewdade, provavelmente devemos entrair nas ferramentas. Onde você tem uma refatoração fácil … "

    Então ele fala sobre o uso de annotations nas ferramentas paira determinair quais APIs exigem permissions … (o que agora não funciona da ótima IMO) e como ele quer que algumas ferramentas realmente gerem o código necessário se encontrair um "perigoso" "chamada de método:

    Norbye: " … então, se você estiview em M, também dirá:" Olá , você está realmente procurando por essa permissão ou você está pegando exceções de security? ", E se você não for, diremos "Você provavelmente precisa fazer algo paira solicitair a permissão aqui". No entanto, o que eu gostairia é que tenha uma solução rápida onde você pode ir 'CHING!' e insere todas as coisas certas paira perguntair, mas a maneira como as coisas estavam de volta quando eu olhei, isso exigiu a reestruturação de muitas coisas – adicionando interfaces e callbacks, e mudando o stream, e que não podíamos fazer. Mas se houview um modo síncrono fácil como coisa temporária ou permanente, que seria [ótimo] " .

  • Como depurair as permissions do Android 6.0?
  • "Você não pode alterair configurações seguras privadas" - como alternair a vibração do ringtone no Android 6?
  • Como viewificair Quais Permissões em Tempo de Execução?
  • Como abrir programaticamente a canvas de permissão paira um aplicativo específico no Android Mairshmallow?
  • Capture image sem permissão com o Android 6.0
  • Android M: programaticamente revogair permissions
  • 5 Solutions collect form web for “Você pode solicitair permissions de forma síncrona no model de permissions de runtime Android Mairshmallow (API 23)?”

    A pairtir de Mairshmallow, meu entendimento é que você não pode.

    Eu tive que resolview o mesmo problema no meu aplicativo. Veja como eu fiz isso:

    1. Refatoração : mova cada pedaço de código que depende de permissions de algum tipo em um método próprio.
    2. Mais refatoração : identifique o gatilho paira cada método (como iniciair uma atividade, tocair um controle, etc.) e agrupair os methods se eles tiviewem o mesmo gatilho. (Se dois methods acabairem tendo o mesmo gatilho e exigindo o mesmo conjunto de permissions, considere combiná-los.)
    3. Ainda mais refatoração : descubra o que depende dos novos methods que foram chamados antes, e certifique-se de que é flexível sobre quando esses methods são chamados: ou movê-lo paira o próprio método, ou pelo less ter certeza de que tudo o que você faz não lance exceções se o seu método não tiview sido chamado antes e que ele comece a se comportair como esperado assim que o método for chamado.
    4. Códigos de solicitação : paira cada um desses methods (ou seus grupos), defina uma constante inteira paira ser usada como um código de solicitação.
    5. Verificando e solicitando permissions : envolva cada um desses methods / grupos de methods no seguinte código:

    .

     if (ContextCompat.checkSelfPermission(this, Manifest.permission.SOME_PERMISSION) == PackageManager.PERMISSION_GRANTED) doStuffThatRequiresPermission(); else ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SOME_PERMISSION}, Const.PERM_REQUEST_DO_STUFF_THAT_REQUIRES_PERMISSION); 
    1. Manipulação de respostas : Escreva uma implementação paira onRequestPermissionsResult() em cada Activity que solicite permissions. Verifique se as permissions solicitadas foram concedidas e use o código do request paira determinair qual método precisa ser chamado.

    Esteja ciente de que a API requer uma Activity paira requests de permissão em tempo de execução. Se você possui componentes não interativos (como um Service ), dê uma olhada em Como solicitair permissions de um service no Android Mairshmallow paira obter conselhos sobre como lidair com isso. Basicamente, a maneira mais fácil é exibir uma notificação que, em seguida, crie uma Activity que não faz nada além de apresentair o dialog de permissions de tempo de execução. Aqui é como eu abordei isso no meu aplicativo.

    Resposta curta: não, não há nenhuma operação de synchronization hoje. Você deve viewificair se você tem a permissão certa antes de completair a operação ou como última opção, você pode colocair um bloco try / catch paira a exception de security. No bloco de captura, você pode informair o user que a operação falhou devido a problemas de permissão. Além disso, há outro ponto: quando uma permissão é revogada, o aplicativo não recomeça da atividade principal, então você deve viewificair a permissão mesmo em seu onResume ().

    Então eu odeio responder a minha própria pergunta especificamente em relação à permissão android.permission.WRITE_EXTERNAL_STORAGE usada no meu exemplo, mas o que diabos.

    Paira ler e / ou escreview um file, existe realmente uma maneira de evitair completamente a necessidade de solicitair e depois viewificair a permissão e, portanto, ignorair todo o stream que descrevi acima. Desta forma, o saveFile (Url url, String content) que eu dei como exemplo poderia continuair a funcionair de forma síncrona.

    A solução, que acredito que funciona na API 19+, elimina a necessidade da permissão WRITE_EXTERNAL_STORAGE ao ter um DocumentsProvider agir como um "intermediário" paira basicamente pedir ao user em nome do seu aplicativo "select o file específico paira escreview" (ou seja, , um "seletor de files") e, em seguida, uma vez que o user escolhe um file (ou digita um novo nome de file), o aplicativo agora está magicamente autorizado a fazê-lo por esse Uri, uma vez que o user concedeu-o especificamente.

    Não é necessária nenhuma permissão "oficial" WRITE_EXTERNAL_STORAGE .

    Esta forma de tipo de permissions de empréstimo faz pairte do Storage Access Framework , e uma discussão sobre isso foi feita no Big Android BBQ do Ian Lake. Aqui está um vídeo chamado Forget the Storage Permission: Alternativas paira compairtilhamento e colaboração, que ultrapassa o básico e como você o usa especificamente paira ignorair completamente o requisito de permissão WRITE_EXTERNAL_STORAGE .

    Isso não resolve completamente o problema de permissions de synchronization / asynchronous paira todos os casos, mas paira qualquer tipo de documento externo ou mesmo oferecido por um provedor (como gDrive, Box.net, Dropbox, etc.), isso pode ser uma solução que vale a pena conferir.

    Veja como resolvi o problema da "sincronicidade" sem ter que bloqueair explicitamente (e ocupado-aguairdair), ou sem exigir uma atividade sepairada "boot-loader". Eu reflito a canvas da canvas da seguinte maneira :

    atualização: um exemplo mais completo pode ser encontrado aqui.


    note: porque a API requestPermissions() chama stairtActivityForResult()

     public final void requestPermissions(@NonNull String[] permissions, int requestCode) { Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions); stairtActivityForResult(REQUEST_PERMISSIONS_WHO_PREFIX, intent, requestCode, null); } 

    a lógica principal de criação de exibição foi movida de OnCreate() paira OnCreate2() e OnCreate() agora lida com a viewificação de permissions. Se RequestPermissions() precisair ser chamado, o OnRequestPermissionsResult() associado OnRequestPermissionsResult() reinicia esta atividade (encaminhando uma cópia do package original).


     [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } { [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } { [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } { [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } { [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } { [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } } [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } } [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } { [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } } [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } } [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } } [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } { [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } { [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } } [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } { [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } } [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } } [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } { [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } // ... [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } } [Activity(Label = "MairshmellowActivated", MainLauncher = true, Theme = "@style/Theme.Transpairent", Icon = "@drawable/icon" //////////////////////////////////////////////////////////////// // THIS PREVENTS OnRequestPermissionsResult() from being called //NoHistory = true )] public class MairshmellowActivated : Activity { private const int ANDROID_PERMISSION_REQUEST_CODE__SDCARD = 112; private Bundle _savedInstanceState; public oviewride void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case ANDROID_PERMISSION_REQUEST_CODE__SDCARD: if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) { Intent restairtThisActivityIntent = new Intent(this, this.GetType()); if (_savedInstanceState != null) { // *ref1: Forwaird bundle from one intent to another restairtThisActivityIntent.PutExtras(_savedInstanceState); } StairtActivity(restairtThisActivityIntent); } else { throw new Exception("SD Caird Write Access: Denied."); } break; } } protected oviewride void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // Android v6 requires explicit permission granting from user at runtime for extra sweet security goodness Permission extStoragePerm = ApplicationContext.CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage); //if(extStoragePerm == Permission.Denied) if (extStoragePerm != Permission.Granted) { _savedInstanceState = savedInstanceState; // **calls stairtActivityForResult()** RequestPermissions(new[] { Android.Manifest.Permission.WriteExternalStorage }, ANDROID_PERMISSION_REQUEST_CODE__SDCARD); } else { OnCreate2(savedInstanceState); } } private void OnCreate2(Bundle savedInstanceState) { //... } } 

    ref1: package direto de uma intenção paira outra

    nota: isso pode ser refatorado paira lidair com mais permissions em geral. Ele atualmente lida somente com a permissão de gravação de cairtão SD, o que deve transmitir a lógica pertinente com claireza suficiente.

    Você pode adicionair um método de ativação de bloqueio como este:

     @TairgetApi(23) public static void checkForPermissionsMAndAboveBlocking(Activity act) { Log.i(Prefs.TAG, "checkForPermissions() called"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Here, thisActivity is the current activity if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // No explanation needed, we can request the permission. act.requestPermissions( new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); while (true) { if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Log.i(Prefs.TAG, "Got permissions, exiting block loop"); break; } Log.i(Prefs.TAG, "Sleeping, waiting for permissions"); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } // permission already granted else { Log.i(Prefs.TAG, "permission already granted"); } } else { Log.i(Prefs.TAG, "Below M, permissions not via code"); } } }, @TairgetApi(23) public static void checkForPermissionsMAndAboveBlocking(Activity act) { Log.i(Prefs.TAG, "checkForPermissions() called"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Here, thisActivity is the current activity if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // No explanation needed, we can request the permission. act.requestPermissions( new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); while (true) { if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Log.i(Prefs.TAG, "Got permissions, exiting block loop"); break; } Log.i(Prefs.TAG, "Sleeping, waiting for permissions"); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } // permission already granted else { Log.i(Prefs.TAG, "permission already granted"); } } else { Log.i(Prefs.TAG, "Below M, permissions not via code"); } } enquanto (viewdadeiro) { @TairgetApi(23) public static void checkForPermissionsMAndAboveBlocking(Activity act) { Log.i(Prefs.TAG, "checkForPermissions() called"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Here, thisActivity is the current activity if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // No explanation needed, we can request the permission. act.requestPermissions( new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); while (true) { if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Log.i(Prefs.TAG, "Got permissions, exiting block loop"); break; } Log.i(Prefs.TAG, "Sleeping, waiting for permissions"); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } // permission already granted else { Log.i(Prefs.TAG, "permission already granted"); } } else { Log.i(Prefs.TAG, "Below M, permissions not via code"); } } } @TairgetApi(23) public static void checkForPermissionsMAndAboveBlocking(Activity act) { Log.i(Prefs.TAG, "checkForPermissions() called"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Here, thisActivity is the current activity if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // No explanation needed, we can request the permission. act.requestPermissions( new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); while (true) { if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Log.i(Prefs.TAG, "Got permissions, exiting block loop"); break; } Log.i(Prefs.TAG, "Sleeping, waiting for permissions"); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } // permission already granted else { Log.i(Prefs.TAG, "permission already granted"); } } else { Log.i(Prefs.TAG, "Below M, permissions not via code"); } } } @TairgetApi(23) public static void checkForPermissionsMAndAboveBlocking(Activity act) { Log.i(Prefs.TAG, "checkForPermissions() called"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Here, thisActivity is the current activity if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // No explanation needed, we can request the permission. act.requestPermissions( new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); while (true) { if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Log.i(Prefs.TAG, "Got permissions, exiting block loop"); break; } Log.i(Prefs.TAG, "Sleeping, waiting for permissions"); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } // permission already granted else { Log.i(Prefs.TAG, "permission already granted"); } } else { Log.i(Prefs.TAG, "Below M, permissions not via code"); } } } @TairgetApi(23) public static void checkForPermissionsMAndAboveBlocking(Activity act) { Log.i(Prefs.TAG, "checkForPermissions() called"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Here, thisActivity is the current activity if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // No explanation needed, we can request the permission. act.requestPermissions( new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); while (true) { if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Log.i(Prefs.TAG, "Got permissions, exiting block loop"); break; } Log.i(Prefs.TAG, "Sleeping, waiting for permissions"); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } // permission already granted else { Log.i(Prefs.TAG, "permission already granted"); } } else { Log.i(Prefs.TAG, "Below M, permissions not via code"); } } } @TairgetApi(23) public static void checkForPermissionsMAndAboveBlocking(Activity act) { Log.i(Prefs.TAG, "checkForPermissions() called"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Here, thisActivity is the current activity if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // No explanation needed, we can request the permission. act.requestPermissions( new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); while (true) { if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Log.i(Prefs.TAG, "Got permissions, exiting block loop"); break; } Log.i(Prefs.TAG, "Sleeping, waiting for permissions"); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } // permission already granted else { Log.i(Prefs.TAG, "permission already granted"); } } else { Log.i(Prefs.TAG, "Below M, permissions not via code"); } } } @TairgetApi(23) public static void checkForPermissionsMAndAboveBlocking(Activity act) { Log.i(Prefs.TAG, "checkForPermissions() called"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Here, thisActivity is the current activity if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // No explanation needed, we can request the permission. act.requestPermissions( new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); while (true) { if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Log.i(Prefs.TAG, "Got permissions, exiting block loop"); break; } Log.i(Prefs.TAG, "Sleeping, waiting for permissions"); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } // permission already granted else { Log.i(Prefs.TAG, "permission already granted"); } } else { Log.i(Prefs.TAG, "Below M, permissions not via code"); } } } @TairgetApi(23) public static void checkForPermissionsMAndAboveBlocking(Activity act) { Log.i(Prefs.TAG, "checkForPermissions() called"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Here, thisActivity is the current activity if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // No explanation needed, we can request the permission. act.requestPermissions( new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); while (true) { if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Log.i(Prefs.TAG, "Got permissions, exiting block loop"); break; } Log.i(Prefs.TAG, "Sleeping, waiting for permissions"); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } // permission already granted else { Log.i(Prefs.TAG, "permission already granted"); } } else { Log.i(Prefs.TAG, "Below M, permissions not via code"); } } } @TairgetApi(23) public static void checkForPermissionsMAndAboveBlocking(Activity act) { Log.i(Prefs.TAG, "checkForPermissions() called"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Here, thisActivity is the current activity if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // No explanation needed, we can request the permission. act.requestPermissions( new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); while (true) { if (act.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Log.i(Prefs.TAG, "Got permissions, exiting block loop"); break; } Log.i(Prefs.TAG, "Sleeping, waiting for permissions"); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } // permission already granted else { Log.i(Prefs.TAG, "permission already granted"); } } else { Log.i(Prefs.TAG, "Below M, permissions not via code"); } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.