小编xua*_*ndl的帖子

使用Intent.ACTION_PICK打开图像

我正在尝试使用intent.ACTION_PICK打开图像,但是当我使用startActivityForResoult启动活动时,我的应用程序崩溃了。我做错了什么线索吗?

    public void button_load_image(View view) {
    String path = Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/" + SimpleCamera.getAlbumName();
    File f = new File(path);

    if (f.exists()) {
        Log.d("button_load_image", "folder exists");
        if (f.isDirectory()) {
            Log.d("button_load_image", "is directory");
            Uri u = Uri.fromFile(f);
            Intent intent = new Intent(Intent.ACTION_PICK, u);
            Log.d("Intent.ACTION_PICK", "IS CREATED");              
            startActivityForResult(intent, REQUEST_CODE_LOAD_IMAGE);                
        }
    }
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_CODE_LOAD_IMAGE:
        if (resultCode == RESULT_OK) {
            Uri imageUri= data.getData();
            Log.d("image selected path", imageUri.getPath());
        }
        break;
    }
} …
Run Code Online (Sandbox Code Playgroud)

android android-intent

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

android-intent ×1