Search in sources :

Example 1 with MediaScannerConnection

use of android.media.MediaScannerConnection in project cordova-android-chromeview by thedracle.

the class CameraLauncher method scanForGallery.

private void scanForGallery(Uri newImage) {
    this.scanMe = newImage;
    if (this.conn != null) {
        this.conn.disconnect();
    }
    this.conn = new MediaScannerConnection(this.cordova.getActivity().getApplicationContext(), this);
    conn.connect();
}
Also used : MediaScannerConnection(android.media.MediaScannerConnection)

Example 2 with MediaScannerConnection

use of android.media.MediaScannerConnection in project jpHolo by teusink.

the class CameraLauncher method scanForGallery.

private void scanForGallery(Uri newImage) {
    this.scanMe = newImage;
    if (this.conn != null) {
        this.conn.disconnect();
    }
    this.conn = new MediaScannerConnection(this.cordova.getActivity().getApplicationContext(), this);
    conn.connect();
}
Also used : MediaScannerConnection(android.media.MediaScannerConnection)

Example 3 with MediaScannerConnection

use of android.media.MediaScannerConnection in project storymaker by StoryMaker.

the class MediaHelper method handleResult.

public MediaHelper.MediaResult handleResult(int requestCode, int resultCode, Intent intent, File fileTmp) {
    MediaResult result = null;
    if (requestCode == MediaConstants.GALLERY_RESULT) {
        if (intent != null) {
            Uri uriGalleryFile = intent.getData();
            try {
                if (uriGalleryFile != null) {
                    Cursor cursor = mActivity.managedQuery(uriGalleryFile, null, null, null, null);
                    try {
                        cursor.moveToNext();
                        // Retrieve the path and the mime type
                        result = new MediaResult();
                        result.path = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA));
                        result.mimeType = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.MIME_TYPE));
                    } finally {
                        if (cursor != null) {
                            cursor.close();
                        }
                    }
                }
            } catch (Exception e) {
                result = null;
                Timber.e(e, "error loading media: " + e.getMessage());
            }
        } else {
            result = null;
        }
    } else if (requestCode == MediaConstants.CAMERA_RESULT) {
        //Uri uriCameraImage = intent.getData();			
        //Timber.d("RETURNED URI FROM CAMERA RESULT: " + uriCameraImage.toString());
        //Uri uriCameraImage = Uri.fromFile(mFileTmp);
        result = new MediaResult();
        result.mimeType = getMimeType(mMediaFileTmp.getAbsolutePath());
        if (result.mimeType == null) {
            if (mMediaUriTmp.getPathSegments().contains("video")) {
                result.mimeType = MediaConstants.MIME_TYPE_MP4;
            } else if (mMediaUriTmp.getPathSegments().contains("images")) {
                result.mimeType = MediaConstants.MIME_TYPE_JPEG;
            }
        }
        if ((!mMediaFileTmp.exists()) && result.mimeType.equals(MediaConstants.MIME_TYPE_MP4)) {
            // write input stream to file
            FileOutputStream fos;
            try {
                fos = new FileOutputStream(mMediaFileTmp);
                InputStream media = mActivity.getContentResolver().openInputStream(mMediaUriTmp);
                byte[] buf = new byte[1024];
                int len;
                while ((len = media.read(buf)) > 0) fos.write(buf, 0, len);
                fos.close();
                media.close();
            } catch (FileNotFoundException e) {
                Timber.e(e, e.toString());
            } catch (IOException e) {
                Timber.e(e, e.toString());
            }
        }
        mScanner = new MediaScannerConnection(mActivity, this);
        mScanner.connect();
    } else if (requestCode == MediaConstants.AUDIO_RESULT) {
        if (intent.getData() != null) {
            Uri uriMediaResult = intent.getData();
            if (uriMediaResult.getScheme().equalsIgnoreCase("content")) {
                Cursor cursor = mActivity.managedQuery(uriMediaResult, null, null, null, null);
                try {
                    if (cursor.moveToNext()) {
                        // Retrieve the path and the mime type
                        result = new MediaResult();
                        result.path = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA));
                        result.mimeType = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.MIME_TYPE));
                    }
                } finally {
                    cursor.close();
                }
            } else {
                String uriPath = uriMediaResult.toString();
                // Retrieve the path and the mime type
                result = new MediaResult();
                //get rid of file://
                result.path = uriPath.substring(7);
                result.mimeType = intent.getStringExtra("mimeType");
            }
        }
    } else if (requestCode == MediaConstants.FILE_RESULT) {
        if (intent.getData() != null) {
            Uri uriMediaResult = intent.getData();
            if (uriMediaResult.getScheme().equalsIgnoreCase("content")) {
                Cursor cursor = mActivity.managedQuery(uriMediaResult, null, null, null, null);
                if (cursor.moveToNext()) {
                    // Retrieve the path and the mime type
                    result = new MediaResult();
                    result.path = new String(cursor.getBlob(cursor.getColumnIndex(MediaStore.MediaColumns.DATA)));
                    result.mimeType = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.MIME_TYPE));
                    if (intent.getDataString().indexOf("#") != -1)
                        result.path = new File(uriMediaResult.getPath() + '#' + uriMediaResult.getFragment()).getAbsolutePath();
                    if (result.mimeType == null)
                        result.mimeType = MediaConstants.MIME_TYPE_ANY;
                }
            } else if (uriMediaResult.getScheme().equalsIgnoreCase("file")) {
                result = new MediaResult();
                result.path = new File(intent.getDataString()).getAbsolutePath();
                String fileExtension = MimeTypeMap.getFileExtensionFromUrl(intent.getDataString());
                result.mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension);
                if (result.mimeType == null)
                    result.mimeType = MediaConstants.MIME_TYPE_ANY;
            }
        }
    }
    return result;
}
Also used : InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) MediaScannerConnection(android.media.MediaScannerConnection) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Cursor(android.database.Cursor) Uri(android.net.Uri) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 4 with MediaScannerConnection

use of android.media.MediaScannerConnection in project android_frameworks_base by ResurrectionRemix.

the class ObjectViewer method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mClient = ((CameraBrowserApplication) getApplication()).getMtpClient();
    setContentView(R.layout.object_info);
    mImportButton = (Button) findViewById(R.id.import_button);
    mImportButton.setOnClickListener(this);
    mDeleteButton = (Button) findViewById(R.id.delete_button);
    mDeleteButton.setOnClickListener(this);
    mDeviceName = getIntent().getStringExtra("device");
    mStorageID = getIntent().getIntExtra("storage", 0);
    mObjectID = getIntent().getIntExtra("object", 0);
    mDisconnectedReceiver = new DeviceDisconnectedReceiver(this, mDeviceName);
    mScannerClient = new ScannerClient(this);
    mScannerConnection = new MediaScannerConnection(this, mScannerClient);
}
Also used : MediaScannerConnection(android.media.MediaScannerConnection)

Example 5 with MediaScannerConnection

use of android.media.MediaScannerConnection in project android_frameworks_base by DirtyUnicorns.

the class ObjectViewer method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mClient = ((CameraBrowserApplication) getApplication()).getMtpClient();
    setContentView(R.layout.object_info);
    mImportButton = (Button) findViewById(R.id.import_button);
    mImportButton.setOnClickListener(this);
    mDeleteButton = (Button) findViewById(R.id.delete_button);
    mDeleteButton.setOnClickListener(this);
    mDeviceName = getIntent().getStringExtra("device");
    mStorageID = getIntent().getIntExtra("storage", 0);
    mObjectID = getIntent().getIntExtra("object", 0);
    mDisconnectedReceiver = new DeviceDisconnectedReceiver(this, mDeviceName);
    mScannerClient = new ScannerClient(this);
    mScannerConnection = new MediaScannerConnection(this, mScannerClient);
}
Also used : MediaScannerConnection(android.media.MediaScannerConnection)

Aggregations

MediaScannerConnection (android.media.MediaScannerConnection)10 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1