1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Android: Add support for sharing debug.txt (#12370)

This commit is contained in:
rubenwardy 2022-06-05 17:42:09 +01:00 committed by GitHub
parent a69b7abe00
commit 4baf56520d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 81 additions and 2 deletions

View file

@ -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>

View file

@ -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);
}
}

View file

@ -0,0 +1,3 @@
<paths>
<external-files-path path="Minetest/" name="minetest" />
</paths>