New Google restrictions on CN1 apps

42 views
Skip to first unread message

Javier Anton

unread,
Apr 15, 2021, 5:10:34 PM4/15/21
to codenameone...@googlegroups.com
Darn it

Got this message today. This unresolved, high-priority, 8-months-old issue is finally coming to bite in the ass
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";
}
}

Shai Almog

unread,
Apr 15, 2021, 11:50:21 PM4/15/21
to CodenameOne Discussions
Hi,
I've asked Steve to look into this issue and raised its priority to critical.

Javier Anton

unread,
Apr 16, 2021, 4:11:30 AM4/16/21
to codenameone...@googlegroups.com
Thanks

--
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 codenameone-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/1179bb13-e115-4969-b3f2-400787765742n%40googlegroups.com.

Javier Anton

unread,
Apr 18, 2021, 5:40:42 PM4/18/21
to codenameone...@googlegroups.com
Just a heads up.. I re-opened the issue after thinking that Steve had fixed it on Friday. Some devices are still showing the error

I have one such glitched device. As I mentioned on Github, feel free to ask me to test things
Reply all
Reply to author
Forward
0 new messages