调用系统内置的gallery查看图片

来源:互联网 发布:服务器端软件有哪些 编辑:程序博客网 时间:2024/05/22 12:32
Java代码
  1. Intent intent = new Intent(Intent.ACTION_GET_CONTENT);   
  2. // 告诉打开的内容  
  3.   
  4. intent.setType("file:///sdcard/image/*");    
  5. startActivityForResult(intent, 1);   

 

Java代码
  1. protected final void onActivityResult(final int requestCode, final int   
  2.                      resultCode, final Intent i) {   
  3.     super.onActivityResult(requestCode, resultCode, i);   
  4.    
  5.   // this matches the request code in the above call   
  6.   if (requestCode == 1) {   
  7.       Uri _uri = i.getData();   
  8.    
  9.     // this will be null if no image was selected...   
  10.     if (_uri != null) {   
  11.       // now we get the path to the image file   
  12.      cursor = getContentResolver().query(_uri, null,   
  13.                                       nullnullnull);   
  14.      cursor.moveToFirst();   
  15.      String imageFilePath = cursor.getString(0);   
  16.      cursor.close();   
  17.      }   
  18.    }  
原创粉丝点击