aboutsummaryrefslogtreecommitdiff
path: root/android/app/src/main/java/net
diff options
context:
space:
mode:
Diffstat (limited to 'android/app/src/main/java/net')
-rw-r--r--android/app/src/main/java/net/minetest/minetest/GameActivity.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/android/app/src/main/java/net/minetest/minetest/GameActivity.java b/android/app/src/main/java/net/minetest/minetest/GameActivity.java
index 46fc9b1de..f5e9fd6d0 100644
--- a/android/app/src/main/java/net/minetest/minetest/GameActivity.java
+++ b/android/app/src/main/java/net/minetest/minetest/GameActivity.java
@@ -26,6 +26,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.InputType;
+import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
@@ -34,10 +35,16 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
+import androidx.annotation.Keep;
import androidx.appcompat.app.AlertDialog;
+import androidx.core.content.FileProvider;
+import java.io.File;
import java.util.Objects;
+// Native code finds these methods by name (see porting_android.cpp).
+// This annotation prevents the minifier/Proguard from mangling them.
+@Keep
public class GameActivity extends NativeActivity {
static {
System.loadLibrary("c++_shared");
@@ -179,4 +186,22 @@ public class GameActivity extends NativeActivity {
public String getCachePath() {
return Utils.getCacheDirectory(this).getAbsolutePath();
}
+
+ public void shareFile(String path) {
+ File file = new File(path);
+ if (!file.exists()) {
+ Log.e("GameActivity", "File " + file.getAbsolutePath() + " doesn't exist");
+ return;
+ }
+
+ Uri fileUri = FileProvider.getUriForFile(this, "net.minetest.minetest.fileprovider", file);
+
+ Intent intent = new Intent(Intent.ACTION_SEND, fileUri);
+ intent.setDataAndType(fileUri, getContentResolver().getType(fileUri));
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ intent.putExtra(Intent.EXTRA_STREAM, fileUri);
+
+ Intent shareIntent = Intent.createChooser(intent, null);
+ startActivity(shareIntent);
+ }
}