0

我在 VS 2022 中使用 Xamarin 来创建一个 android 应用程序。我的主要目标是 Android 10,但我的目标是最小的 Android 8 和最大的 Android 11。当我在使用 Android 11 的 android 模拟器上启动此应用程序时,我的应用程序会立即退出,而不会出现错误消息。

谢谢您的帮助

编辑 :

在日志中我两次发现此错误,这是因为 Android 10 和 Android 11 之间的权限处理程序不同吗?

android.runtime.JavaProxyThrowable: System.UnauthorizedAccessException: Access to the path '/storage/emulated/0/TBV/log/' is denied. ---> System.IO.IOException: Operation not permitted
   --- End of inner exception stack trace ---
  at System.IO.FileSystem.CreateDirectory (System.String fullPath) [0x00191] in <2615c4eaf97e4dd59aa46c819840e5a3>:0 
  at System.IO.Directory.CreateDirectory (System.String path) [0x0002c] in <2615c4eaf97e4dd59aa46c819840e5a3>:0 
  at TBV.TbvApp.writeError (System.Exception ex, System.String erreur) [0x0002a] in <6f35ba81f5be4c248d54abc0fc5cebb6>:0 
  at TBV.Login.VerifVersionAPK () [0x00306] in <6f35ba81f5be4c248d54abc0fc5cebb6>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in <2615c4eaf97e4dd59aa46c819840e5a3>:0 
  at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <9bc33e0337de495f9ddcd5fdf4e98819>:0 
  at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <9bc33e0337de495f9ddcd5fdf4e98819>:0 
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <9bc33e0337de495f9ddcd5fdf4e98819>:0 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.25(intptr,intptr)
    at mono.java.lang.RunnableImplementor.n_run(Native Method)
    at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
4

1 回答 1

0

您没有在 Android Manifest 中启用正确的权限。您需要启用 WRITE_EXTERNAL_STORAGE、READ_EXTERNAL_STORAGE 和 MANAGE_EXTERNAL_STORAGE。

但是,这可能不适用于 Android 版本 11;

https://developer.android.com/about/versions/11/privacy/storage

这个主题包含在这个 SO 问题中:Android 11 Scoped storage permissions

于 2022-01-11T10:47:05.633 回答