0

I am getting an EACCES (permission denied). I have informed the authorization in the manifest, the application is installed there, and is no error except that I cannot write to the smartphone and I do not know why. To me, it seems everything is configured correctly:

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



<application
    android:name=".CalendarNotificationChannel"
    android:allowBackup="false"
    android:icon="@mipmap/calendar"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/calendar_round"
    android:supportsRtl="true"
    android:requestLegacyExternalStorage="true"
    android:theme="@style/AppTheme">

This is my launch code to create the file:

       >   buttonexport.setOnClickListener(new View.OnClickListener() {
        EventDBHelper dbHelper = new EventDBHelper(MainActivity.this);
        SQLiteDatabase sqldb = dbHelper.getReadableDatabase(); //My Database class
        Cursor c = null;

        @Override
        public void onClick(View v) { //main code begins here

            try {
                c = sqldb.rawQuery("select * from EVENTS", null);
                int rowcount = 0;
                int colcount = 0;
                File sdCardDir = Environment.getExternalStorageDirectory();
                String filename = "MyBackUp.csv";
                // the name of the file to export with
                File saveFile = new File(sdCardDir, filename);
                FileWriter fw = new FileWriter(saveFile);

                BufferedWriter bw = new BufferedWriter(fw);
                rowcount = c.getCount();
                colcount = c.getColumnCount();
                if (rowcount > 0) {
                    c.moveToFirst();

                    for (int i = 0; i < colcount; i++) {
                        if (i != colcount - 1) {

                            bw.write(c.getColumnName(i) + ",");

                        } else {

                            bw.write(c.getColumnName(i));

                        }
                    }
                    bw.newLine();

                    for (int i = 0; i < rowcount; i++) {
                        c.moveToPosition(i);

                        for (int j = 0; j < colcount; j++) {
                            if (j != colcount - 1)
                                bw.write(c.getString(j) + ",");
                            else
                                bw.write(c.getString(j));
                        }
                        bw.newLine();
                    }
                    bw.flush();
                    infotext.setText("Exported Successfully.");
                }
            } catch (Exception ex) {
                if (sqldb.isOpen()) {
                    sqldb.close();
                    infotext.setText(ex.getMessage().toString());
                }

            } finally {

            }

        }
    });

Lastly, here is my gradle config

   > android {
     compileSdkVersion 30
            buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.example.myapplication"
          minSdkVersion 27
             targetSdkVersion 30
             versionCode 1
            versionName "1.0"

I don't understand why I am getting this error.

My lodcast :

02/19 21:28:32: Launching 'app' on Nexus 5X API 29.
$ adb shell am start -n 
"com.example.myapplication/com.example.myapplication.MainActivity" -a 
 android.intent.action.MAIN -c android.intent.category.LAUNCHER
 Connected to process 23675 on device 'emulator-5554'.
 Capturing and displaying logcat messages from application. This behavior 
 can be disabled in the "Logcat output" section of the "Debugger" settings 
 page.
 W/RenderThread: type=1400 audit(0.0:2218): avc: denied { write } for 
 name="property_service" dev="tmpfs" ino=7954 
 scontext=u:r:untrusted_app:s0:c162,c256,c512,c768 
 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0
 D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
 W/libc: Unable to set property "qemu.gles" to "1": connection failed; 
errno=13 (Permission denied)
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
W/e.myapplicatio: Accessing hidden method Landroid/view/View;- 
>computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z 
(greylist, reflection, allowed)
 W/e.myapplicatio: Accessing hidden method Landroid/view/ViewGroup;- 
 >makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
 E/DB Path: /data/user/0/com.example.myapplication/databases/calendar.db
 D/HostConnection: HostConnection::get() New Host Connection established 
 0xd3f40090, tid 23716
 D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 
 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 
 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan 
 ANDROID_EMU_deferred_vulkan_commands 
 ANDROID_EMU_vulkan_null_optional_strings 
 ANDROID_EMU_vulkan_create_resources_with_requirements 
 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache 
 ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object 
 GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_2 
 W/OpenGLRenderer: Failed to choose config with 
 EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
 I/e.myapplicatio: Background young concurrent copying GC freed 
 14082(3033KB) AllocSpace objects, 0(0B) LOS objects, 79% free, 
 1593KB/7737KB, paused 903us total 818.915ms
 D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
 D/EGL_emulation: eglCreateContext: 0xdf5275c0: maj 2 min 0 rcv 2
 D/EGL_emulation: eglMakeCurrent: 0xdf5275c0: ver 2 0 (tinfo 0xdf555800)
 W/Gralloc3: mapper 3.x is not supported
 D/HostConnection: createUnique: call
 D/HostConnection: HostConnection::get() New Host Connection established 
 0xd3f41fd0, tid 23716
 D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 
 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 
 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan 
 ANDROID_EMU_deferred_vulkan_commands 
 ANDROID_EMU_vulkan_null_optional_strings 
 ANDROID_EMU_vulkan_create_resources_with_requirements 
 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache 
 ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object 
 GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_2 
 D/eglCodecCommon: allocate: Ask for block of size 0x1000
    allocate: ioctl allocate returned offset 0x3ff7c2000 size 0x2000
 D/EGL_emulation: eglMakeCurrent: 0xdf5275c0: ver 2 0 (tinfo 0xdf555800)
 D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0
 I/OpenGLRenderer: Davey! duration=3864ms; Flags=1, 
 IntendedVsync=32434886011645, Vsync=32434886011645, 
 OldestInputEvent=9223372036854775807, NewestInputEvent=0, 
 HandleInputStart=32434887633600, AnimationStart=32434887688500, 
 PerformTraversalsStart=32434887739300, DrawStart=32438175662400, 
  SyncQueued=32438189382200, SyncStart=32438204897600, 
 IssueDrawCommandsStart=32438206494600, SwapBuffers=32438753563900, 
 FrameCompleted=32438766382000, DequeueBufferDuration=341000, 
 QueueBufferDuration=1261000, 
 I/Choreographer: Skipped 235 frames!  The application may be doing too 
  much work on its main thread.
  I/OpenGLRenderer: Davey! duration=4275ms; Flags=0, 
 IntendedVsync=32434903290409, Vsync=32438819956919, 
 OldestInputEvent=9223372036854775807, NewestInputEvent=0, 
 HandleInputStart=32438823876900, AnimationStart=32438823985700, 
 PerformTraversalsStart=32438824612300, DrawStart=32438828781300, 
 SyncQueued=32438830896600, SyncStart=32438832729500, 
  IssueDrawCommandsStart=32438832851400, SwapBuffers=32438837598900, 
  FrameCompleted=32439180645500, DequeueBufferDuration=102000, 
  QueueBufferDuration=2851000, 
  I/Choreographer: Skipped 32 frames!  The application may be doing too 
  much work on its main thread.
  I/Choreographer: Skipped 34 frames!  The application may be doing too 
  much work on its main thread.
  I/OpenGLRenderer: Davey! duration=808ms; Flags=0, 
  IntendedVsync=32457685230954, Vsync=32458251897598, 
  OldestInputEvent=9223372036854775807, NewestInputEvent=0, 
  HandleInputStart=32458258808700, AnimationStart=32458258866600, 
  PerformTraversalsStart=32458259552300, DrawStart=32458259757400, 
  SyncQueued=32458260405700, SyncStart=32458366977600, 
   IssueDrawCommandsStart=32458367564400, SwapBuffers=32458369712000, 
   FrameCompleted=32458599980800, DequeueBufferDuration=166689000, 
   QueueBufferDuration=270000, 
   W/ActivityThread: handleWindowVisibility: no activity for token 
    android.os.BinderProxy@ae54354  
    E/DB Path: /data/user/0/com.example.myapplication/databases/calendar.db
    I/chatty: uid=10162(com.example.myapplication) identical 1 line
    E/DB Path: /data/user/0/com.example.myapplication/databases/calendar.db
    D/EGL_emulation: eglMakeCurrent: 0xdf5275c0: ver 2 0 (tinfo 0xdf555800)
    I/OpenGLRenderer: Davey! duration=790ms; Flags=1, 
    IntendedVsync=33039235301028, Vsync=33039235301028, 
    OldestInputEvent=9223372036854775807, NewestInputEvent=0, 
    HandleInputStart=33039242411000, AnimationStart=33039242490400, 
     PerformTraversalsStart=33039242545400, DrawStart=33039460471300, 
    SyncQueued=33039512956100, SyncStart=33039685759200, 
     IssueDrawCommandsStart=33039685857000, SwapBuffers=33040189855600, 
     FrameCompleted=33040198630400, DequeueBufferDuration=560000, 
     QueueBufferDuration=725000, 
      D/EGL_emulation: eglMakeCurrent: 0xdf5275c0: ver 2 0 (tinfo 
    0xdf555800)
     I/Choreographer: Skipped 60 frames!  The application may be doing too 
     much work on its main thread.
    I/OpenGLRenderer: Davey! duration=1020ms; Flags=1, 
    IntendedVsync=33039235301028, Vsync=33039235301028, 
     OldestInputEvent=9223372036854775807, NewestInputEvent=0, 
     HandleInputStart=33039242411000, AnimationStart=33039242490400, 
      PerformTraversalsStart=33039242545400, DrawStart=33040199616300, 
      SyncQueued=33040207007700, SyncStart=33040210262300, 
      IssueDrawCommandsStart=33040210616200, SwapBuffers=33040252771200, 
      FrameCompleted=33040259479800, DequeueBufferDuration=1054000, 
       QueueBufferDuration=1113000, 
       D/EGL_emulation: eglMakeCurrent: 0xdf5275c0: ver 2 0 (tinfo 
       0xdf555800)
     I/OpenGLRenderer: Davey! duration=1065ms; Flags=0, 
    IntendedVsync=33039252442469, Vsync=33040252442429, 
       OldestInputEvent=9223372036854775807, NewestInputEvent=0, 
      HandleInputStart=33040255441900, AnimationStart=33040257095000, 
      PerformTraversalsStart=33040258537500, DrawStart=33040260022100, 
      SyncQueued=33040260062200, SyncStart=33040263816100, 
      IssueDrawCommandsStart=33040264406200, SwapBuffers=33040265645000, 
      FrameCompleted=33040321257100, DequeueBufferDuration=287000, 
      QueueBufferDuration=719000, 
      D/EGL_emulation: eglMakeCurrent: 0xdf5275c0: ver 2 0 (tinfo 
      0xdf555800)
codewario
  • 19,553
  • 20
  • 90
  • 159
dragon sly
  • 37
  • 3

0 Answers0