Android can now share multiple files at once

This commit is contained in:
Yousef Khadadeh 2026-05-31 23:00:12 +03:00
parent 7f94f65bea
commit 6ef2b88d41
7 changed files with 109 additions and 78 deletions

View file

@ -34,8 +34,8 @@ android {
applicationId 'com.erroratline0.InfiniPaint'
minSdkVersion 27
targetSdk 36
versionCode 1
versionName "0.5.0"
versionCode 2
versionName "0.6.0"
externalNativeBuild {
cmake {
cppFlags "-fexceptions", "-frtti"

View file

@ -23,7 +23,7 @@
void startNetworkService();
void stopNetworkService();
void shareText(java.lang.String);
void shareInternalFile(java.lang.String, java.lang.String);
void shareInternalFiles(java.lang.String[], java.lang.String);
}
-keep,includedescriptorclasses,allowoptimization class org.libsdl.app.SDLActivity {

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
android:versionCode="2"
android:versionName="0.6.0"
android:installLocation="auto">
<!-- OpenGL ES 2.0 -->
@ -82,7 +82,7 @@
<meta-data android:name="SDL_ENV.SDL_ANDROID_TRAP_BACK_BUTTON" android:value="0"/>
-->
<service
android:name=".InfiniPaintNetworkService"
android:name="InfiniPaintNetworkService"
android:foregroundServiceType="specialUse"
android:exported="false">
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"

View file

@ -39,6 +39,7 @@ import org.libsdl.app.SDLDummyEdit;
import org.libsdl.app.SDLSurface;
import java.io.File;
import java.util.ArrayList;
public class InfiniPaint extends SDLActivity {
protected void onCreate(Bundle savedInstanceState) {
@ -154,24 +155,43 @@ public class InfiniPaint extends SDLActivity {
mSingleton.stopService(new Intent(mSingleton, InfiniPaintNetworkService.class));
}
static public void shareInternalFile(String filePath, String mimeType) {
File newFile = new File(getContext().getFilesDir(), filePath);
Uri contentUri;
static public void shareInternalFiles(String[] filePaths, String mimeType) {
if(filePaths.length == 1) {
File newFile = new File(getContext().getFilesDir(), filePaths[0]);
Uri contentUri;
try {
contentUri = getUriForFile(getContext(), "com.erroratline0.infinipaint.fileprovider", newFile);
}
catch (Exception e) {
Log.v("INFO", "[shareInternalFile] Exception " + e);
return;
}
try {
contentUri = getUriForFile(getContext(), "com.erroratline0.infinipaint.fileprovider", newFile);
} catch (Exception e) {
Log.v("INFO", "[shareInternalFile] Exception " + e);
return;
}
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
sendIntent.setType(mimeType);
Intent shareIntent = Intent.createChooser(sendIntent, null);
getContext().startActivity(shareIntent);
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
sendIntent.setType(mimeType);
Intent shareIntent = Intent.createChooser(sendIntent, null);
getContext().startActivity(shareIntent);
}
else if(filePaths.length > 1) {
ArrayList<Uri> arrayList = new ArrayList<Uri>();
for(String str : filePaths) {
File newFile = new File(getContext().getFilesDir(), str);
try {
arrayList.add(getUriForFile(getContext(), "com.erroratline0.infinipaint.fileprovider", newFile));
} catch (Exception e) {
Log.v("INFO", "[shareInternalFile] Exception " + e);
return;
}
}
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, arrayList);
sendIntent.setType(mimeType);
Intent shareIntent = Intent.createChooser(sendIntent, null);
getContext().startActivity(shareIntent);
}
}
static public void shareText(String textToSend) {