Java 在whatsapp中共享图像和文本
我正试图通过我的应用程序在whatsapp中共享文本+图像。 但我无法共享该图像,只能共享文本。图像区域显示为空白。Java 在whatsapp中共享图像和文本,java,android,whatsapp,Java,Android,Whatsapp,我正试图通过我的应用程序在whatsapp中共享文本+图像。 但我无法共享该图像,只能共享文本。图像区域显示为空白。 这是我的密码 Uri uri = Uri.fromFile(new File(fname)); Intent share = new Intent(); share.setAction(Intent.ACTION_SEND); share.setPackage("com.whatsapp"); share.putExtra(Intent.EXTRA_TEXT,ci.descrip
这是我的密码
Uri uri = Uri.fromFile(new File(fname));
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setPackage("com.whatsapp");
share.putExtra(Intent.EXTRA_TEXT,ci.description);
share.putExtra(Intent.EXTRA_STREAM,uri);
share.setType("image/*");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
context.startActivity(share);
}catch (Exception what){
Toast.makeText(context,"Whatsapp have not been installed",Toast.LENGTH_LONG).show();
}
这是我的截图
Uri uri = Uri.fromFile(new File(fname));
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setPackage("com.whatsapp");
share.putExtra(Intent.EXTRA_TEXT,ci.description);
share.putExtra(Intent.EXTRA_STREAM,uri);
share.setType("image/*");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
context.startActivity(share);
}catch (Exception what){
Toast.makeText(context,"Whatsapp have not been installed",Toast.LENGTH_LONG).show();
}
Uri uri = Uri.fromFile(new File(fname));
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setPackage("com.whatsapp");
share.putExtra(Intent.EXTRA_TEXT,ci.description);
share.putExtra(Intent.EXTRA_STREAM,uri);
share.setType("image/*");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
context.startActivity(share);
}catch (Exception what){
Toast.makeText(context,"Whatsapp have not been installed",Toast.LENGTH_LONG).show();
}
有人能帮我吗?也许你的URI有问题。。试试这个答案
Uri uri = Uri.fromFile(new File(fname));
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setPackage("com.whatsapp");
share.putExtra(Intent.EXTRA_TEXT,ci.description);
share.putExtra(Intent.EXTRA_STREAM,uri);
share.setType("image/*");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
context.startActivity(share);
}catch (Exception what){
Toast.makeText(context,"Whatsapp have not been installed",Toast.LENGTH_LONG).show();
}
意图代码:
Uri uri = Uri.fromFile(new File(fname));
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setPackage("com.whatsapp");
share.putExtra(Intent.EXTRA_TEXT,ci.description);
share.putExtra(Intent.EXTRA_STREAM,uri);
share.setType("image/*");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
context.startActivity(share);
}catch (Exception what){
Toast.makeText(context,"Whatsapp have not been installed",Toast.LENGTH_LONG).show();
}
Intent i = new Intent(Intent.ACTION_SEND);
i.setPackage("com.whatsapp");
i.setType("image/*");
i.putExtra(Intent.EXTRA_STREAM, getLocalBitmapUri(context, bitmap, id));
i.putExtra(Intent.EXTRA_TEXT, text);
context.startActivity(Intent.createChooser(i, "Share News"));
位图到URI代码:(如果有文件URI跳过此)
Uri uri = Uri.fromFile(new File(fname));
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setPackage("com.whatsapp");
share.putExtra(Intent.EXTRA_TEXT,ci.description);
share.putExtra(Intent.EXTRA_STREAM,uri);
share.setType("image/*");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
context.startActivity(share);
}catch (Exception what){
Toast.makeText(context,"Whatsapp have not been installed",Toast.LENGTH_LONG).show();
}