List of usage examples for android.content ContentUris withAppendedId
public static Uri withAppendedId(Uri contentUri, long id)
From source file:com.gzsll.downloads.DownloadNotification.java
private void updateCompletedNotification(Collection<DownloadInfo> downloads) { for (DownloadInfo download : downloads) { if (!isCompleteAndVisible(download)) { continue; }/*w ww . ja va 2s . co m*/ long id = download.mId; String title = download.mTitle; if (title == null || title.length() == 0) { title = mContext.getResources().getString(R.string.download_unknown_title); } Uri contentUri = ContentUris.withAppendedId(Downloads.ALL_DOWNLOADS_CONTENT_URI, id); String caption; Intent intent; if (Downloads.isStatusError(download.mStatus)) { caption = mContext.getResources().getString(R.string.notification_download_failed); intent = new Intent(Constants.ACTION_LIST); } else { caption = mContext.getResources().getString(R.string.notification_download_complete); if (download.mDestination == Downloads.DESTINATION_EXTERNAL) { intent = new Intent(Constants.ACTION_OPEN); } else { intent = new Intent(Constants.ACTION_LIST); } } intent.setClassName(mContext.getPackageName(), DownloadReceiver.class.getName()); intent.setData(contentUri); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext); mBuilder.setSmallIcon(android.R.drawable.stat_sys_download_done); mBuilder.setContentTitle(title); mBuilder.setContentText(caption); mBuilder.setWhen(download.mLastMod); mBuilder.setContentIntent(PendingIntent.getBroadcast(mContext, 0, intent, 0)); intent = new Intent(Constants.ACTION_HIDE); intent.setClassName(mContext.getPackageName(), DownloadReceiver.class.getName()); intent.setData(contentUri); mBuilder.setDeleteIntent(PendingIntent.getBroadcast(mContext, 0, intent, 0)); mSystemFacade.postNotification(download.mId, mBuilder.build()); } }
From source file:com.ternup.caddisfly.fragment.ResultFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); getActivity().setTitle(R.string.result); mContext = getActivity();/*from ww w . ja v a2 s. c o m*/ mPpmText = (TextView) view.findViewById(R.id.ppmText); mDateView = (TextView) view.findViewById(R.id.testDate); mTitleView = (TextView) view.findViewById(R.id.titleView); mResultTextView = (TextView) view.findViewById(R.id.result); //mResultIcon = (ImageView) view.findViewById(R.id.resultIcon); mAddressText = (TextView) view.findViewById(R.id.address1); mAddress2Text = (TextView) view.findViewById(R.id.address2); mAddress3Text = (TextView) view.findViewById(R.id.address3); mSourceText = (TextView) view.findViewById(R.id.sourceType); ListView drawerList = (ListView) getActivity().findViewById(R.id.navigation_drawer); drawerList.setItemChecked(-1, true); drawerList.setSelection(-1); folderName = getArguments().getString(PreferencesHelper.FOLDER_NAME_KEY); mId = getArguments().getLong(getString(R.string.currentTestId)); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); mLocationId = sharedPreferences.getLong(getString(R.string.currentLocationId), -1); /*Button deleteButton = (Button) view.findViewById(R.id.deleteButton); deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AlertUtils.askQuestion(getActivity(), R.string.delete, R.string.areYouSure, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { FileUtils.deleteFolder(getActivity(), mLocationId, folderName); Uri uri = ContentUris .withAppendedId(TestContentProvider.CONTENT_URI, mId); mContext.getContentResolver().delete(uri, null, null); int value = 0; int counter = 0; SharedPreferences.Editor editor = sharedPreferences.edit(); while (value != -1) { value = sharedPreferences .getInt(String.format("result_%d_%d", mId, counter), -1); if (value > -1) { editor.remove(String.format("result_%d_%d", mId, counter)); editor.commit(); counter++; } } goBack(); } }, null ); } }); Button sendButton = (Button) view.findViewById(R.id.sendButton); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (NetworkUtils.checkInternetConnection(mContext)) { if (progressDialog == null) { progressDialog = new ProgressDialog(getActivity()); progressDialog.setMessage("Sending..."); progressDialog.setCancelable(false); } progressDialog.show(); postResult("testresults"); } } }); */ ArrayList<String> filePaths = FileUtils.getFilePaths(getActivity(), folderName, mLocationId); File directory = new File(FileUtils.getStoragePath(getActivity(), mLocationId, folderName, false)); if (!directory.exists()) { Uri uri = ContentUris.withAppendedId(TestContentProvider.CONTENT_URI, mId); mContext.getContentResolver().delete(uri, null, null); goBack(); } else if (filePaths.size() > 0) { displayResult(); } else { FileUtils.deleteFolder(getActivity(), mLocationId, folderName); } }
From source file:com.gsma.rcs.ri.utils.RcsContactUtil.java
/** * Gets the photo of a contact, or null if no photo is present * //from w w w .ja v a2s.co m * @param contact the contact ID * @return an Bitmap of the photo, or null if no photo is present */ public Bitmap getPhotoFromContactId(ContactId contact) { /* First try to get it from cache */ Bitmap photo = mPhotoContactCache.get(contact); if (photo != null) { return photo; } Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_FILTER_URI, Uri.encode(contact.toString())); Cursor cursor = null; try { cursor = mResolver.query(contactUri, PROJ_CONTACT_ID, null, null, null); if (cursor == null) { throw new SQLException("Cannot query photo for contact=" + contact); } if (!cursor.moveToFirst()) { return null; } long contactId = cursor.getLong(cursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup._ID)); InputStream photoInputStream = ContactsContract.Contacts.openContactPhotoInputStream(mResolver, ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId)); if (photoInputStream != null) { photo = BitmapFactory.decodeStream(photoInputStream); /* Insert in cache */ mPhotoContactCache.put(contact, photo); return photo; } return null; } finally { if (cursor != null) { cursor.close(); } } }
From source file:at.bitfire.davdroid.mirakel.resource.LocalAddressBook.java
@Override public void populate(Resource res) throws LocalStorageException { Contact c = (Contact) res;/*from w w w . java 2 s .co m*/ try { @Cleanup Cursor cursor = providerClient.query(ContentUris.withAppendedId(entriesURI(), c.getLocalID()), new String[] { entryColumnUID(), COLUMN_UNKNOWN_PROPERTIES, RawContacts.STARRED }, null, null, null); if (cursor != null && cursor.moveToNext()) { c.setUid(cursor.getString(0)); c.setUnknownProperties(cursor.getString(1)); c.setStarred(cursor.getInt(2) != 0); } else throw new RecordNotFoundException(); populateStructuredName(c); populatePhoneNumbers(c); populateEmailAddresses(c); populatePhoto(c); populateOrganization(c); populateIMPPs(c); populateNickname(c); populateNote(c); populatePostalAddresses(c); populateCategories(c); populateURLs(c); populateEvents(c); populateSipAddress(c); } catch (RemoteException ex) { throw new LocalStorageException(ex); } }
From source file:com.android.calendar.SearchActivity.java
private void showEventInfo(EventInfo event) { if (mShowEventDetailsWithAgenda) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); mEventInfoFragment = new EventInfoFragment(this, event.id, event.startTime.toMillis(false), event.endTime.toMillis(false), event.getResponse(), false, EventInfoFragment.DIALOG_WINDOW_STYLE, null /* No reminders to explicitly pass in. */); ft.replace(R.id.agenda_event_info, mEventInfoFragment); ft.commit();//w ww .j ava 2s . c om } else { Intent intent = new Intent(Intent.ACTION_VIEW); Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id); intent.setData(eventUri); intent.setClass(this, EventInfoActivity.class); intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime != null ? event.startTime.toMillis(true) : -1); intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime != null ? event.endTime.toMillis(true) : -1); startActivity(intent); } mCurrentEventId = event.id; }
From source file:com.charabia.SmsViewActivity.java
@Override public void onResume() { super.onResume(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefPhoneNumber = prefs.getString(PreferencesActivity.PHONE_NUMBER, null); if (prefPhoneNumber == null || prefPhoneNumber.length() <= 0) { Intent intent;/* w w w .j av a 2 s . c o m*/ intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.setClassName(this, PreferencesActivity.class.getName()); startActivity(intent); intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.setClassName(this, WebViewActivity.class.getName()); intent.setData(Uri.parse(WebViewActivity.getBaseUrl(this, "/help", "enter_phone_number.html"))); startActivity(intent); //Attempt to retrieve old keys android.content.ContentResolver cr = getContentResolver(); android.database.Cursor cursor = cr.query(Data.CONTENT_URI, new String[] { Data._ID, Tools.PHONE, Tools.KEY }, Data.MIMETYPE + "=?", new String[] { Tools.CONTENT_ITEM_TYPE }, null); while (cursor.moveToNext()) { try { tools.updateOrCreateContactKey(cursor.getString(cursor.getColumnIndex(Tools.PHONE)), Base64.decode(cursor.getString(cursor.getColumnIndex(Tools.KEY)), Base64.DEFAULT), false); cr.delete(ContentUris.withAppendedId(Data.CONTENT_URI, cursor.getLong(cursor.getColumnIndex(Data._ID))), null, null); } catch (NoContactException e) { e.printStackTrace(); Toast.makeText(this, "No contact for " + cursor.getColumnIndex(Tools.PHONE), Toast.LENGTH_SHORT) .show(); } } } }
From source file:com.zertinteractive.wallpaper.activities.DetailActivity.java
public void setAsWallpaper(long mImageId) { if (mImageId == -1) { setAsWallpaperMore();/*w w w . j av a2 s . co m*/ } else { Intent intent = new Intent(DetailActivity.this, SetWallpaperActivity.class); Uri base_uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; Uri item_uri = ContentUris.withAppendedId(base_uri, mImageId); intent.putExtra(Intent.EXTRA_STREAM, item_uri); Cursor cur = getContentResolver().query(item_uri, null, null, null, null); if (cur.moveToFirst()) { int colMimetype = cur.getColumnIndex(MediaStore.Images.ImageColumns.MIME_TYPE); intent.setDataAndType(item_uri, cur.getString(colMimetype)); } cur.close(); startActivity(intent); } }
From source file:com.bangz.shotrecorder.MainActivity.java
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Uri uri = ContentUris.withAppendedId(ShotRecord.ShotRecords.CONTENT_URI, id); Intent intent = new Intent(Intent.ACTION_EDIT, uri); startActivity(intent);/* w w w .j a va 2 s . c o m*/ }
From source file:bander.notepad.NoteListAppCompat.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info; try {/*w w w .ja va 2s .co m*/ info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); } catch (ClassCastException e) { return false; } switch (item.getItemId()) { case DELETE_ID: deleteNote(this, info.id); return true; case SEND_ID: Uri uri = ContentUris.withAppendedId(Note.CONTENT_URI, info.id); Cursor cursor = getContentResolver().query(uri, new String[] { Note._ID, Note.TITLE, Note.BODY }, null, null, null); Note note = Note.fromCursor(cursor); cursor.close(); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, note.getBody()); startActivity(Intent.createChooser(intent, getString(R.string.menu_send))); return true; } return false; }
From source file:com.example.android.notepad.NotesList.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info; try {/*from w w w . j ava2 s .co m*/ info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); } catch (ClassCastException e) { Log.e(TAG, "bad menuInfo", e); return false; } switch (item.getItemId()) { case MENU_ITEM_DELETE: { // Delete the note that the context menu is for Uri noteUri = ContentUris.withAppendedId(getIntent().getData(), info.id); getContentResolver().delete(noteUri, null, null); return true; } } return false; }