使用android共享对话框共享图像和文本
是否可以使用android共享对话框向facebook、instagram和whatsapp共享图像和文本?我尝试了两周,但没有成功。我唯一能做的就是在不使用共享对话框的情况下为每个媒体编写一些代码。这是一些与whatsapp一起使用的代码,但不适用于insta和facebook使用android共享对话框共享图像和文本,android,Android,是否可以使用android共享对话框向facebook、instagram和whatsapp共享图像和文本?我尝试了两周,但没有成功。我唯一能做的就是在不使用共享对话框的情况下为每个媒体编写一些代码。这是一些与whatsapp一起使用的代码,但不适用于insta和facebook String DishImage = listDishes.get(selectedDish).getDishImage(); Picasso.with(this).load(DishImage
String DishImage = listDishes.get(selectedDish).getDishImage();
Picasso.with(this).load(DishImage).into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bm, Picasso.LoadedFrom from) {
OutputStream fOut = null;
Uri outputFileUri;
try {
File root = new File(Environment.getExternalStorageDirectory() + File.separator + "FoodMana" + File.separator);
root.mkdirs();
File sdImageMainDirectory = new File(root, "myPicName.jpg");
fOut = new FileOutputStream(sdImageMainDirectory);
} catch (Exception e) {Toast.makeText(getApplicationContext(), "Error occured. Please try again later.", Toast.LENGTH_SHORT).show();}
try {
bm.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
} catch (Exception e) {
}
Intent waIntent = new Intent(android.content.Intent.ACTION_SEND);
waIntent.setType("image/*");
waIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment.getExternalStorageDirectory()
+ File.separator + "FoodMana" + File.separator + "myPicName.jpg"));
waIntent.putExtra(Intent.EXTRA_TEXT, "I am going to eat that dish!!!!!" + "\n" + "what do you think? check out");
startActivity(Intent.createChooser(waIntent, "Share with"));
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
Log.d("TAG","error");
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
Log.d("TAG","prepared");
}
});
我用这个来分享一个链接 我从
al\u details.get(getLayoutPosition()).get(URL\u WEB.toString())获取链接
我在网上尝试了很多东西,但最后我做到了。所以你可以试一下。好的,我找到了解决办法
String DishImage = listDishes.get(selectedDish).getDishImage();
Picasso.with(this).load(DishImage).into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bm, Picasso.LoadedFrom from) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Hey view/download this image");
String path = null;
path = MediaStore.Images.Media.insertImage(getContentResolver(), bm, "", null);
Uri screenshotUri = Uri.parse(path);
intent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
intent.setType("image/*");
startActivity(Intent.createChooser(intent, "Share image via..."));
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
Log.d("TAG","error");
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
Log.d("TAG","prepared");
}
});
String DishImage = listDishes.get(selectedDish).getDishImage();
Picasso.with(this).load(DishImage).into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bm, Picasso.LoadedFrom from) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Hey view/download this image");
String path = null;
path = MediaStore.Images.Media.insertImage(getContentResolver(), bm, "", null);
Uri screenshotUri = Uri.parse(path);
intent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
intent.setType("image/*");
startActivity(Intent.createChooser(intent, "Share image via..."));
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
Log.d("TAG","error");
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
Log.d("TAG","prepared");
}
});