我写了一个简单的代码,用于从任何支持图像的应用程序中导入图像
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);代码在从图库导入图像时运行良好,但只要我在我的摩托罗拉xoom中从picasa导入图像。它返回null,并且force以NullPointerException结束。
有人知道这是怎么回事吗?
发布于 2012-01-20 12:15:56
ACTIVITYRESULT_CHOOSEPICTURE是调用startActivity(intent,requestCode)时使用的整型;
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == ACTIVITYRESULT_CHOOSEPICTURE) {
BitmapFactory.Options options = new BitmapFactory.Options();
final InputStream is = context.getContentResolver().openInputStream(intent.getData());
final Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
is.close();
}https://stackoverflow.com/questions/6358248
复制相似问题