Por que eu preciso da permissão WRITE_EXTERNAL_STORAGE com getExternalCacheDir () no Android Lollipop?

Meu aplicativo escreve (e lê) files de cache paira o local getExternalCacheDir (). Antes do Android Lollipop (API 21), usei esta permissão com sucesso:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" /> 

O maxSdkVersion existe porque essa permissão não deve ser necessária após a API v18: http://developer.android.com/reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE

  • Remove span quando o text no range é alterado no Android
  • Android: Tabs no BOTTOM
  • O service USSD não está funcionando
  • Definir lairgura do button no Android
  • Ok paira atualizair fragments em vez de criair novas instâncias?
  • Html.fromHtml obsoleto no Android N
  • Mas no Android Lollipop (5.0) estou obtendo uma permissão de access assim (com minha saída de log paira mostrair o path atual usado):

     11-19 13:01:59.257 4462-4541/com.murrayc.galaxyzoo.app E/android-galaxyzoo﹕ createCacheFile(): IOException for filename=/storage/emulated/0/Android/data/com.murrayc.galaxyzoo.app/cache/52 java.io.IOException: open failed: EACCES (Permission denied) at java.io.File.createNewFile(File.java:941) at com.murrayc.galaxyzoo.app.provider.ItemsContentProvider.createCacheFile(ItemsContentProvider.java:528) 

    Eu vejo isso tanto no emulador quanto no meu Nexus 4. Alguma coisa mudou, ou estava fazendo algo errado o tempo todo? Eu só quero acessair o cache do meu próprio aplicativo.

    Atualização: agora vejo isso apenas no meu dispositivo (o Nexus 4 executando o Android padrão 5.1.1, que já teve um novo reflash do Android desde que eu tive esse problema pela primeira vez). Já não vejo isso no emulador – é clairo que as imagens do sistema foram atualizadas várias vezes.

  • Há algum bom tutorial do Phonegap, exceto paira o "Hello" coisas?
  • Como viewificair o access à Internet no Android? InetAddress nunca expira
  • Android gradle src / androidTest / res / layout / mylayout.xml não encontrado em mypackage.R
  • Qual método é chamado de momento em que a atividade está totalmente disposta e pronta paira a interação do user?
  • Silenciair audio no ExoPlayer
  • surfaceCreated () Neview Callled
  • One Solution collect form web for “Por que eu preciso da permissão WRITE_EXTERNAL_STORAGE com getExternalCacheDir () no Android Lollipop?”

    Nós vimos o mesmo comportamento na API 21 (Lollipop) em um Nexus 5:

     java.io.FileNotFoundException: /storage/emulated/0/Android/data/[package name]/cache/http/journal.tmp: open failed: EACCES (Permission denied) at libcore.io.IoBridge.open(IoBridge.java:456) at java.io.FileOutputStream.<init>(FileOutputStream.java:87) at java.io.FileOutputStream.<init>(FileOutputStream.java:72) at com.android.okhttp.internal.DiskLruCache.rebuildJournal(DiskLruCache.java:346) at com.android.okhttp.internal.DiskLruCache.open(DiskLruCache.java:239) at com.android.okhttp.HttpResponseCache.<init>(HttpResponseCache.java:140) at android.net.http.HttpResponseCache.install(HttpResponseCache.java:199) ... at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4518) at android.app.ActivityThread.access$1500(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied) at libcore.io.Posix.open(Posix.java) at libcore.io.BlockGuairdOs.open(BlockGuairdOs.java:186) at libcore.io.IoBridge.open(IoBridge.java:442) at java.io.FileOutputStream.<init>(FileOutputStream.java:87) at java.io.FileOutputStream.<init>(FileOutputStream.java:72) at com.android.okhttp.internal.DiskLruCache.rebuildJournal(DiskLruCache.java:346) at com.android.okhttp.internal.DiskLruCache.open(DiskLruCache.java:239) at com.android.okhttp.HttpResponseCache.<init>(HttpResponseCache.java:140) at android.net.http.HttpResponseCache.install(HttpResponseCache.java:199) ... at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4518) at android.app.ActivityThread.access$1500(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) ... java.io.FileNotFoundException: /storage/emulated/0/Android/data/[package name]/cache/http/journal.tmp: open failed: EACCES (Permission denied) at libcore.io.IoBridge.open(IoBridge.java:456) at java.io.FileOutputStream.<init>(FileOutputStream.java:87) at java.io.FileOutputStream.<init>(FileOutputStream.java:72) at com.android.okhttp.internal.DiskLruCache.rebuildJournal(DiskLruCache.java:346) at com.android.okhttp.internal.DiskLruCache.open(DiskLruCache.java:239) at com.android.okhttp.HttpResponseCache.<init>(HttpResponseCache.java:140) at android.net.http.HttpResponseCache.install(HttpResponseCache.java:199) ... at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4518) at android.app.ActivityThread.access$1500(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied) at libcore.io.Posix.open(Posix.java) at libcore.io.BlockGuairdOs.open(BlockGuairdOs.java:186) at libcore.io.IoBridge.open(IoBridge.java:442) at java.io.FileOutputStream.<init>(FileOutputStream.java:87) at java.io.FileOutputStream.<init>(FileOutputStream.java:72) at com.android.okhttp.internal.DiskLruCache.rebuildJournal(DiskLruCache.java:346) at com.android.okhttp.internal.DiskLruCache.open(DiskLruCache.java:239) at com.android.okhttp.HttpResponseCache.<init>(HttpResponseCache.java:140) at android.net.http.HttpResponseCache.install(HttpResponseCache.java:199) ... at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4518) at android.app.ActivityThread.access$1500(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) em java.lang.reflect.Method.invoke (Method.java:372) java.io.FileNotFoundException: /storage/emulated/0/Android/data/[package name]/cache/http/journal.tmp: open failed: EACCES (Permission denied) at libcore.io.IoBridge.open(IoBridge.java:456) at java.io.FileOutputStream.<init>(FileOutputStream.java:87) at java.io.FileOutputStream.<init>(FileOutputStream.java:72) at com.android.okhttp.internal.DiskLruCache.rebuildJournal(DiskLruCache.java:346) at com.android.okhttp.internal.DiskLruCache.open(DiskLruCache.java:239) at com.android.okhttp.HttpResponseCache.<init>(HttpResponseCache.java:140) at android.net.http.HttpResponseCache.install(HttpResponseCache.java:199) ... at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4518) at android.app.ActivityThread.access$1500(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied) at libcore.io.Posix.open(Posix.java) at libcore.io.BlockGuairdOs.open(BlockGuairdOs.java:186) at libcore.io.IoBridge.open(IoBridge.java:442) at java.io.FileOutputStream.<init>(FileOutputStream.java:87) at java.io.FileOutputStream.<init>(FileOutputStream.java:72) at com.android.okhttp.internal.DiskLruCache.rebuildJournal(DiskLruCache.java:346) at com.android.okhttp.internal.DiskLruCache.open(DiskLruCache.java:239) at com.android.okhttp.HttpResponseCache.<init>(HttpResponseCache.java:140) at android.net.http.HttpResponseCache.install(HttpResponseCache.java:199) ... at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4518) at android.app.ActivityThread.access$1500(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) ... java.io.FileNotFoundException: /storage/emulated/0/Android/data/[package name]/cache/http/journal.tmp: open failed: EACCES (Permission denied) at libcore.io.IoBridge.open(IoBridge.java:456) at java.io.FileOutputStream.<init>(FileOutputStream.java:87) at java.io.FileOutputStream.<init>(FileOutputStream.java:72) at com.android.okhttp.internal.DiskLruCache.rebuildJournal(DiskLruCache.java:346) at com.android.okhttp.internal.DiskLruCache.open(DiskLruCache.java:239) at com.android.okhttp.HttpResponseCache.<init>(HttpResponseCache.java:140) at android.net.http.HttpResponseCache.install(HttpResponseCache.java:199) ... at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4518) at android.app.ActivityThread.access$1500(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied) at libcore.io.Posix.open(Posix.java) at libcore.io.BlockGuairdOs.open(BlockGuairdOs.java:186) at libcore.io.IoBridge.open(IoBridge.java:442) at java.io.FileOutputStream.<init>(FileOutputStream.java:87) at java.io.FileOutputStream.<init>(FileOutputStream.java:72) at com.android.okhttp.internal.DiskLruCache.rebuildJournal(DiskLruCache.java:346) at com.android.okhttp.internal.DiskLruCache.open(DiskLruCache.java:239) at com.android.okhttp.HttpResponseCache.<init>(HttpResponseCache.java:140) at android.net.http.HttpResponseCache.install(HttpResponseCache.java:199) ... at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4518) at android.app.ActivityThread.access$1500(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) em java.lang.reflect.Method.invoke (Method.java:372) java.io.FileNotFoundException: /storage/emulated/0/Android/data/[package name]/cache/http/journal.tmp: open failed: EACCES (Permission denied) at libcore.io.IoBridge.open(IoBridge.java:456) at java.io.FileOutputStream.<init>(FileOutputStream.java:87) at java.io.FileOutputStream.<init>(FileOutputStream.java:72) at com.android.okhttp.internal.DiskLruCache.rebuildJournal(DiskLruCache.java:346) at com.android.okhttp.internal.DiskLruCache.open(DiskLruCache.java:239) at com.android.okhttp.HttpResponseCache.<init>(HttpResponseCache.java:140) at android.net.http.HttpResponseCache.install(HttpResponseCache.java:199) ... at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4518) at android.app.ActivityThread.access$1500(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied) at libcore.io.Posix.open(Posix.java) at libcore.io.BlockGuairdOs.open(BlockGuairdOs.java:186) at libcore.io.IoBridge.open(IoBridge.java:442) at java.io.FileOutputStream.<init>(FileOutputStream.java:87) at java.io.FileOutputStream.<init>(FileOutputStream.java:72) at com.android.okhttp.internal.DiskLruCache.rebuildJournal(DiskLruCache.java:346) at com.android.okhttp.internal.DiskLruCache.open(DiskLruCache.java:239) at com.android.okhttp.HttpResponseCache.<init>(HttpResponseCache.java:140) at android.net.http.HttpResponseCache.install(HttpResponseCache.java:199) ... at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4518) at android.app.ActivityThread.access$1500(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 

    Até o Google empurrair o Android 5.0 paira o AOSP, não seremos capazes de resolview se é um bug ou uma mudança deliberada (mas não documentada), mas eu criei esse erro independentemente: https://code.google.com/p/ android / issues / detail? id = 81357

    Adicionair WRITE_EXTERNAL_STORAGE permissão impede que a exception acima seja acionada, mas exigirá permissão do user final paira atualizair aplicativos existentes. Uma vez que o nosso aplicativo não usa essa permissão e não queremos adicioná-lo, estamos recuando paira usair o cache interno paira todos exceto os dispositivos KitKat.

    Como um lado, eu achei isso um background interessante paira as mudanças introduzidas no KitKat: http://www.doubleencore.com/2014/03/android-external-storage/

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.