【问题标题】:Retrieving only images from gallery when firing android image chooser intent触发android图像选择器意图时仅从图库中检索图像
【发布时间】:2017-04-07 16:37:48
【问题描述】:

我允许用户使用以下代码从设备中选择图像:

(来自this post

public class BrowsePicture extends Activity {

private static final int SELECT_PICTURE = 1;

private String selectedImagePath;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ((Button) findViewById(R.id.Button01))
            .setOnClickListener(new OnClickListener() {

                public void onClick(View arg0) {

                    // in onCreate or any event where your want the user to
                    // select a file
                    Intent intent = new Intent();
                    intent.setType("image/*");
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    startActivityForResult(Intent.createChooser(intent,
                            "Select Picture"), SELECT_PICTURE);
                }
            });
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_PICTURE) {
            Uri selectedImageUri = data.getData();
            selectedImagePath = getPath(selectedImageUri);
        }
    }
}

public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    int column_index = cursor
            .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

代码工作正常,但它也显示所选区域内的应用程序资源。有什么方法可以从选择区域中删除应用程序资源?

【问题讨论】:

    标签: android image android-activity android-intent gallery


    【解决方案1】:

    没有。这取决于用户选择满足 SELECT_PICTURE 的应用程序。

    也就是说,有一些方法可以通过将标志文件添加到文件夹或隐藏文件夹来阻止图像一直显示在图库中,但这不是您所要求的。你不能在你的程序中做到这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多