我正在尝试按照{分享和发送图片
上AndroidQuery应用的步骤进行操作我仔细地遵循了代码并确保一切都与它在那里完全相同,但我收到了错误。
我在“aq”上收到错误,说“aq无法解析”,而“SEND_REQUEST”则说“SEND_REQUEST无法解析为变量”
有人能帮我解决这个问题吗,我不知道为什么我会收到这些错误。
case R.id.ShareWallpaper:
String url = "http://i.telegraph.co.uk/multimedia/archive/02370/12C_Spider_4_2370457b.jpg";
File file = aq.makeSharedFile(url, "car.png");
if(file != null) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("Image/jpeg");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivityForResult(Intent.createChooser(intent, "Share via"), SEND_REQUEST);
}
break;
}
return super.onOptionsItemSelected(item);
}
答案 0 :(得分:1)
如果你想分享图片,请使用:
Bitmap bm;
BitmapDrawable drawable = (BitmapDrawable) yourimageview.getDrawable();
bm = drawable.getBitmap();
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("image/jpeg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "temporary_file.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (Exception e) {
e.printStackTrace();
}
i.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file:///sdcard/temporary_file.jpg"));
startActivity(Intent.createChooser(i, "Share via"));
SEND_REQUEST是一个整数变量,因此您必须将其声明为全局变量:
public final static int SEND_REQUEST =0;