List of usage examples for android.app Activity startManagingCursor
@Deprecated public void startManagingCursor(Cursor c)
From source file:Main.java
public static String getVideoPath(Activity activity, Uri uri) { String[] projection = { MediaStore.Video.Media.DATA }; Cursor cursor = activity.managedQuery(uri, projection, null, null, null); activity.startManagingCursor(cursor); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); cursor.moveToFirst();//from w w w .j av a 2 s. c o m return cursor.getString(column_index); }
From source file:Main.java
public static String getPath(Activity activity, Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = activity.managedQuery(uri, projection, null, null, null); activity.startManagingCursor(cursor); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();//from www. j a v a 2 s .co m return cursor.getString(column_index); }
From source file:Main.java
public static String getName(Activity activity, Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = activity.managedQuery(uri, projection, null, null, null); activity.startManagingCursor(cursor); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();/*from w w w . j ava2 s .c om*/ Uri filePathUri = Uri.parse(cursor.getString(column_index)); String file_name = filePathUri.getLastPathSegment().toString(); return file_name; }
From source file:Main.java
public static String geVideotName(Activity activity, Uri uri) throws Exception { String[] projection = { MediaStore.Video.Media.DATA }; Cursor cursor = activity.managedQuery(uri, projection, null, null, null); activity.startManagingCursor(cursor); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); cursor.moveToFirst();// www . j a v a2s. c o m Uri filePathUri = Uri.parse(cursor.getString(column_index)); String file_name = filePathUri.getLastPathSegment().toString(); return file_name; }
From source file:com.winsuk.pebbletype.WatchCommunication.java
private void sendThreadList(Context context) { Cursor msgCursor = context.getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);// www . j ava 2 s . c o m Activity act = new Activity(); act.startManagingCursor(msgCursor); ArrayList<SMSThread> threads = new ArrayList<SMSThread>(); if (msgCursor.moveToFirst()) { for (int i = 0; i < msgCursor.getCount(); i++) { int thread_id = msgCursor.getInt(msgCursor.getColumnIndexOrThrow("thread_id")); SMSThread th = null; for (int t = 0; t < threads.size(); t++) { SMSThread existingTh = threads.get(t); if (existingTh.thread_id == thread_id) { th = existingTh; } } if (th == null) { String address = msgCursor.getString(msgCursor.getColumnIndexOrThrow("address")).toString(); String name = ""; Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, address); Cursor contactCursor = context.getContentResolver().query(uri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null); if (contactCursor.moveToFirst()) { name = contactCursor.getString(contactCursor.getColumnIndex(PhoneLookup.DISPLAY_NAME)); contactCursor.close(); } th = new SMSThread(); th.thread_id = thread_id; th.address = address; th.name = name; //th.messages = new ArrayList<String>(); threads.add(th); } /* TODO: this line is causing crashes on select few devices String body = msgCursor.getString(msgCursor.getColumnIndexOrThrow("body")).toString(); if (th.messages.size() < 5) { th.messages.add(body); } */ msgCursor.moveToNext(); } } msgCursor.close(); int limit = (threads.size() <= THREAD_LIMIT ? threads.size() : THREAD_LIMIT); String output = ""; if (limit > 0) { // Calculate how many characters names can take up int availibleCharacters = 120; for (int i = 0; i < limit; i++) { availibleCharacters -= threads.get(i).address.length(); availibleCharacters -= 2; //for ; and \n } int maxNameLength = availibleCharacters / limit - 3; for (int i = 0; i < limit; i++) { SMSThread thread = threads.get(i); String name = ""; if (thread.name.length() < maxNameLength) { name = thread.name; } else { name = thread.name.substring(0, maxNameLength - 1); name += ""; } output = output + thread.address + ";" + name + "\n"; /* List messages for (int ii = 0; ii < thread.messages.size(); ii++) { output = output + thread.messages.get(ii) + "\n"; }*/ } } PebbleDictionary data = new PebbleDictionary(); data.addString(KEY_THREAD_LIST, output); PebbleKit.sendDataToPebble(context, PEBBLE_APP_UUID, data); }
From source file:com.todoroo.astrid.actfm.CommentsFragment.java
protected void refreshUpdatesList() { Activity activity = getActivity(); View view = getView();//from ww w . j a v a 2s . c om if (activity == null || view == null) { return; } Cursor cursor; ListView listView = ((ListView) view.findViewById(android.R.id.list)); if (updateAdapter == null) { cursor = getCursor(); activity.startManagingCursor(cursor); updateAdapter = new UpdateAdapter(this, R.layout.update_adapter_row, cursor); addHeaderToListView(listView); addFooterToListView(listView); listView.setAdapter(updateAdapter); } else { cursor = updateAdapter.getCursor(); cursor.requery(); activity.startManagingCursor(cursor); if (footerView != null) { listView.removeFooterView(footerView); footerView = null; } } listView.setVisibility(View.VISIBLE); }
From source file:Main.java
/** * Get the real file path from URI registered in media store * @param contentUri URI registered in media store *///from w w w.ja v a 2 s . c om public static String getRealPathFromURI(Activity activity, Uri contentUri) { String releaseNumber = Build.VERSION.RELEASE; if (releaseNumber != null) { /* ICS Version */ if (releaseNumber.length() > 0 && releaseNumber.charAt(0) == '4') { String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; CursorLoader cursorLoader = new CursorLoader(activity, contentUri, proj, null, null, null); Cursor cursor = cursorLoader.loadInBackground(); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); cursor.close(); } return strFileName; } /* GB Version */ else if (releaseNumber.startsWith("2.3")) { String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); cursor.close(); } return strFileName; } } //--------------------- // Undefined Version //--------------------- /* GB, ICS Common */ String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); // Use the Cursor manager in ICS activity.startManagingCursor(cursor); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); //cursor.close(); // If the cursor close use , This application is terminated .(In ICS Version) activity.stopManagingCursor(cursor); } return strFileName; }
From source file:org.mozilla.gecko.AboutHomeContent.java
private void loadTopSites(final Activity activity) { if (mCursor != null) activity.stopManagingCursor(mCursor); // Ensure we initialize GeckoApp's startup mode in // background thread before we use it when updating // the top sites section layout in main thread. final GeckoApp.StartupMode startupMode = GeckoApp.mAppContext.getStartupMode(); // The isSyncSetup method should not be called on // UI thread as it touches disk to access a sqlite DB. final boolean syncIsSetup = isSyncSetup(); ContentResolver resolver = GeckoApp.mAppContext.getContentResolver(); mCursor = BrowserDB.getTopSites(resolver, NUMBER_OF_TOP_SITES_PORTRAIT); activity.startManagingCursor(mCursor); GeckoApp.mAppContext.mMainHandler.post(new Runnable() { public void run() { if (mTopSitesAdapter == null) { mTopSitesAdapter = new TopSitesCursorAdapter(activity, R.layout.abouthome_topsite_item, mCursor, new String[] { URLColumns.TITLE, URLColumns.THUMBNAIL }, new int[] { R.id.title, R.id.thumbnail }); mTopSitesAdapter.setViewBinder(new TopSitesViewBinder()); mTopSitesGrid.setAdapter(mTopSitesAdapter); } else { mTopSitesAdapter.changeCursor(mCursor); }//from ww w. ja v a 2 s. co m mTopSitesGrid.setNumColumns(getNumberOfColumns()); updateLayout(startupMode, syncIsSetup); } }); }
From source file:Main.java
/** * Get the real file path from URI registered in media store * @param contentUri URI registered in media store */// ww w . j a v a2 s .com public static String getRealPathFromURI(Activity activity, Uri contentUri) { String releaseNumber = Build.VERSION.RELEASE; if (releaseNumber != null) { /* ICS, JB Version */ if (releaseNumber.length() > 0 && releaseNumber.charAt(0) == '4') { // URI from Gallery(MediaStore) String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; CursorLoader cursorLoader = new CursorLoader(activity, contentUri, proj, null, null, null); Cursor cursor = cursorLoader.loadInBackground(); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); cursor.close(); } // URI from Others(Dropbox, etc.) if (strFileName == null || strFileName.isEmpty()) { if (contentUri.getScheme().compareTo("file") == 0) strFileName = contentUri.getPath(); } return strFileName; } /* GB Version */ else if (releaseNumber.startsWith("2.3")) { // URI from Gallery(MediaStore) String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); cursor.close(); } // URI from Others(Dropbox, etc.) if (strFileName == null || strFileName.isEmpty()) { if (contentUri.getScheme().compareTo("file") == 0) strFileName = contentUri.getPath(); } return strFileName; } } //--------------------- // Undefined Version //--------------------- /* GB, ICS Common */ String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); // Use the Cursor manager in ICS activity.startManagingCursor(cursor); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); //cursor.close(); // If the cursor close use , This application is terminated .(In ICS Version) activity.stopManagingCursor(cursor); } return strFileName; }
From source file:Main.java
/** * Get the real file path from URI registered in media store * @param contentUri URI registered in media store *///from ww w.jav a2s. c om @SuppressWarnings("deprecation") public static String getRealPathFromURI(Activity activity, Uri contentUri) { String releaseNumber = Build.VERSION.RELEASE; if (releaseNumber != null) { /* ICS, JB Version */ if (releaseNumber.length() > 0 && releaseNumber.charAt(0) == '4') { // URI from Gallery(MediaStore) String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; CursorLoader cursorLoader = new CursorLoader(activity, contentUri, proj, null, null, null); Cursor cursor = cursorLoader.loadInBackground(); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); cursor.close(); } // URI from Others(Dropbox, etc.) if (strFileName == null || strFileName.isEmpty()) { if (contentUri.getScheme().compareTo("file") == 0) strFileName = contentUri.getPath(); } return strFileName; } /* GB Version */ else if (releaseNumber.startsWith("2.3")) { // URI from Gallery(MediaStore) String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); cursor.close(); } // URI from Others(Dropbox, etc.) if (strFileName == null || strFileName.isEmpty()) { if (contentUri.getScheme().compareTo("file") == 0) strFileName = contentUri.getPath(); } return strFileName; } } //--------------------- // Undefined Version //--------------------- /* GB, ICS Common */ String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); // Use the Cursor manager in ICS activity.startManagingCursor(cursor); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); //cursor.close(); // If the cursor close use , This application is terminated .(In ICS Version) activity.stopManagingCursor(cursor); } return strFileName; }