[英]Share image to whatsapp Android 7.1.1
我正在应用程序中创建图像,并允许用户直接在whatsapp,facebook,instagram等中发送图像。它在Android 7.1.1中不起作用。 它不会产生任何错误发送。 共享意图很好,没有任何问题,只是不能与Facebook,whatsapp等自定义共享意图一起工作。我的代码如下。 让我知道是否有人对此有何疑问。
private void shareViaInstaApp() {
try {
Intent instaIntent = new Intent(Intent.ACTION_SEND);
File imageFile = new File(rootFile.toString());
Uri imageUri = FileProvider.getUriForFile(PreviewActivity.this,
BuildConfig.APPLICATION_ID + ".provider", imageFile);
instaIntent.putExtra(Intent.EXTRA_TEXT, "Share..");
instaIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
instaIntent.setType("image/*");
instaIntent.setPackage("com.instagram.android");
instaIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(instaIntent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
Toast.makeText(PreviewActivity.this, "You don't seem to have Instagram installed on this device", Toast.LENGTH_SHORT).show();
}
}
调试未从此行前行
BuildConfig.APPLICATION_ID + ".provider", imageFile);
谢谢
如果要共享特定应用程序,则只需使用instaIntent.setPackage("Pacakename")
必须删除此行。
和
专门分享在whatsapp中使用这种方式
instaIntent.setPackage("com.whatsapp")
专门分享给Messenger使用这种方式
instaIntent.setPackage("com.facebook.orca")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.