android Intent.setType() 过滤图片,返回所有的文件类型

我想在我的app中通过Intent从启动的应用程序中刚抓取图片

我尝试使用如下代码:
 

Intent intent = new Intent("android.intent.action.GET_CONTENT");
    intent.addCategory("android.intent.category.OPENABLE");
    intent.setType("image/*");


处理方法

id.os.Bundle;
 
 
 
public class StackOverflowAppActivity extends Activity {
  
    private final int PICK_IMAGE = 0;
 
 
 
    /** Called when the activity is first created. */
  
    @Override
  
    public void onCreate(Bundle savedInstanceState) {
  
        super.onCreate(savedInstanceState);
  
        setContentView(R.layout.main);
 
 
 
        Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  
        startActivityForResult(i, PICK_IMAGE);
 
 
 
 
    }
 
 
 
    @Override
  
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  
        super.onActivityResult(requestCode, resultCode, data);
 
 
 
        switch (requestCode) {
 
 
 
        case PICK_IMAGE:
  
            if (resultCode == RESULT_OK) {
  
                // do your thing
  
            }
  
        }
  
    }
}
}


原文地址:http://www.itmmd.com/201411/188.html 
该文章由 萌萌的IT人 整理发布,转载须标明出处。

你可能感兴趣的:(android)