射击机器人图像选择器的意图时,仅检索图像从画廊 [英] Retrieving only images from gallery when firing android image chooser intent

查看:110
本文介绍了射击机器人图像选择器的意图时,仅检索图像从画廊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我允许用户使用以下code选择从设备的图像:

I am allowing the user to select an image from the device using the following code:

(从<一个href="http://stackoverflow.com/questions/2169649/open-an-image-in-androids-built-in-gallery-app-programmatically/2636538#2636538">this帖子)

公共类BrowsePicture延伸活动{

public class BrowsePicture extends Activity {

私有静态最终诠释SELECT_PICTURE = 1;

private static final int SELECT_PICTURE = 1;

私人字符串selectedImagePath;

private String selectedImagePath;

公共无效的onCreate(包savedInstanceState){     super.onCreate(savedInstanceState);     的setContentView(R.layout.main);

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);
            }
        });

}

公共无效onActivityResult(INT申请code,INT结果code,意图数据){     如果(结果code == RESULT_OK){         如果(要求code == SELECT_PICTURE){             乌里selectedImageUri = data.getData();             selectedImagePath = getPath(selectedImageUri);         }     } }

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

公共字符串getPath(URI URI){     的String []投影= {MediaStore.Images.Media.DATA};     光标光标= managedQuery(URI,投影,NULL,NULL,NULL);     INT与Column_Index =光标             .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);     cursor.moveToFirst();     返回cursor.getString(Column_Index中); }

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); }

在code正常工作,但它也将选择区域内显示的应用程序资源。有没有什么办法可以从选择区域删除应用程序资源?

The code works fine but it also displays application resources within the selection area. Is there any way I can remove application resources from the selection area?

推荐答案

没有。即至用户选择满足SELECT_PICTURE应用

No. That is up to the application the user chooses to satisfy the SELECT_PICTURE.

这是说,有很多方法可以从显示在图库中所有的时间通过添加标志文件夹或隐藏文件夹块图像,但是这不是你的要求。你不能从你的程序去做。

That said, there are ways to block images from showing in the Gallery all the time by adding flag files to folders or hiding the folders, but that is not what you asked. You can't do it from your program.

这篇关于射击机器人图像选择器的意图时,仅检索图像从画廊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆