我正在使用Gallery类型的应用。我想在点击特定图像时添加共享选项,但未能这样做。
我试图创建Intents,它没有用。我该怎么办?
这是我的适配器类代码:https://gist.github.com/mukundmadhav/e63fcf7e34414b9b88458400a6d55651
(同样用于测试我在可绘制文件夹中保存了8张图片)
当我使用Intents时,它会显示以下错误消息: 错误:(51,17)错误:找不到符号方法startActivity(Intent)
我已导入android.content.Intent但错误仍然存在。
答案 0 :(得分:0)
在适配器中尝试:
viewHolder.img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//here write code to share image //get clicked image bitmap and then share
Bitmap bitmap = ((BitmapDrawable)viewHolder.img.getDrawable()).getBitmap();
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/png");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap , "Title", null);
// Uri uri = Uri.parse("android.resource://your package
//name/"+R.drawable.ic_launcher);
Uri uri = Uri.parse(path);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello, This is test Sharing");
startActivity(Intent.createChooser(shareIntent, "Send your image"));
}
});