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

本文介绍如何在Java应用中通过Intent获取SD卡上指定类型文件,并获取所选图片的完整路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Java代码
  1. Intent intent =  new  Intent(Intent.ACTION_GET_CONTENT);   
  2. // 告诉打开的内容   
  3.   
  4. intent.setType("file:///sdcard/image/*" );    
  5. startActivityForResult(intent, 1 );   
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
// 告诉打开的内容

intent.setType("file:///sdcard/image/*");  
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.    }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值