//打开系统相册 Intent intent=new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); startActivity(intent);
//打开指定的一张照片 Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(pictureFilepath), "image/*"); startActivity(intent);
//打开系统相册浏览照片 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/internal/images/media")); startActivity(intent);
// 采用MediaScannerConnection扫描制定路径下的图片文件,并启动系统相册进行浏览
自己写的一个类
public class PictureScanner implements MediaScannerConnection.MediaScannerConnectionClient{ private MediaScannerConnection mMs; private File mFile; private Context context; File[] allFiles ; public PictureScanner(Context context) { File folder = new File(pictureFolderPath); allFiles = folder.listFiles(); swap(allFiles); this.context = context; mFile = allFiles[0]; mMs = new MediaScannerConnection(context, this); mMs.connect(); } public void onMediaScannerConnected() { mMs.scanFile(mFile.getAbsolutePath(), null); } public void onScanCompleted(String path, Uri uri) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(uri); context.startActivity(intent); mMs.disconnect(); } private void swap(File a[]){ int len = a.length; for(int i=0;i<len/2;i++){ File tmp = a[i]; a[i] = a[len-1-i]; a[len-1-i] = tmp; } } }
//调用 new PictureScanner(MyActivity.this);
时间: 2024-10-18 23:37:45