aboutsummaryrefslogtreecommitdiff
path: root/android/app/src
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2022-06-05 17:42:09 +0100
committerGitHub <noreply@github.com>2022-06-05 17:42:09 +0100
commit4baf56520d61e22687b563d403f5d873251e135f (patch)
tree222fc895a63ac842866345d2fe216092f65134f2 /android/app/src
parenta69b7abe00fb818fd88f3cd04e7f9997ffd21072 (diff)
downloadminetest-4baf56520d61e22687b563d403f5d873251e135f.tar.gz
minetest-4baf56520d61e22687b563d403f5d873251e135f.tar.bz2
minetest-4baf56520d61e22687b563d403f5d873251e135f.zip
Android: Add support for sharing debug.txt (#12370)
Diffstat (limited to 'android/app/src')
-rw-r--r--android/app/src/main/AndroidManifest.xml13
-rw-r--r--android/app/src/main/java/net/minetest/minetest/GameActivity.java21
-rw-r--r--android/app/src/main/res/xml/filepaths.xml3
3 files changed, 36 insertions, 1 deletions
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 6ea677cb9..11c868622 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -59,6 +59,17 @@
android:name=".UnzipService"
android:enabled="true"
android:exported="false" />
- </application>
+
+ <provider
+ android:name="androidx.core.content.FileProvider"
+ android:authorities="net.minetest.minetest.fileprovider"
+ android:grantUriPermissions="true"
+ android:exported="false">
+ <meta-data
+ android:name="android.support.FILE_PROVIDER_PATHS"
+ android:resource="@xml/filepaths" />
+ </provider>
+
+</application>
</manifest>
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 eeb90ea7f..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;
@@ -36,7 +37,9 @@ 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).
@@ -183,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);
+ }
}
diff --git a/android/app/src/main/res/xml/filepaths.xml b/android/app/src/main/res/xml/filepaths.xml
new file mode 100644
index 000000000..2fff06908
--- /dev/null
+++ b/android/app/src/main/res/xml/filepaths.xml
@@ -0,0 +1,3 @@
+<paths>
+ <external-files-path path="Minetest/" name="minetest" />
+</paths>