[android] Fix saving to Google Drive #8817

Merged
krozhdestvenski merged 2 commits from fix_save_to_google_drive into master 2024-08-07 11:18:33 +00:00

View file

@ -19,6 +19,8 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import app.organicmaps.Framework;
import app.organicmaps.R;
@ -212,7 +214,7 @@ public class SharingUtils
public static void shareFile(Context context, ActivityResultLauncher<SharingIntent> launcher, ShareInfo info)
{
Intent intent = new Intent(Intent.ACTION_SEND);
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
if (!info.mSubject.isEmpty())
intent.putExtra(Intent.EXTRA_SUBJECT, info.mSubject);
@ -228,15 +230,16 @@ public class SharingUtils
{
final Uri fileUri = StorageUtils.getUriForFilePath(context, info.mFileName);
Logger.i(TAG, "Sharing file " + info.mMimeType + " " + info.mFileName + " with URI " + fileUri);
intent.putExtra(Intent.EXTRA_STREAM, fileUri);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, new ArrayList<>(List.of(fileUri)));
biodranik commented 2024-08-01 14:22:29 +00:00 (Migrated from github.com)
Review

Should it be inside if (context instanceof Application), as it is done in other apps?

Should it be inside `if (context instanceof Application)`, as it is done in other apps?
krozhdestvenski commented 2024-08-01 14:44:55 +00:00 (Migrated from github.com)
Review

In this case context is Activity.

In this case context is Activity.
biodranik commented 2024-08-01 14:46:54 +00:00 (Migrated from github.com)
Review

Does it allow to come back into Organic Maps after the file is exported?

Does it allow to come back into Organic Maps after the file is exported?
krozhdestvenski commented 2024-08-01 15:13:51 +00:00 (Migrated from github.com)
Review

Yes. After exporting we return to Organic Maps (checked it for exporting to Google Drive and local deevice)

Yes. After exporting we return to Organic Maps (checked it for exporting to Google Drive and local deevice)
biodranik commented 2024-08-01 16:59:56 +00:00 (Migrated from github.com)
Review

There are several more places in the code where this function is called. Did you test it on different Android versions too? Does it work on Android 5?

There are several more places in the code where this function is called. Did you test it on different Android versions too? Does it work on Android 5?
krozhdestvenski commented 2024-08-01 21:05:52 +00:00 (Migrated from github.com)
Review

i tested it in send bug report functionality.
It works correcctly on Android 10
On Android 5 send e-mail and savind to documents work too. Saving to Google Drive i can't check

i tested it in send bug report functionality. It works correcctly on Android 10 On Android 5 send e-mail and savind to documents work too. Saving to Google Drive i can't check
biodranik commented 2024-08-03 10:48:49 +00:00 (Migrated from github.com)
Review

Should FLAG_ACTIVITY_NEW_TASK be used when a single bookmark or POI is shared from the Place Page?

Should FLAG_ACTIVITY_NEW_TASK be used when a single bookmark or POI is shared from the Place Page?
biodranik commented 2024-08-06 07:10:34 +00:00 (Migrated from github.com)
Review
      intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
```suggestion intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK); ```
krozhdestvenski commented 2024-08-06 08:01:36 +00:00 (Migrated from github.com)
Review

On current version works correctly

On current version works correctly
intent.setDataAndType(fileUri, info.mMimeType);
// Properly set permissions for intent, see
// https://developer.android.com/reference/androidx/core/content/FileProvider#include-the-permission-in-an-intent
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
intent.setClipData(ClipData.newRawUri("", fileUri));
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
}
Intent saveIntent = new Intent(Intent.ACTION_CREATE_DOCUMENT);