當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。