【发布时间】:2018-12-10 09:05:51
【问题描述】:
图片可以在 Facebook Messenger 聊天中显示,但无法在 Whatsapp 中显示,也无法在 Messenger 和 whatsapp 中显示预览图。知道我哪里做错了吗?
Main.dart - 这是我捕获图像并将其保存到临时目录的位置。
RenderRepaintBoundary boundary = globalKey.currentContext.findRenderObject();
var image = await boundary.toImage(pixelRatio: 3.0);
ByteData byteData = await image.toByteData(format: ImageByteFormat.png);
Uint8List pngBytes = byteData.buffer.asUint8List();
final tempDir = await getTemporaryDirectory();
final file = await new File('${tempDir.path}/image.png').create();
await file.writeAsBytes(pngBytes);
final channel = const MethodChannel('channel:me.amanda.share/share');
channel.invokeMethod('shareFile', 'image.png');
MainActivity.java
private void shareFile(String path) {
try{
File imageFile = new File(this.getCacheDir(), path);
Uri contentUri = FileProvider.getUriForFile(this, "me.amanda.share",
imageFile);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.setData(contentUri);
shareIntent.setType("image/png");
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
this.startActivity(Intent.createChooser(shareIntent, "Share image
using"));
}
catch (Exception ex){
//android.widget.Toast.makeText(this, ex.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
file_path.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<cache-path name="image" path="."/>
</paths>
【问题讨论】:
标签: android image android-intent dart flutter