From 444057f1604b540f83d593b30d68691786aedb20 Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Fri, 1 Nov 2013 12:21:35 -0700 Subject: [PATCH] Bug 904551 - Stop using deprecated managedQuery api. r=lucasr --- .../base/CameraVideoResultHandler.java | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/mobile/android/base/CameraVideoResultHandler.java b/mobile/android/base/CameraVideoResultHandler.java index d67138e6a358..4e6982c11aa6 100644 --- a/mobile/android/base/CameraVideoResultHandler.java +++ b/mobile/android/base/CameraVideoResultHandler.java @@ -7,8 +7,14 @@ package org.mozilla.gecko; import org.mozilla.gecko.util.ActivityResultHandler; import android.app.Activity; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.LoaderManager; +import android.support.v4.app.LoaderManager.LoaderCallbacks; +import android.support.v4.content.CursorLoader; +import android.support.v4.content.Loader; import android.content.Intent; import android.database.Cursor; +import android.os.Bundle; import android.provider.MediaStore; import android.util.Log; @@ -40,20 +46,37 @@ class CameraVideoResultHandler implements ActivityResultHandler { } @Override - public void onActivityResult(int resultCode, Intent data) { + public void onActivityResult(int resultCode, final Intent data) { // Intent.getData() can return null. Avoid a crash. See bug 904551. if (data == null || data.getData() == null || resultCode != Activity.RESULT_OK) { sendResult(""); return; } - Cursor cursor = GeckoAppShell.getGeckoInterface().getActivity().managedQuery(data.getData(), - new String[] { MediaStore.Video.Media.DATA }, - null, - null, - null); - cursor.moveToFirst(); + final FragmentActivity fa = (FragmentActivity) GeckoAppShell.getGeckoInterface().getActivity(); + final LoaderManager lm = fa.getSupportLoaderManager(); + lm.initLoader(data.hashCode(), null, new LoaderCallbacks() { + @Override + public Loader onCreateLoader(int id, Bundle args) { + return new CursorLoader(fa, + data.getData(), + new String[] { MediaStore.Video.Media.DATA }, + null, // selection + null, // selectionArgs + null); // sortOrder + } - sendResult(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA))); + @Override + public void onLoadFinished(Loader loader, Cursor cursor) { + if (cursor.moveToFirst()) { + sendResult(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA))); + } else { + sendResult(""); + } + } + + @Override + public void onLoaderReset(Loader loader) { } + }); } }