当前位置: 首页>>代码示例>>Java>>正文


Java Media类代码示例

本文整理汇总了Java中android.provider.MediaStore.Images.Media的典型用法代码示例。如果您正苦于以下问题:Java Media类的具体用法?Java Media怎么用?Java Media使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Media类属于android.provider.MediaStore.Images包,在下文中一共展示了Media类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildAlbumInfo

import android.provider.MediaStore.Images.Media; //导入依赖的package包/类
private void buildAlbumInfo(ContentResolver cr) {
    String[] distinctBucketColumns = new String[]{Media.BUCKET_ID, Media.BUCKET_DISPLAY_NAME};
    Cursor bucketCursor = null;
    try {
        bucketCursor = cr.query(Media.EXTERNAL_CONTENT_URI, distinctBucketColumns, "0==0)" + " GROUP BY(" + Media.BUCKET_ID, null,
                Media.DATE_MODIFIED + " desc");
        if (bucketCursor != null && bucketCursor.moveToFirst()) {
            do {
                String buckId = bucketCursor.getString(bucketCursor.getColumnIndex(Media.BUCKET_ID));
                String name = bucketCursor.getString(bucketCursor.getColumnIndex(Media.BUCKET_DISPLAY_NAME));
                AlbumEntity album = buildAlbumInfo(name, buckId);
                if (!TextUtils.isEmpty(buckId)) {
                    buildAlbumCover(cr, buckId, album);
                }
            } while (bucketCursor.moveToNext() && !bucketCursor.isLast());
        }
    } finally {
        if (bucketCursor != null) {
            bucketCursor.close();
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:AlbumTask.java

示例2: buildAlbumCover

import android.provider.MediaStore.Images.Media; //导入依赖的package包/类
/**
 * get the cover and count
 *
 * @param buckId album id
 */
private void buildAlbumCover(ContentResolver cr, String buckId, AlbumEntity album) {
    String[] photoColumn = new String[]{Media._ID, Media.DATA};
    Cursor coverCursor = cr.query(Media.EXTERNAL_CONTENT_URI, photoColumn, SELECTION_ID,
            new String[]{buckId, "image/jpeg", "image/png", "image/jpg", "image/gif"}, Media.DATE_MODIFIED + " desc");
    try {
        if (coverCursor != null && coverCursor.moveToFirst()) {
            String picPath = coverCursor.getString(coverCursor.getColumnIndex(Media.DATA));
            String id = coverCursor.getString(coverCursor.getColumnIndex(Media._ID));
            album.mCount = coverCursor.getCount();
            album.mImageList.add(new ImageMedia(id, picPath));
            if (album.mImageList.size() > 0) {
                mBucketMap.put(buckId, album);
            }
        }
    } finally {
        if (coverCursor != null) {
            coverCursor.close();
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:AlbumTask.java

示例3: buildAlbumInfo

import android.provider.MediaStore.Images.Media; //导入依赖的package包/类
private void buildAlbumInfo(ContentResolver cr) {
    String[] distinctBucketColumns = new String[]{Media.BUCKET_ID, Media.BUCKET_DISPLAY_NAME};
    Cursor bucketCursor = null;
    try {
        bucketCursor = cr.query(Media.EXTERNAL_CONTENT_URI, distinctBucketColumns, "0==0)" + " GROUP BY(" + Media.BUCKET_ID, null,
                Media.DATE_MODIFIED + " desc");
        if (bucketCursor != null && bucketCursor.moveToFirst()) {
            do {
                String buckId = bucketCursor.getString(bucketCursor.getColumnIndex(Media.BUCKET_ID));
                String name = bucketCursor.getString(bucketCursor.getColumnIndex(Media.BUCKET_DISPLAY_NAME));
                AlbumEntity album = buildAlbumInfo(name, buckId);
                if (!TextUtils.isEmpty(buckId)) {
                    buildAlbumCover(cr, buckId, album);
                }
            } while (bucketCursor.moveToNext());
        }
    } finally {
        if (bucketCursor != null) {
            bucketCursor.close();
        }
    }
}
 
开发者ID:Bilibili,项目名称:boxing,代码行数:23,代码来源:AlbumTask.java

示例4: PhotoDirectoryLoader

import android.provider.MediaStore.Images.Media; //导入依赖的package包/类
public PhotoDirectoryLoader(Context context, boolean showGif) {
  super(context);

  setProjection(IMAGE_PROJECTION);
  setUri(Media.EXTERNAL_CONTENT_URI);
  setSortOrder(Media.DATE_ADDED + " DESC");

  setSelection(
      MIME_TYPE + "=? or " + MIME_TYPE + "=? or "+ MIME_TYPE + "=? " + (showGif ? ("or " + MIME_TYPE + "=?") : ""));
  String[] selectionArgs;
  if (showGif) {
    selectionArgs = new String[] { "image/jpeg", "image/png", "image/jpg","image/gif" };
  } else {
    selectionArgs = new String[] { "image/jpeg", "image/png", "image/jpg" };
  }
  setSelectionArgs(selectionArgs);
}
 
开发者ID:zuoweitan,项目名称:Hitalk,代码行数:18,代码来源:PhotoDirectoryLoader.java

示例5: onClick

import android.provider.MediaStore.Images.Media; //导入依赖的package包/类
public void onClick(View v) {
    int id = v.getId();
    if (R.id.btn_share == id) {
        this.mIvQrCodeArea.setDrawingCacheEnabled(true);
        PageJumpUtil.jumpToPageSystemShare(this, "", "", "", Uri.parse(Media.insertImage(getContentResolver(), this.mIvQrCodeArea.getDrawingCache(), null, null)));
    } else if (R.id.btn_refresh == id) {
        DialogUtil.showDialog(this, getResources().getString(R.string.qrcode_gen_refresh_prompt), "", "", null, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                QrCodeShareActivity.this.refreshQrCode();
            }
        });
    } else if (R.id.common_nav_left == id) {
        finish();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:17,代码来源:QrCodeShareActivity.java

示例6: getRealPathByUri

import android.provider.MediaStore.Images.Media; //导入依赖的package包/类
public static String getRealPathByUri(Context context, Uri uri) {
    if ("file".equals(uri.getScheme())) {
        return uri.getPath();
    }
    try {
        Cursor cursor = Media.query(context.getContentResolver(), uri, new String[]{"_data"});
        String realPath = null;
        if (cursor == null) {
            return null;
        }
        int columnIndex = cursor.getColumnIndexOrThrow("_data");
        if (cursor.getCount() > 0 && cursor.moveToFirst()) {
            realPath = cursor.getString(columnIndex);
        }
        cursor.close();
        return realPath;
    } catch (Exception e) {
        return uri.getPath();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:MQUtils.java

示例7: getLatestPath

import android.provider.MediaStore.Images.Media; //导入依赖的package包/类
public static String getLatestPath(Context context) {
    String imageLocation = null;
    Cursor cursor = null;
    try {
        cursor = context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new
                String[]{"_id", "_data", "bucket_display_name", "datetaken", "mime_type"},
                null, null, "_id DESC");
        if (cursor != null && cursor.moveToFirst()) {
            imageLocation = cursor.getString(cursor.getColumnIndex("_data"));
        }
        if (cursor != null) {
            cursor.close();
        }
        return imageLocation;
    } catch (Throwable th) {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:MediaStoreUtils.java

示例8: getBuckets

import android.provider.MediaStore.Images.Media; //导入依赖的package包/类
static List<Image> getBuckets(Context context) {
    final Cursor cursor = Media.query(context.getContentResolver(), URI, PROJECTION,
            "1 = 1) GROUP BY (" + Media.BUCKET_ID,  // WTF
            Media.DATE_ADDED + " DESC");

    final List<Image> images = new ArrayList<>();
    final File root = Environment.getExternalStorageDirectory();

    if (cursor.moveToFirst()) {
        do {
            final Image image = Image.fromCursor(cursor);
            if (image.getParentFile().equals(root)) {
                continue;
            }
            images.add(image);
        } while (cursor.moveToNext());
    }

    cursor.close();

    return images;
}
 
开发者ID:oxoooo,项目名称:nomedia,代码行数:23,代码来源:MediaStoreUtils.java

示例9: getImages

import android.provider.MediaStore.Images.Media; //导入依赖的package包/类
static List<Image> getImages(Context context, String bucketId, int limit) {
    final Cursor cursor = Media.query(context.getContentResolver(), URI, PROJECTION,
            Media.BUCKET_ID + " = ?", new String[]{bucketId},
            Media.DATE_ADDED + " DESC");

    final List<Image> images = new ArrayList<>();
    int count = 0;

    if (cursor.moveToFirst()) {
        do {
            images.add(Image.fromCursor(cursor));
            count++;
        } while (count < limit && cursor.moveToNext());
    }

    cursor.close();

    return images;
}
 
开发者ID:oxoooo,项目名称:nomedia,代码行数:20,代码来源:MediaStoreUtils.java

示例10: decodeIntentBundle

import android.provider.MediaStore.Images.Media; //导入依赖的package包/类
@Test
public void decodeIntentBundle() {
  Bundle bundle = new Bundle();

  ContentUriTrigger uriTrigger = getContentUriTrigger();
  Bundle encode = encodeContentUriJob(uriTrigger, coder);
  bundle.putBundle(GooglePlayJobWriter.REQUEST_PARAM_EXTRAS, encode);

  ArrayList<Uri> uris = new ArrayList<>();
  uris.add(ContactsContract.AUTHORITY_URI);
  uris.add(Media.EXTERNAL_CONTENT_URI);
  bundle.putParcelableArrayList(BundleProtocol.PACKED_PARAM_TRIGGERED_URIS, uris);

  JobInvocation jobInvocation = coder.decodeIntentBundle(bundle);

  assertEquals(uris, jobInvocation.getTriggerReason().getTriggeredContentUris());
  assertEquals("TAG", jobInvocation.getTag());
  assertEquals(uriTrigger.getUris(), ((ContentUriTrigger) jobInvocation.getTrigger()).getUris());
  assertEquals(TestJobService.class.getName(), jobInvocation.getService());
  assertEquals(
      RetryStrategy.DEFAULT_EXPONENTIAL.getPolicy(),
      jobInvocation.getRetryStrategy().getPolicy());
}
 
开发者ID:firebase,项目名称:firebase-jobdispatcher-android,代码行数:24,代码来源:JobCoderTest.java

示例11: prepareJob

import android.provider.MediaStore.Images.Media; //导入依赖的package包/类
@Test
public void prepareJob() {
  Intent intent = new Intent();

  Bundle encode = encodeContentUriJob(getContentUriTrigger(), TestUtil.JOB_CODER);
  intent.putExtra(GooglePlayJobWriter.REQUEST_PARAM_EXTRAS, encode);

  Parcel container = Parcel.obtain();
  container.writeStrongBinder(new Binder());
  PendingCallback pcb = new PendingCallback(container);
  intent.putExtra("callback", pcb);

  ArrayList<Uri> uris = new ArrayList<>();
  uris.add(ContactsContract.AUTHORITY_URI);
  uris.add(Media.EXTERNAL_CONTENT_URI);
  intent.putParcelableArrayListExtra(BundleProtocol.PACKED_PARAM_TRIGGERED_URIS, uris);

  JobInvocation jobInvocation = receiver.prepareJob(intent);
  assertEquals(jobInvocation.getTriggerReason().getTriggeredContentUris(), uris);
}
 
开发者ID:firebase,项目名称:firebase-jobdispatcher-android,代码行数:21,代码来源:GooglePlayReceiverTest.java

示例12: PhotoDirectoryLoader

import android.provider.MediaStore.Images.Media; //导入依赖的package包/类
public PhotoDirectoryLoader(Context context, boolean showGif) {
  super(context);

  setProjection(IMAGE_PROJECTION);
  setUri(Media.EXTERNAL_CONTENT_URI);
  setSortOrder(Media.DATE_ADDED + " DESC");

  setSelection(
      MIME_TYPE + "=? or " + MIME_TYPE + "=? " + (showGif ? ("or " + MIME_TYPE + "=?") : ""));
  String[] selectionArgs;
  if (showGif) {
    selectionArgs = new String[] { "image/jpeg", "image/png", "image/gif" };
  } else {
    selectionArgs = new String[] { "image/jpeg", "image/png" };
  }
  setSelectionArgs(selectionArgs);
}
 
开发者ID:jiang111,项目名称:ObservableScheduler,代码行数:18,代码来源:PhotoDirectoryLoader.java

示例13: handleImageOnKitKat

import android.provider.MediaStore.Images.Media; //导入依赖的package包/类
@TargetApi(19)
private void handleImageOnKitKat(Intent data){
	String imagePath=null;
	Uri uri=data.getData();
	if(DocumentsContract.isDocumentUri(this,uri)){
		String docId=DocumentsContract.getDocumentId(uri);
		if("com.android.providers.media.documents".equals(uri.getAuthority())){
			String id=docId.split(":")[1];
			String selection=MediaStore.Images.Media._ID+"="+id;
			imagePath=getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,selection);
		}else if("com.android.providers.downloads.documents".equals(uri.getAuthority())){
			Uri contentUri=ContentUris.withAppendedId(Uri.parse("cintent://downloads/public_downloads"),Long.valueOf(docId));
			imagePath=getImagePath(contentUri,null);
		}	
	}else if("content".equalsIgnoreCase(uri.getScheme())){
		imagePath=getImagePath(uri,null);
	}
	displayImage(imagePath);
}
 
开发者ID:1641835946,项目名称:MyPlan,代码行数:20,代码来源:LifeActivity.java

示例14: showFileChooser

import android.provider.MediaStore.Images.Media; //导入依赖的package包/类
private void showFileChooser() {
    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK,
            Media.EXTERNAL_CONTENT_URI);
    photoPickerIntent.setType("image/*");
    photoPickerIntent.putExtra("crop", "true");
    photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
    photoPickerIntent.putExtra("outputFormat", CompressFormat.JPEG.toString());
    startActivityForResult(photoPickerIntent, PICK_IMAGE_REQUEST);
}
 
开发者ID:maysamrasoli,项目名称:Doctor,代码行数:10,代码来源:ActivitySendAds.java

示例15: getCurrent

import android.provider.MediaStore.Images.Media; //导入依赖的package包/类
/**
 * 获取最近使用的照片
 * 
 * @return
 */
public List<PhotoModel> getCurrent() {
    Cursor cursor = resolver.query(Media.EXTERNAL_CONTENT_URI, new String[] {
            ImageColumns.DATA,
            ImageColumns.DATE_ADDED, ImageColumns.SIZE
    }, null, null, ImageColumns.DATE_ADDED);
    if (cursor == null || !cursor.moveToNext())
        return new ArrayList<PhotoModel>();
    List<PhotoModel> photos = new ArrayList<PhotoModel>();
    cursor.moveToLast();
    do {
        if (cursor.getLong(cursor.getColumnIndex(ImageColumns.SIZE)) > 1024 * 10) {
            PhotoModel photoModel = new PhotoModel();
            photoModel.setOriginalPath(cursor.getString(cursor
                    .getColumnIndex(ImageColumns.DATA)));
            photos.add(photoModel);
        }
    } while (cursor.moveToPrevious());
    IOUtils.closeQuietly(cursor);
    return photos;
}
 
开发者ID:umeng,项目名称:umeng_community_android,代码行数:26,代码来源:AlbumController.java


注:本文中的android.provider.MediaStore.Images.Media类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。