Darn it

Got this message today. This unresolved, high-priority, 8-months-old issue
is finally coming to bite in the ass
https://github.com/codenameone/CodenameOne/issues/3204
We won't be able to update or publish any existing app that uses the
Gallery on Android unless this is resolved. The workaround proposed by Shai
in the issue is going to be shut down on the 5th of May

We've detected that your app contains the requestLegacyExternalStorage flag
in the manifest file of one or more of your app bundles or APKs.

Developers with apps on devices running Android 11+ must use scoped storage
to give users better access control over their device storage. To release
your app on Android 11 or newer after 5 May, you must either:

   - Update your app to use more privacy-friendly best practices, such as
   the storage access framework or Media Store API
   - Update your app to declare the All files access (
   MANAGE_EXTERNAL_STORAGE) permission in the manifest file, and complete
   the All files access permission declaration in Play Console from 5 May
   - Remove the All files access permission from your app entirely

For apps targeting Android 11, the requestLegacyExternalStorage flag will
be ignored. You must use the All files access permission to retain broad
access.

Apps requesting access to the All files access permission without a
permitted use will be removed from Google Play, and you won't be able to
publish updates.

I am not 100% sure of what needs fixing in CN1, but I recently had to do
some native android work where I needed to read images from an intent in
the most up-to-date way. The below code allowed me to get these images from
an intent (the code gets images shared into an app with the latest APIs
etc). Just sharing in case it helps


Intent intent = getIntent();

Uri sharedFileUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);

 if(sharedFileUri != null)
    {
        FileInputStream input = null;
        FileOutputStream output = null;
        try
        {
            //first get filename
            String originalFieName = getFileName(sharedFileUri);
            String filePath = new File(getCacheDir(),
originalFieName).getAbsolutePath();
            android.os.ParcelFileDescriptor pfd =
getContentResolver().openFileDescriptor(sharedFileUri, "r");
            if(pfd != null)
            {
                FileDescriptor fd = pfd.getFileDescriptor();
                input = new FileInputStream(fd);
                output = new FileOutputStream(filePath);
                int read;
                byte[] bytes = new byte[4096];
                while ((read = input.read(bytes)) != -1) {
                    output.write(bytes, 0, read);
                }
                File sharedFile = new File(filePath);
                String finalPath = sharedFile.getPath();//this is the
final image path to be used
            }
        }catch(Exception ex){}
        finally{
            try {
                input.close();
                output.close();
            } catch (Exception ignored) {}
        }
    }
}

public String getFileName(Uri uri) {
    try
    {
      String result = null;
      if (uri.getScheme().equals("content")) {
        Cursor cursor = getContentResolver().query(uri, null, null, null, null);
        try {
          if (cursor != null && cursor.moveToFirst()) {
            result =
cursor.getString(cursor.getColumnIndex(android.provider.OpenableColumns.DISPLAY_NAME));
          }
        } finally {
          cursor.close();
        }
      }
      if (result == null) {
        result = uri.getPath();
        int cut = result.lastIndexOf('/');
        if (cut != -1) {
          result = result.substring(cut + 1);
        }
      }
      return result;
    }catch(Exception e)
    {
        return "temp_file";
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/CAG90yJ0B%3DaAsCZMSz0YUSFRWeuJV7C%2BmYDKBvyBa0%3D0kikCryg%40mail.gmail.com.

Reply via email to