android: share file type

This commit is contained in:
ardocrat 2024-09-20 00:16:12 +03:00
parent bacc87945c
commit 3e249c5314
3 changed files with 7 additions and 7 deletions

View file

@ -450,14 +450,14 @@ public class MainActivity extends GameActivity {
// Pass image from camera into native code. // Pass image from camera into native code.
public native void onCameraImage(byte[] buff, int rotation); public native void onCameraImage(byte[] buff, int rotation);
// Called from native code to share image from provided path. // Called from native code to share data from provided path.
public void shareImage(String path) { public void shareData(String path) {
File file = new File(path); File file = new File(path);
Uri uri = FileProvider.getUriForFile(this, "mw.gri.android.fileprovider", file); Uri uri = FileProvider.getUriForFile(this, "mw.gri.android.fileprovider", file);
Intent intent = new Intent(Intent.ACTION_SEND); Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uri); intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/*"); intent.setType("*/*");
startActivity(Intent.createChooser(intent, "Share image")); startActivity(Intent.createChooser(intent, "Share data"));
} }
// Called from native code to check if device is using dark theme. // Called from native code to check if device is using dark theme.

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<paths> <paths>
<external-cache-path name="images" path="images/" /> <external-cache-path name="share" path="share/" />
</paths> </paths>

View file

@ -144,7 +144,7 @@ impl PlatformCallbacks for Android {
let default_cache = OsString::from(dirs::cache_dir().unwrap()); let default_cache = OsString::from(dirs::cache_dir().unwrap());
let mut file = PathBuf::from(env::var_os("XDG_CACHE_HOME").unwrap_or(default_cache)); let mut file = PathBuf::from(env::var_os("XDG_CACHE_HOME").unwrap_or(default_cache));
// File path for Android provider. // File path for Android provider.
file.push("images"); file.push("share");
if !file.exists() { if !file.exists() {
std::fs::create_dir(file.clone())?; std::fs::create_dir(file.clone())?;
} }
@ -159,7 +159,7 @@ impl PlatformCallbacks for Android {
let vm = unsafe { jni::JavaVM::from_raw(self.android_app.vm_as_ptr() as _) }.unwrap(); let vm = unsafe { jni::JavaVM::from_raw(self.android_app.vm_as_ptr() as _) }.unwrap();
let env = vm.attach_current_thread().unwrap(); let env = vm.attach_current_thread().unwrap();
let arg_value = env.new_string(file.to_str().unwrap()).unwrap(); let arg_value = env.new_string(file.to_str().unwrap()).unwrap();
let _ = self.call_java_method("shareImage", let _ = self.call_java_method("shareData",
"(Ljava/lang/String;)V", "(Ljava/lang/String;)V",
&[JValue::Object(&JObject::from(arg_value))]); &[JValue::Object(&JObject::from(arg_value))]);
Ok(()) Ok(())