// GET THE URI FROM THE IMAGE (YOU NEED A BITMAP FOR THIS - WORKAROUND FOLLOWS)
Uri tempUri = getImageUri(getApplicationContext(), bitmap);
public Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
}
// THE WORKAROUND (OPTIONAL IN CASE YOU DO NOT HAVE A BITMAP)
Bitmap bitmap = ((BitmapDrawable)youImageView.getDrawable()).getBitmap();
信用:https ://stackoverflow.com/a/8306683/450534
// NOW THAT YOU WILL HAVE THE URI, USE THIS TO GET THE ABSOLUTE PATH OF THE IMAGE
File finalFile = new File(getRealPathFromURI(tempUri));
public String getRealPathFromURI(Uri uri) {
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
return cursor.getString(idx);
}
根据我使用 Android 的经验,我唯一需要的是当我开始使用 Twitter4J SDK 和 TwitPic API 时。TwitPic 需要你要上传的图片的绝对路径。这是我找到的最好的解决方案(实际上是几种不同解决方案的组合),但它总是很有魅力。希望它可以帮助你。