added single share
This commit is contained in:
parent
4de4664f7c
commit
ba88896e52
3 changed files with 35 additions and 2 deletions
|
@ -38,6 +38,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
import deckers.thibault.aves.model.ImageEntry;
|
||||
import deckers.thibault.aves.model.provider.MediaStoreImageProvider;
|
||||
import deckers.thibault.aves.utils.ShareUtils;
|
||||
import deckers.thibault.aves.utils.Utils;
|
||||
import io.flutter.app.FlutterActivity;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
@ -102,10 +103,16 @@ public class MainActivity extends FlutterActivity {
|
|||
case "cancelGetImageBytes": {
|
||||
String uri = call.argument("uri");
|
||||
thumbnailFetcher.cancel(uri);
|
||||
// do not send `null`, as it closes the channel
|
||||
result.success("");
|
||||
result.success(null);
|
||||
break;
|
||||
}
|
||||
case "share": {
|
||||
String title = call.argument("title");
|
||||
Uri uri = Uri.parse(call.argument("uri"));
|
||||
String mimeType = call.argument("mimeType");
|
||||
ShareUtils.share(this, title, uri, mimeType);
|
||||
result.success(null);
|
||||
}
|
||||
default:
|
||||
result.notImplemented();
|
||||
break;
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package deckers.thibault.aves.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
public class ShareUtils {
|
||||
public static void share(Activity activity, String title, Uri uri, String mimeType) {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.putExtra(Intent.EXTRA_STREAM, uri);
|
||||
intent.setType(mimeType);
|
||||
activity.startActivity(Intent.createChooser(intent, title));
|
||||
}
|
||||
}
|
|
@ -55,4 +55,16 @@ class ImageFetcher {
|
|||
}
|
||||
return Map();
|
||||
}
|
||||
|
||||
static share(String uri, String mimeType) async {
|
||||
try {
|
||||
await platform.invokeMethod('share', <String, dynamic>{
|
||||
'title': 'Share via:',
|
||||
'uri': uri,
|
||||
'mimeType': mimeType,
|
||||
});
|
||||
} on PlatformException catch (e) {
|
||||
debugPrint('share failed with exception=${e.message}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue