當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaStore類代碼示例

本文整理匯總了Java中android.provider.MediaStore的典型用法代碼示例。如果您正苦於以下問題:Java MediaStore類的具體用法?Java MediaStore怎麽用?Java MediaStore使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MediaStore類屬於android.provider包,在下文中一共展示了MediaStore類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getImgInfo

import android.provider.MediaStore; //導入依賴的package包/類
/**
 * 獲取本地圖片信息
 * @param context
 * @param map
 */
public static void getImgInfo(Context context, HashMap<String, ArrayList<String>> map) {
    //獲取圖片信息表
    Uri imageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    ContentResolver mContentResolver = context.getContentResolver();
    Cursor mCursor = mContentResolver.query(imageUri, null,
            MediaStore.Images.Media.MIME_TYPE + "=? or " + MediaStore.Images.Media.MIME_TYPE + "=?",
            new String[]{"image/jpeg", "image/png"}, MediaStore.Images.Media.DATE_TAKEN + " DESC");
    while (mCursor.moveToNext()) {
        String imgPath = mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media.DATA));
        //獲取圖片父路徑
        String parentPath = new File(imgPath).getParentFile().getName();
        if (!map.containsKey(parentPath)) {
            ArrayList<String> childList = new ArrayList<String>();
            childList.add(imgPath);
            map.put(parentPath, childList);
        } else {
            map.get(parentPath).add(imgPath);
        }
    }
    mCursor.close();
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:27,代碼來源:MediaUtils.java

示例2: checkForDuplicateImage

import android.provider.MediaStore; //導入依賴的package包/類
/**
 * Used to find out if we are in a situation where the Camera Intent adds to images
 * to the content store. If we are using a FILE_URI and the number of images in the DB
 * increases by 2 we have a duplicate, when using a DATA_URL the number is 1.
 *
 * @param type FILE_URI or DATA_URL
 */
private void checkForDuplicateImage(int type) {
    int diff = 1;
    Uri contentStore = whichContentStore();
    Cursor cursor = queryImgDB(contentStore);
    int currentNumOfImages = cursor.getCount();

    if (type == FILE_URI && this.saveToPhotoAlbum) {
        diff = 2;
    }

    // delete the duplicate file if the difference is 2 for file URI or 1 for Data URL
    if ((currentNumOfImages - numPics) == diff) {
        cursor.moveToLast();
        int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
        if (diff == 2) {
            id--;
        }
        Uri uri = Uri.parse(contentStore + "/" + id);
        this.cordova.getActivity().getContentResolver().delete(uri, null, null);
        cursor.close();
    }
}
 
開發者ID:disit,項目名稱:siiMobilityAppKit,代碼行數:30,代碼來源:CameraLauncher.java

示例3: takePhoto

import android.provider.MediaStore; //導入依賴的package包/類
private void takePhoto() {
  Intent intentPhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  ComponentName componentName = intentPhoto.resolveActivity(getPackageManager());
  if (componentName != null) {
    // 使用 lambda 表達式捕獲局部變量,避免了將 tmpFile 作為類變量。
    File tmpFile = getTempFile(FileType.IMG);
    if (tmpFile != null) {
      BuilderUtil.createBuilder(this, intentPhoto)
          .asIntent()
          .setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
          .putExtra(MediaStore.EXTRA_OUTPUT, getUri(componentName, tmpFile))
          .asBuilder()
          .forOk((context, intent) -> context.showPicture(tmpFile))
          .start();
    }
  }
}
 
開發者ID:douo,項目名稱:ActivityBuilder,代碼行數:18,代碼來源:CameraActivity.java

示例4: cropImage

import android.provider.MediaStore; //導入依賴的package包/類
/**
     * 裁剪圖片
     *
     * @param uri
     */
    private void cropImage(Uri uri) {
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(uri, "image/*");
//        圖片處於可裁剪狀態
        intent.putExtra("crop", "true");
//        aspectX aspectY 是寬高的比例
        intent.putExtra("aspectX", 4);
        intent.putExtra("aspectY", 3);
//        是否縮放
        intent.putExtra("scale", true);
//        設置圖片的大小,提高頭像的上傳速度
        intent.putExtra("outputX", 500);
        intent.putExtra("outputY", 500);
//        以Uri的方式傳遞照片
        File cropFile = new File(getFilePath() + "crop.jpg");
        cropFileUri = Uri.fromFile(cropFile);
//        把裁剪好的圖片保存到這個路徑
        intent.putExtra(MediaStore.EXTRA_OUTPUT, cropFileUri);

        startActivityForResult(intent, CROP_REQUEST);


    }
 
開發者ID:HowieTianDev,項目名稱:ChenYan,代碼行數:29,代碼來源:PublishAActivity.java

示例5: catchIntent

import android.provider.MediaStore; //導入依賴的package包/類
private void catchIntent(){
    if (file == null)
        throw new NullPointerException("You need to set the file you want to save the image in.");

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    selectedFilePath = file.getPath();
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));

    if (activity==null)
        return;

    // start the image capture Intent
    if (dialogFragment != null)
        activity.startActivityFromFragment(dialogFragment, intent, requestCode);
    else if (fragment!= null)
        activity.startActivityFromFragment(fragment, intent, requestCode);
    else activity.startActivityForResult(intent, requestCode);
}
 
開發者ID:MobileDev418,項目名稱:chat-sdk-android-push-firebase,代碼行數:20,代碼來源:CatchImageClickListener.java

示例6: openCamera

import android.provider.MediaStore; //導入依賴的package包/類
public void openCamera() {
    try {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File image = AndroidUtilities.generatePicturePath();
        if (image != null) {
            if (Build.VERSION.SDK_INT >= 24) {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(parentFragment.getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", image));
                takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            } else {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
            }
            currentPicturePath = image.getAbsolutePath();
        }
        parentFragment.startActivityForResult(takePictureIntent, 13);
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:20,代碼來源:AvatarUpdater.java

示例7: loadInBackground

import android.provider.MediaStore; //導入依賴的package包/類
@Override
public Cursor loadInBackground() {
    Cursor albums = super.loadInBackground();
    MatrixCursor allAlbum = new MatrixCursor(COLUMNS);
    int totalCount = 0;
    String allAlbumCoverPath = "";
    if (albums != null) {
        while (albums.moveToNext()) {
            totalCount += albums.getInt(albums.getColumnIndex(COLUMN_COUNT));
        }
        if (albums.moveToFirst()) {
            allAlbumCoverPath = albums.getString(albums.getColumnIndex(MediaStore.MediaColumns.DATA));
        }
    }
    allAlbum.addRow(new String[]{Album.ALBUM_ID_ALL, Album.ALBUM_ID_ALL, Album.ALBUM_NAME_ALL, allAlbumCoverPath,
            String.valueOf(totalCount)});

    return new MergeCursor(new Cursor[]{allAlbum, albums});
}
 
開發者ID:zhihu,項目名稱:Matisse,代碼行數:20,代碼來源:AlbumLoader.java

示例8: getPathOfImage

import android.provider.MediaStore; //導入依賴的package包/類
public static String getPathOfImage(Context context, Uri uri) throws URISyntaxException {
    Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
    if (cursor.moveToFirst()) {
        String document_id = cursor.getString(0);
        document_id = document_id.substring(document_id.lastIndexOf(":") + 1);
        cursor.close();

        cursor = context.getContentResolver().query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                null, MediaStore.Images.Media._ID + " = ? ", new String[]{document_id}, null);
        if (cursor.moveToFirst()) {
            String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
            cursor.close();
            return path;
        } else return null;
    } else return null;
}
 
開發者ID:architjn,項目名稱:SharePanel,代碼行數:18,代碼來源:Utils.java

示例9: instantiateItem

import android.provider.MediaStore; //導入依賴的package包/類
public Object instantiateItem(ViewGroup container, int position){
    View v = inflater.inflate(R.layout.viewpager_image,null);
    ImageView imgView = (ImageView) v.findViewById(R.id.viewPagerImage);
    //이미지를 가져옴
    Uri uri = Uri.fromFile(new File(cards.get(position)));

    try {
        Bitmap bitmap = MediaStore.Images.Media.getBitmap(inflater.getContext().getContentResolver(),uri);
        int nh = (int) (bitmap.getHeight() * (1024.0 / bitmap.getWidth()));
        Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 1024, nh, true);

        imgView.setImageBitmap(scaled);

    } catch (IOException e) {
        e.printStackTrace();
    }
    container.addView(v);

    return v;
}
 
開發者ID:gugusny5758,項目名稱:OSS-green-07,代碼行數:21,代碼來源:CardNewsPagerAdapter.java

示例10: captureImage

import android.provider.MediaStore; //導入依賴的package包/類
/**
 * Start camera intent
 * Create a temporary file and pass file Uri to camera intent
 */
private void captureImage() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (intent.resolveActivity(getPackageManager()) != null) {
        File imageFile = ImageUtils.createImageFile(imageDirectory);
        if (imageFile != null) {
            String authority = getPackageName() + ".fileprovider";
            Uri uri = FileProvider.getUriForFile(this, authority, imageFile);
            currentImagePath = "file:" + imageFile.getAbsolutePath();
            intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
            startActivityForResult(intent, Constants.REQUEST_CODE_CAPTURE);
        } else {
            Toast.makeText(this, getString(R.string.error_create_image_file), Toast.LENGTH_LONG).show();
        }
    } else {
        Toast.makeText(this, getString(R.string.error_no_camera), Toast.LENGTH_LONG).show();
    }
}
 
開發者ID:sega4revenge,項目名稱:Sega,代碼行數:22,代碼來源:ImagePickerActivity.java

示例11: captureVideo

import android.provider.MediaStore; //導入依賴的package包/類
public void captureVideo(Activity activity, final ModuleResultListener listener) {
    if (mIsTakingVideo) {
        listener.onResult(Util.getError(Constant.CAMERA_BUSY, Constant.CAMERA_BUSY_CODE));
        return;
    }

    mCaptureVideoStartTime = System.currentTimeMillis();
    mIsTakingVideo = true;
    String fileName = "nat_video_" + new Date().getTime() + ".mov";
    Intent intent = new Intent();
    intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    try {
        videoFile = Util.getFile(fileName);
    } catch (IOException e) {
        e.printStackTrace();
    }
    Uri uri = Uri.fromFile(videoFile);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    activity.startActivityForResult(intent, Constant.VIDEO_REQUEST_CODE);
}
 
開發者ID:natjs,項目名稱:nat-camera,代碼行數:22,代碼來源:CameraModule.java

示例12: handleImageOnKitKat

import android.provider.MediaStore; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.KITKAT)
public void handleImageOnKitKat(Intent data) {
    String imagePath=null;
    Uri uri=data.getData();
    if (DocumentsContract.isDocumentUri(this,uri)){
        //如果是document類型的Uri,則通過document id處理
        String docId=DocumentsContract.getDocumentId(uri);
        if ("com.android.providers.media.documents".equals(uri.getAuthority())){
            String id=docId.split(":")[1];//解析數字可是的id
            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("content://downloads/punlic_downloads"),Long.valueOf(docId));
            imagePath=getImagePath(contentUri,null);
        }
    }else if ("content".equalsIgnoreCase(uri.getScheme())){
        //如果是content類型的Uri,則使用普通方法
        imagePath=getImagePath(uri,null);
    }else  if ("file".equalsIgnoreCase(uri.getScheme())){
        imagePath=uri.getPath();
    }
    displayImage(imagePath);//根據圖片路徑顯示圖片
}
 
開發者ID:guzhigang001,項目名稱:QNewsDemo,代碼行數:25,代碼來源:MainActivity.java

示例13: captureImage

import android.provider.MediaStore; //導入依賴的package包/類
public void captureImage(Activity activity, final ModuleResultListener listener){
    if (mIsTakingPhoto) {
        listener.onResult(Util.getError(Constant.CAMERA_BUSY, Constant.CAMERA_BUSY_CODE));
        return;
    }
    mCaptureImgStartTime = System.currentTimeMillis();

    mIsTakingPhoto = true;

    String fileName = "nat_img_" + new Date().getTime() + ".jpg";
    Intent intent = new Intent();
    intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    try {
        finalImageFile = Util.getFile(fileName);
    } catch (IOException e) {
        e.printStackTrace();
        listener.onResult(Util.getError(Constant.CAMERA_INTERNAL_ERROR, Constant.CAMERA_INTERNAL_ERROR_CODE));
    }
    Uri uri = Uri.fromFile(finalImageFile);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

    activity.startActivityForResult(intent, Constant.IMAGE_REQUEST_CODE);
}
 
開發者ID:natjs,項目名稱:nat-camera,代碼行數:25,代碼來源:CameraModule.java

示例14: dispatchTakePictureIntentTest3

import android.provider.MediaStore; //導入依賴的package包/類
private void dispatchTakePictureIntentTest3() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile(false);
        } catch (IOException ex) {
            // Error occurred while creating the File
            ex.printStackTrace();
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(this,
                    "com.ge.droid.takingphotossimply.fileprovider",
                    photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PICTURE_TEST_3);
        }
    }
}
 
開發者ID:gejiaheng,項目名稱:TakingPhotosSimply,代碼行數:23,代碼來源:MainActivity.java

示例15: getRealPathFromURI

import android.provider.MediaStore; //導入依賴的package包/類
public static String getRealPathFromURI(Context context, Uri contentURI) throws Exception {
    String result;
    String[] proj = {MediaStore.Images.Media.DATA};
    try {
        Cursor cursor = context.getContentResolver().query(contentURI, proj, null, null, null);
        if (cursor == null || cursor.getCount() == 0) { // Source is Dropbox or other similar local file path
            result = contentURI.getPath();
        } else {
            cursor.moveToFirst();
            int idx = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            result = cursor.getString(idx);
            if (result == null) {
                result = contentURI.getPath();
            }
            cursor.close();
        }
        return result;
    } catch (Exception e) {
        throw new Exception(e.getMessage());
    }
}
 
開發者ID:nhocga1995s,項目名稱:MyCalendar,代碼行數:22,代碼來源:FunctionHelper.java


注:本文中的android.provider.MediaStore類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。