Java Code Examples for android.content.ContentUris
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project ActionBarSherlock, under directory /samples/fragments/src/com/actionbarsherlock/sample/fragments/.
Source file: LoaderThrottleSupport.java

/** * Handler inserting new data. */ @Override public Uri insert(Uri uri,ContentValues initialValues){ if (mUriMatcher.match(uri) != MAIN) { throw new IllegalArgumentException("Unknown URI " + uri); } ContentValues values; if (initialValues != null) { values=new ContentValues(initialValues); } else { values=new ContentValues(); } if (values.containsKey(MainTable.COLUMN_NAME_DATA) == false) { values.put(MainTable.COLUMN_NAME_DATA,""); } SQLiteDatabase db=mOpenHelper.getWritableDatabase(); long rowId=db.insert(MainTable.TABLE_NAME,null,values); if (rowId > 0) { Uri noteUri=ContentUris.withAppendedId(MainTable.CONTENT_ID_URI_BASE,rowId); getContext().getContentResolver().notifyChange(noteUri,null); return noteUri; } throw new SQLException("Failed to insert row into " + uri); }
Example 2
From project Alerte-voirie-android, under directory /src/com/fabernovel/alertevoirie/.
Source file: ReportDetailsActivity.java

private void setCategory(long l){ String subCategories=EMPTY_STRING, category=EMPTY_STRING; long catId=l; currentIncident.categoryId=catId; do { Cursor c=getContentResolver().query(ContentUris.withAppendedId(Category.CONTENT_URI,catId),new String[]{Category.PARENT,Category.NAME},null,null,null); if (c.moveToFirst()) { catId=c.getInt(c.getColumnIndex(Category.PARENT)); if (catId != 0) { subCategories=c.getString(c.getColumnIndex(Category.NAME)) + (subCategories.length() > 0 ? ", " + subCategories : EMPTY_STRING); } else { category=c.getString(c.getColumnIndex(Category.NAME)); } } c.close(); } while (catId > 0); ((TextView)findViewById(R.id.TextView_sub_categories)).setText(subCategories); ((TextView)findViewById(R.id.TextView_main_category)).setText(category); }
Example 3
From project android-cropimage, under directory /src/com/android/camera/gallery/.
Source file: BaseImageList.java

public Uri contentUri(long id){ try { long existingId=ContentUris.parseId(mBaseUri); if (existingId != id) Log.e(TAG,"id mismatch"); return mBaseUri; } catch ( NumberFormatException ex) { return ContentUris.withAppendedId(mBaseUri,id); } }
Example 4
From project android-shuffle, under directory /client/src/org/dodgybits/shuffle/android/core/model/persistence/.
Source file: InitialDataGenerator.java

private Context insertContext(org.dodgybits.shuffle.android.core.model.Context context){ Uri uri=mContextPersister.insert(context); long id=ContentUris.parseId(uri); Log.d(cTag,"Created context id=" + id + " uri="+ uri); Context.Builder builder=Context.newBuilder(); builder.mergeFrom(context); builder.setLocalId(Id.create(id)); context=builder.build(); return context; }
Example 5
From project android-voip-service, under directory /src/main/java/org/linphone/.
Source file: ContactPickerActivityNew.java

@Override public Uri getPhotoUri(String id){ Uri contactUri=ContentUris.withAppendedId(Contacts.CONTENT_URI,Long.parseLong(id)); Uri photoUri=Uri.withAppendedPath(contactUri,Contacts.Photo.CONTENT_DIRECTORY); if (photoUri == null) { return null; } Cursor cursor=getContentResolver().query(photoUri,new String[]{ContactsContract.CommonDataKinds.Photo.PHOTO},null,null,null); try { if (cursor == null || !cursor.moveToNext()) { return null; } byte[] data=cursor.getBlob(0); if (data == null) { return null; } return photoUri; } finally { if (cursor != null) { cursor.close(); } } }
Example 6
From project android-xbmcremote, under directory /src/org/xbmc/android/util/.
Source file: HostFactory.java

/** * Returns a host based on its database ID. * @param activity Reference to activity * @param id Host database ID * @return */ private static Host getHost(Context context,int id){ Uri hostUri=ContentUris.withAppendedId(Hosts.CONTENT_URI,id); Cursor cur=context.getContentResolver().query(hostUri,null,null,null,null); try { if (cur.moveToFirst()) { final Host host=new Host(); host.id=cur.getInt(cur.getColumnIndex(HostProvider.Hosts._ID)); host.name=cur.getString(cur.getColumnIndex(HostProvider.Hosts.NAME)); host.addr=cur.getString(cur.getColumnIndex(HostProvider.Hosts.ADDR)); host.port=cur.getInt(cur.getColumnIndex(HostProvider.Hosts.PORT)); host.user=cur.getString(cur.getColumnIndex(HostProvider.Hosts.USER)); host.pass=cur.getString(cur.getColumnIndex(HostProvider.Hosts.PASS)); host.esPort=cur.getInt(cur.getColumnIndex(HostProvider.Hosts.ESPORT)); host.timeout=cur.getInt(cur.getColumnIndex(HostProvider.Hosts.TIMEOUT)); host.wifi_only=cur.getInt(cur.getColumnIndex(HostProvider.Hosts.WIFI_ONLY)) == 1; host.access_point=cur.getString(cur.getColumnIndex(HostProvider.Hosts.ACCESS_POINT)); host.mac_addr=cur.getString(cur.getColumnIndex(HostProvider.Hosts.MAC_ADDR)); host.wol_port=cur.getInt(cur.getColumnIndex(HostProvider.Hosts.WOL_PORT)); host.wol_wait=cur.getInt(cur.getColumnIndex(HostProvider.Hosts.WOL_WAIT)); return host; } } finally { cur.close(); } return null; }
Example 7
From project AndroidDevWeekendDub-BookLibrary, under directory /src/org/curiouscreature/android/shelves/provider/.
Source file: BooksProvider.java

public Uri insert(Uri uri,ContentValues initialValues){ ContentValues values; if (initialValues != null) { values=new ContentValues(initialValues); values.put(BooksStore.Book.SORT_TITLE,keyFor(values.getAsString(BooksStore.Book.TITLE))); } else { values=new ContentValues(); } if (URI_MATCHER.match(uri) != BOOKS) { throw new IllegalArgumentException("Unknown URI " + uri); } SQLiteDatabase db=mOpenHelper.getWritableDatabase(); final long rowId=db.insert("books",BooksStore.Book.TITLE,values); if (rowId > 0) { Uri insertUri=ContentUris.withAppendedId(BooksStore.Book.CONTENT_URI,rowId); getContext().getContentResolver().notifyChange(uri,null); return insertUri; } throw new SQLException("Failed to insert row into " + uri); }
Example 8
From project AndroidLab, under directory /src/src/de/tubs/ibr/android/ldap/core/activities/.
Source file: LocalTabActivity.java

@Override protected void onResume(){ super.onResume(); ListView contacts=(ListView)findViewById(android.R.id.list); LinkedList<EntityEntry> entries=new LinkedList<LocalTabActivity.EntityEntry>(); LinkedHashMap<Integer,Bundle> contactlist=ContactManager.loadContactList(this); for ( Entry<Integer,Bundle> contact : contactlist.entrySet()) { String status=contact.getValue().getString(ContactManager.LDAP_SYNC_STATUS_KEY); if (status == null || status.length() < 1) entries.add(new EntityEntry(contact.getValue().getString(AttributeMapper.FULL_NAME),contact.getKey())); } adapter=new ArrayAdapter<EntityEntry>(this,android.R.layout.simple_list_item_1,entries); contacts.setAdapter(adapter); contacts.setOnItemClickListener(new OnItemClickListener(){ @Override public void onItemClick( AdapterView<?> arg0, View arg1, int row, long id){ Intent i=new Intent(getBaseContext(),EditContactActivity.class); i.setAction(Intent.ACTION_EDIT); i.setData(ContentUris.withAppendedId(RawContacts.CONTENT_URI,((EntityEntry)arg0.getItemAtPosition(row)).getId())); startActivityForResult(i,0); } } ); }
Example 9
From project Android_1, under directory /PropagatedIntents/src/com/example/android/notepad/.
Source file: NotePadProvider.java

@Override public Uri insert(Uri uri,ContentValues initialValues){ if (sUriMatcher.match(uri) != NOTES) { throw new IllegalArgumentException("Unknown URI " + uri); } ContentValues values; if (initialValues != null) { values=new ContentValues(initialValues); } else { values=new ContentValues(); } Long now=Long.valueOf(System.currentTimeMillis()); if (values.containsKey(NotePad.Notes.CREATED_DATE) == false) { values.put(NotePad.Notes.CREATED_DATE,now); } if (values.containsKey(NotePad.Notes.MODIFIED_DATE) == false) { values.put(NotePad.Notes.MODIFIED_DATE,now); } if (values.containsKey(NotePad.Notes.TITLE) == false) { Resources r=Resources.getSystem(); values.put(NotePad.Notes.TITLE,r.getString(android.R.string.untitled)); } if (values.containsKey(NotePad.Notes.NOTE) == false) { values.put(NotePad.Notes.NOTE,""); } SQLiteDatabase db=mOpenHelper.getWritableDatabase(); long rowId=db.insert(NOTES_TABLE_NAME,Notes.NOTE,values); if (rowId > 0) { Uri noteUri=ContentUris.withAppendedId(NotePad.Notes.CONTENT_URI,rowId); getContext().getContentResolver().notifyChange(noteUri,null); return noteUri; } throw new SQLException("Failed to insert row into " + uri); }
Example 10
From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/.
Source file: ApnPreference.java

public void onClick(android.view.View v){ if ((v != null) && (R.id.text_layout == v.getId())) { Context context=getContext(); if (context != null) { int pos=Integer.parseInt(getKey()); Uri url=ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI,pos); context.startActivity(new Intent(Intent.ACTION_EDIT,url)); } } }
Example 11
From project android_packages_apps_cmparts, under directory /src/com/cyanogenmod/cmparts/provider/.
Source file: SettingsProvider.java

@Override public Uri insert(Uri uri,ContentValues initialValues){ if (URI_MATCHER.match(uri) != SETTINGS) { throw new IllegalArgumentException("Cannot insert into URI: " + uri); } ContentValues values=(initialValues != null) ? new ContentValues(initialValues) : new ContentValues(); for ( String colName : Constants.getRequiredColumns()) { if (values.containsKey(colName) == false) { throw new IllegalArgumentException("Missing column: " + colName); } } SQLiteDatabase db=mOpenHelper.getWritableDatabase(); long rowId=db.insert(TABLE_NAME,"",values); if (rowId < 0) { throw new SQLException("Failed to insert row into: " + uri); } Uri noteUri=ContentUris.withAppendedId(CONTENT_URI,rowId); getContext().getContentResolver().notifyChange(noteUri,null); return noteUri; }
Example 12
From project android_packages_apps_Exchange, under directory /src/com/android/exchange/adapter/.
Source file: CalendarSyncAdapter.java

@Override public void commit() throws IOException { userLog("Calendar SyncKey saved as: ",mMailbox.mSyncKey); mOps.add(new Operation(SyncStateContract.Helpers.newSetOperation(asSyncAdapter(SyncState.CONTENT_URI,mEmailAddress,Eas.EXCHANGE_ACCOUNT_MANAGER_TYPE),mAccountManagerAccount,mMailbox.mSyncKey.getBytes()))); for ( long eventId : mSendCancelIdList) { EmailContent.Message msg; try { msg=CalendarUtilities.createMessageForEventId(mContext,eventId,EmailContent.Message.FLAG_OUTGOING_MEETING_CANCEL,null,mAccount); } catch ( RemoteException e) { continue; } if (msg != null) { EasOutboxService.sendMessage(mContext,mAccount.mId,msg); } } try { mOps.mResults=safeExecute(CalendarContract.AUTHORITY,mOps); } catch ( RemoteException e) { throw new IOException("Remote exception caught; will retry"); } if (mOps.mResults != null) { if (!mUploadedIdList.isEmpty()) { ContentValues cv=new ContentValues(); cv.put(Events.DIRTY,0); cv.put(EVENT_SYNC_MARK,"0"); for ( long eventId : mUploadedIdList) { mContentResolver.update(asSyncAdapter(ContentUris.withAppendedId(Events.CONTENT_URI,eventId),mEmailAddress,Eas.EXCHANGE_ACCOUNT_MANAGER_TYPE),cv,null,null); } } if (!mDeletedIdList.isEmpty()) { for ( long eventId : mDeletedIdList) { mContentResolver.delete(asSyncAdapter(ContentUris.withAppendedId(Events.CONTENT_URI,eventId),mEmailAddress,Eas.EXCHANGE_ACCOUNT_MANAGER_TYPE),null,null); } } for ( Message msg : mOutgoingMailList) { EasOutboxService.sendMessage(mContext,mAccount.mId,msg); } } }
Example 13
From project android_packages_apps_FileManager, under directory /src/org/openintents/filemanager/.
Source file: BookmarksProvider.java

@Override public Uri insert(Uri uri,ContentValues values){ long rowID=db.insert(TB_NAME,"",values); if (rowID > 0) { Uri _uri=ContentUris.withAppendedId(CONTENT_URI,rowID); getContext().getContentResolver().notifyChange(_uri,null); return _uri; } throw new SQLException("Failed to insert row into " + uri); }
Example 14
From project android_packages_apps_Gallery, under directory /src/com/android/camera/gallery/.
Source file: BaseImageList.java

public Uri contentUri(long id){ try { long existingId=ContentUris.parseId(mBaseUri); if (existingId != id) Log.e(TAG,"id mismatch"); return mBaseUri; } catch ( NumberFormatException ex) { return ContentUris.withAppendedId(mBaseUri,id); } }
Example 15
From project android_packages_apps_Gallery2, under directory /src/com/android/gallery3d/data/.
Source file: LocalSource.java

@Override public Path findPathByUri(Uri uri,String type){ try { switch (mUriMatcher.match(uri)) { case LOCAL_IMAGE_ITEM: { long id=ContentUris.parseId(uri); return id >= 0 ? LocalImage.ITEM_PATH.getChild(id) : null; } case LOCAL_VIDEO_ITEM: { long id=ContentUris.parseId(uri); return id >= 0 ? LocalVideo.ITEM_PATH.getChild(id) : null; } case LOCAL_IMAGE_ALBUM: { return getAlbumPath(uri,MEDIA_TYPE_IMAGE); } case LOCAL_VIDEO_ALBUM: { return getAlbumPath(uri,MEDIA_TYPE_VIDEO); } case LOCAL_ALL_ALBUM: { return getAlbumPath(uri,MEDIA_TYPE_ALL); } } } catch (NumberFormatException e) { Log.w(TAG,"uri: " + uri.toString(),e); } return null; }
Example 16
From project android_packages_apps_Gallery3D, under directory /src/com/cooliris/media/.
Source file: LocalDataSource.java

public static MediaItem createMediaItemFromUri(Context context,Uri target,int mediaType){ MediaItem item=null; long id=ContentUris.parseId(target); ContentResolver cr=context.getContentResolver(); String whereClause=Images.ImageColumns._ID + "=" + Long.toString(id); try { final Uri uri=(mediaType == MediaItem.MEDIA_TYPE_IMAGE) ? Images.Media.EXTERNAL_CONTENT_URI : Video.Media.EXTERNAL_CONTENT_URI; final String[] projection=(mediaType == MediaItem.MEDIA_TYPE_IMAGE) ? CacheService.PROJECTION_IMAGES : CacheService.PROJECTION_VIDEOS; Cursor cursor=cr.query(uri,projection,whereClause,null,null); if (cursor != null) { if (cursor.moveToFirst()) { item=new MediaItem(); CacheService.populateMediaItemFromCursor(item,cr,cursor,uri.toString() + "/"); item.mId=id; } cursor.close(); cursor=null; } } catch ( Exception e) { ; } if (item == null) return null; item.mId=id; return item; }
Example 17
From project android_packages_apps_SalvageParts, under directory /src/com/salvagemod/salvageparts/provider/.
Source file: SettingsProvider.java

@Override public Uri insert(Uri uri,ContentValues initialValues){ if (URI_MATCHER.match(uri) != SETTINGS) { throw new IllegalArgumentException("Cannot insert into URI: " + uri); } ContentValues values=(initialValues != null) ? new ContentValues(initialValues) : new ContentValues(); for ( String colName : Constants.getRequiredColumns()) { if (values.containsKey(colName) == false) { throw new IllegalArgumentException("Missing column: " + colName); } } SQLiteDatabase db=mOpenHelper.getWritableDatabase(); long rowId=db.insert(TABLE_NAME,"",values); if (rowId < 0) { throw new SQLException("Failed to insert row into: " + uri); } Uri noteUri=ContentUris.withAppendedId(CONTENT_URI,rowId); getContext().getContentResolver().notifyChange(noteUri,null); return noteUri; }
Example 18
From project android_packages_apps_Superuser, under directory /src/com/noshufou/android/su/.
Source file: AppDetailsFragment.java

private void setOptions(int option){ ContentResolver cr=getActivity().getContentResolver(); ContentValues values=new ContentValues(); ; switch (option) { case MenuId.USE_APP_SETTINGS: mUseAppSettings=!mUseAppSettings; values.put(Apps.NOTIFICATIONS,mUseAppSettings ? null : mNotificationsEnabled); values.put(Apps.LOGGING,mUseAppSettings ? null : mLoggingEnabled); if (mUseAppSettings) { SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(getActivity()); mNotificationsEnabled=prefs.getBoolean(Preferences.NOTIFICATIONS,true); mLoggingEnabled=prefs.getBoolean(Preferences.LOGGING,true); } break; case MenuId.NOTIFICATIONS: mNotificationsEnabled=!mNotificationsEnabled; values.put(Apps.NOTIFICATIONS,mNotificationsEnabled); break; case MenuId.LOGGING: mLoggingEnabled=!mLoggingEnabled; values.put(Apps.LOGGING,mLoggingEnabled); break; } cr.update(ContentUris.withAppendedId(Apps.CONTENT_URI,mShownIndex),values,null,null); getActivity().invalidateOptionsMenu(); }
Example 19
From project android_packages_apps_Tag, under directory /src/com/android/apps/tag/.
Source file: MyTagList.java

/** * Opens the tag editor for a particular tag. */ private void editTag(long id){ Intent intent=new Intent(this,EditTagActivity.class); intent.setData(ContentUris.withAppendedId(NdefMessages.CONTENT_URI,id)); mTagIdInEdit=id; startActivityForResult(intent,REQUEST_EDIT); }
Example 20
From project andtweet, under directory /src/com/xorcode/andtweet/.
Source file: AndTweetService.java

/** * @param create true - create, false - destroy * @param statusId * @return boolean ok */ private boolean createOrDestroyFavorite(boolean create,long statusId){ boolean ok=false; JSONObject result=new JSONObject(); try { if (create) { result=TwitterUser.getTwitterUser().getConnection().createFavorite(statusId); } else { result=TwitterUser.getTwitterUser().getConnection().destroyFavorite(statusId); } ok=(result != null); } catch ( ConnectionException e) { Log.e(TAG,(create ? "create" : "destroy") + "Favorite Connection Exception: " + e.toString()); } if (ok) { try { Uri uri=ContentUris.withAppendedId(Tweets.CONTENT_URI,result.getLong("id")); Cursor c=getContentResolver().query(uri,new String[]{Tweets._ID,Tweets.AUTHOR_ID,Tweets.TWEET_TYPE},null,null,null); try { c.moveToFirst(); FriendTimeline fl=new FriendTimeline(AndTweetService.this.getApplicationContext(),c.getInt(c.getColumnIndex(Tweets.TWEET_TYPE))); fl.insertFromJSONObject(result,true); } catch ( Exception e) { Log.e(TAG,"e: " + e.toString()); } finally { if (c != null && !c.isClosed()) c.close(); } } catch ( JSONException e) { Log.e(TAG,"Error marking as " + (create ? "" : "not ") + "favorite: "+ e.toString()); } } d(TAG,(create ? "Creating" : "Destroying") + " favorite " + (ok ? "succeded" : "failed")+ ", id="+ statusId); return ok; }
Example 21
From project apps-for-android, under directory /AnyCut/src/com/example/anycut/.
Source file: CreateShortcutActivity.java

/** * Returns an Intent describing a direct text message shortcut. * @param result The result from the phone number picker * @return an Intent describing a phone number shortcut */ private Intent generatePhoneShortcut(Intent result,int actionResId,String scheme,String action){ Uri phoneUri=result.getData(); long personId=0; String name=null; String number=null; int type; Cursor cursor=getContentResolver().query(phoneUri,new String[]{Phones.PERSON_ID,Phones.DISPLAY_NAME,Phones.NUMBER,Phones.TYPE},null,null,null); try { cursor.moveToFirst(); personId=cursor.getLong(0); name=cursor.getString(1); number=cursor.getString(2); type=cursor.getInt(3); } finally { if (cursor != null) { cursor.close(); } } Intent intent=new Intent(); Uri personUri=ContentUris.withAppendedId(People.CONTENT_URI,personId); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON,generatePhoneNumberIcon(personUri,type,actionResId)); phoneUri=Uri.fromParts(scheme,number,null); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,new Intent(action,phoneUri)); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,name); return intent; }
Example 22
From project Birthdays, under directory /src/com/rexmenpara/birthdays/util/.
Source file: BirthdayArrayAdapter.java

/** * @return the photo URI */ private Bitmap loadContactPhoto(ContentResolver cr,long id){ Uri uri=ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI,id); InputStream input=ContactsContract.Contacts.openContactPhotoInputStream(cr,uri); if (input == null) { return null; } return BitmapFactory.decodeStream(input); }
Example 23
From project callmeter, under directory /src/de/ub0r/android/callmeter/data/.
Source file: DataProvider.java

/** * Get Name for id. * @param cr {@link ContentResolver} * @param id id * @return name */ public static String getName(final ContentResolver cr,final long id){ if (id < 0) { return null; } final Cursor cursor=cr.query(ContentUris.withAppendedId(CONTENT_URI,id),PROJECTION_NAME,null,null,null); String ret=null; if (cursor != null && cursor.moveToFirst()) { ret=cursor.getString(INDEX_NAME); } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return ret; }
Example 24
From project convertcsv, under directory /ConvertCSV/src/org/openintents/convertcsv/notepad/.
Source file: NotepadUtils.java

public static long addNote(Context context,String note,long encrypted,String tags){ Uri testuri=ContentUris.withAppendedId(NotePad.Notes.CONTENT_URI,0); Cursor c=context.getContentResolver().query(testuri,null,null,null,NotePad.Notes.DEFAULT_SORT_ORDER); int COLUMN_INDEX_ENCRYPTED=c.getColumnIndex(NotePad.Notes.ENCRYPTED); int COLUMN_INDEX_TAGS=c.getColumnIndex(NotePad.Notes.TAGS); c.close(); ContentValues values=new ContentValues(1); values.put(NotePad.Notes.NOTE,note); String title=extractTitle(note,encrypted); values.put(NotePad.Notes.TITLE,title); if (COLUMN_INDEX_ENCRYPTED > -1) { values.put(NotePad.Notes.ENCRYPTED,encrypted); } if (COLUMN_INDEX_TAGS > -1) { values.put(NotePad.Notes.TAGS,tags); } try { Uri uri=context.getContentResolver().insert(NotePad.Notes.CONTENT_URI,values); Log.i(TAG,"Insert new note: " + uri); return Long.parseLong(uri.getPathSegments().get(1)); } catch ( Exception e) { Log.i(TAG,"Insert item failed",e); return -1; } }
Example 25
From project COSsettings, under directory /src/com/cyanogenmod/cmparts/provider/.
Source file: SettingsProvider.java

@Override public Uri insert(Uri uri,ContentValues initialValues){ if (URI_MATCHER.match(uri) != SETTINGS) { throw new IllegalArgumentException("Cannot insert into URI: " + uri); } ContentValues values=(initialValues != null) ? new ContentValues(initialValues) : new ContentValues(); for ( String colName : Constants.getRequiredColumns()) { if (values.containsKey(colName) == false) { throw new IllegalArgumentException("Missing column: " + colName); } } SQLiteDatabase db=mOpenHelper.getWritableDatabase(); long rowId=db.insert(TABLE_NAME,"",values); if (rowId < 0) { throw new SQLException("Failed to insert row into: " + uri); } Uri noteUri=ContentUris.withAppendedId(CONTENT_URI,rowId); getContext().getContentResolver().notifyChange(noteUri,null); return noteUri; }
Example 26
From project creamed_glacier_app_settings, under directory /src/com/android/settings/.
Source file: ApnPreference.java

public void onClick(android.view.View v){ if ((v != null) && (R.id.text_layout == v.getId())) { Context context=getContext(); if (context != null) { int pos=Integer.parseInt(getKey()); Uri url=ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI,pos); context.startActivity(new Intent(Intent.ACTION_EDIT,url)); } } }
Example 27
From project cw-advandroid, under directory /ContentProvider/ConstantsPlus/src/com/commonsware/android/constants/.
Source file: Provider.java

@Override public Uri insert(Uri url,ContentValues initialValues){ long rowID=db.getWritableDatabase().insert(TABLE,Constants.TITLE,initialValues); if (rowID > 0) { Uri uri=ContentUris.withAppendedId(Provider.Constants.CONTENT_URI,rowID); getContext().getContentResolver().notifyChange(uri,null); return (uri); } throw new SQLException("Failed to insert row into " + url); }
Example 28
From project cw-omnibus, under directory /ContentProvider/ConstantsPlus/src/com/commonsware/android/constants/.
Source file: Provider.java

@Override public Uri insert(Uri url,ContentValues initialValues){ long rowID=db.getWritableDatabase().insert(TABLE,Constants.TITLE,initialValues); if (rowID > 0) { Uri uri=ContentUris.withAppendedId(Provider.Constants.CONTENT_URI,rowID); getContext().getContentResolver().notifyChange(uri,null); return (uri); } throw new SQLException("Failed to insert row into " + url); }
Example 29
From project DeliciousDroid, under directory /src/com/deliciousdroid/providers/.
Source file: BookmarkContentProvider.java

private Uri insertBookmark(Uri uri,ContentValues values){ db=dbHelper.getWritableDatabase(); long rowId=db.insert(BOOKMARK_TABLE_NAME,"",values); if (rowId > 0) { Uri rowUri=ContentUris.appendId(BookmarkContent.Bookmark.CONTENT_URI.buildUpon(),rowId).build(); getContext().getContentResolver().notifyChange(rowUri,null); return rowUri; } throw new SQLException("Failed to insert row into " + uri); }
Example 30
From project DeskSMS, under directory /DeskSMS/src/com/koushikdutta/desktopsms/.
Source file: C2DMReceiver.java

private void markAllAsRead(Context context){ Uri contentProviderUri=Uri.parse("content://sms"); Cursor c=context.getContentResolver().query(contentProviderUri,new String[]{"_id"},"read = 0",null,null); ; try { int idColumn=c.getColumnIndex("_id"); ArrayList<ContentProviderOperation> ops=new ArrayList<ContentProviderOperation>(); while (c.moveToNext()) { int id=c.getInt(idColumn); ContentProviderOperation op=ContentProviderOperation.newUpdate(ContentUris.withAppendedId(contentProviderUri,id)).withValue("read",1).build(); ops.add(op); } context.getContentResolver().applyBatch("sms",ops); } catch ( Exception ex) { ex.printStackTrace(); } finally { if (c != null) c.close(); } }
Example 31
From project Diktofon, under directory /app/src/kaljurand_at_gmail_dot_com/diktofon/activity/.
Source file: SpeakerListActivity.java

@Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); ListView lv=getListView(); lv.setFastScrollEnabled(true); GuiUtils.setEmptyView(this,lv,getString(R.string.emptyview_speakers)); String[] columns=new String[]{Speaker.Columns._ID,Speaker.Columns.NAME}; int[] to=new int[]{R.id.list_item_speaker_id,R.id.list_item_speaker_name}; Cursor managedCursor=managedQuery(CONTENT_URI,columns,null,null,Speaker.Columns.NAME + " ASC"); SimpleCursorAdapter mAdapter=new SimpleCursorAdapter(this,R.layout.list_item_speaker,managedCursor,columns,to); lv.setAdapter(mAdapter); registerForContextMenu(lv); lv.setOnItemClickListener(new OnItemClickListener(){ public void onItemClick( AdapterView<?> parent, View view, int position, long id){ Cursor cursor=(Cursor)parent.getItemAtPosition(position); final long key=cursor.getLong(cursor.getColumnIndex(Speaker.Columns._ID)); Uri selectedSpeakerUri=ContentUris.withAppendedId(CONTENT_URI,key); Intent intent=new Intent(); intent.setData(selectedSpeakerUri); setResult(Activity.RESULT_OK,intent); finish(); } } ); }
Example 32
From project dmix, under directory /MPDroid/src/com/namelessdev/mpdroid/providers/.
Source file: ServerListProvider.java

@Override public Uri insert(Uri uri,ContentValues initialValues){ if (sUriMatcher.match(uri) != SERVERS) throw new IllegalArgumentException("Unknown URI " + uri); ContentValues values=initialValues != null ? new ContentValues(initialValues) : new ContentValues(); Long now=Long.valueOf(System.currentTimeMillis()); if (!values.containsKey(ServerColumns.NAME)) values.put(ServerColumns.NAME,Resources.getSystem().getString(android.R.string.untitled) + now.toString()); if (!values.containsKey(ServerColumns.HOST)) values.put(ServerColumns.HOST,"0.0.0.0"); if (!values.containsKey(ServerColumns.PORT)) values.put(ServerColumns.PORT,"6600"); if (!values.containsKey(ServerColumns.STREAMING_PORT)) values.put(ServerColumns.STREAMING_PORT,"8000"); if (!values.containsKey(ServerColumns.STREAMING_URL)) values.put(ServerColumns.STREAMING_URL,""); if (!values.containsKey(ServerColumns.PASSWORD)) values.put(ServerColumns.PASSWORD,""); SQLiteDatabase db=mOpenHelper.getWritableDatabase(); long rowId=db.insert(SERVERS_TABLE_NAME,"server",values); if (rowId > 0) { Uri noteUri=ContentUris.withAppendedId(ServerColumns.CONTENT_URI,rowId); getContext().getContentResolver().notifyChange(noteUri,null); return noteUri; } throw new SQLException("Failed to insert row into " + uri); }
Example 33
From project DownloadProvider, under directory /src/com/mozillaonline/providers/downloads/.
Source file: DownloadNotification.java

private void updateCompletedNotification(Collection<DownloadInfo> downloads){ for ( DownloadInfo download : downloads) { if (!isCompleteAndVisible(download)) { continue; } Notification n=new Notification(); n.icon=android.R.drawable.stat_sys_download_done; 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); n.when=download.mLastMod; n.setLatestEventInfo(mContext,title,caption,PendingIntent.getBroadcast(mContext,0,intent,0)); intent=new Intent(Constants.ACTION_HIDE); intent.setClassName(mContext.getPackageName(),DownloadReceiver.class.getName()); intent.setData(contentUri); n.deleteIntent=PendingIntent.getBroadcast(mContext,0,intent,0); mSystemFacade.postNotification(download.mId,n); } }
Example 34
From project ElectricSleep, under directory /src/com/androsz/electricsleepbeta/alarmclock/.
Source file: AlarmProvider.java

@Override public Uri insert(final Uri url,final ContentValues initialValues){ if (sURLMatcher.match(url) != ALARMS) { throw new IllegalArgumentException("Cannot insert into URL: " + url); } final ContentValues values=new ContentValues(initialValues); final SQLiteDatabase db=mOpenHelper.getWritableDatabase(); final long rowId=db.insert("alarms",Alarm.Columns.MESSAGE,values); if (rowId < 0) { throw new SQLException("Failed to insert row into " + url); } if (Log.LOGV) { Log.v("Added alarm rowId = " + rowId); } final Uri newUrl=ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI,rowId); getContext().getContentResolver().notifyChange(newUrl,null); return newUrl; }
Example 35
From project eoit, under directory /EOIT/src/fr/eoit/activity/fragment/blueprint/.
Source file: RequiredDecryptorFragment.java

@Override protected Integer doInBackground(Integer... params){ int blueprintId=params[0]; int decryptorId=params[1]; DecryptorBonuses currentDecryptorBonuses=DecryptorUtil.getDecryptorBonusesOrDefault(decryptorId); Uri updateBlueprintUri=ContentUris.withAppendedId(Blueprint.CONTENT_ID_URI_BASE,blueprintId); ContentValues values=new ContentValues(); values.put(Blueprint.COLUMN_NAME_DECRYPTOR_ID,decryptorId); values.put(Blueprint.COLUMN_NAME_ML,(-4 + currentDecryptorBonuses.meModifier)); values.put(Blueprint.COLUMN_NAME_PL,(-4 + currentDecryptorBonuses.peModifier)); if (getActivity() != null && getActivity().getContentResolver() != null) getActivity().getContentResolver().update(updateBlueprintUri,values,null,null); return decryptorId; }
Example 36
From project examples_2, under directory /ContentProvider/ContentProvider/src/com/inazaruk/contentprovider/.
Source file: PreferenceSpyProvider.java

@Override public Uri insert(Uri uri,ContentValues initialValues){ if (sUriMatcher.match(uri) != PREFERENCES_TABLE) { throw new IllegalArgumentException("Unknown URI " + uri); } ContentValues values; if (initialValues != null) { values=new ContentValues(initialValues); } else { values=new ContentValues(); } if (values.containsKey(Preferences.REMOTE_LAST_MODIFIED_TIME) == false) { values.put(Preferences.REMOTE_LAST_MODIFIED_TIME,0L); } if (values.containsKey(Preferences.REMOTE_PACKAGE) == false) { throw new SQLException("Failed to insert row into " + uri + ". "+ "No "+ Preferences.REMOTE_PACKAGE+ " was not specified."); } if (values.containsKey(Preferences.REMOTE_PREF_NAME) == false) { throw new SQLException("Failed to insert row into " + uri + ". "+ "No "+ Preferences.REMOTE_PREF_NAME+ " was not specified."); } if (values.containsKey(Preferences.LOCAL_PREF_NAME) == false) { throw new SQLException("Failed to insert row into " + uri + ". "+ "No "+ Preferences.LOCAL_PREF_NAME+ " was not specified."); } SQLiteDatabase db=mOpenHelper.getWritableDatabase(); long rowId=db.insert(Preferences.TABLE_NAME,null,values); if (rowId > 0) { Uri noteUri=ContentUris.withAppendedId(Preferences.CONTENT_URI,rowId); getContext().getContentResolver().notifyChange(noteUri,null); return noteUri; } throw new SQLException("Failed to insert row into " + uri); }
Example 37
From project farebot, under directory /src/com/codebutler/farebot/fragments/.
Source file: CardsFragment.java

@Override public boolean onContextItemSelected(android.view.MenuItem item){ if (item.getItemId() == R.id.delete_card) { long id=((AdapterView.AdapterContextMenuInfo)item.getMenuInfo()).id; Uri uri=ContentUris.withAppendedId(CardProvider.CONTENT_URI_CARD,id); getActivity().getContentResolver().delete(uri,null,null); return true; } return false; }
Example 38
From project filemanager, under directory /FileManager/src/org/openintents/filemanager/bookmarks/.
Source file: BookmarksProvider.java

@Override public Uri insert(Uri uri,ContentValues values){ long rowID=db.insert(TB_NAME,"",values); if (rowID > 0) { Uri _uri=ContentUris.withAppendedId(CONTENT_URI,rowID); getContext().getContentResolver().notifyChange(_uri,null); return _uri; } throw new SQLException("Failed to insert row into " + uri); }
Example 39
From project finch, under directory /libs/JakeWharton-ActionBarSherlock-2eabf25/samples/fragments/src/com/actionbarsherlock/sample/fragments/.
Source file: LoaderThrottleSupport.java

/** * Handler inserting new data. */ @Override public Uri insert(Uri uri,ContentValues initialValues){ if (mUriMatcher.match(uri) != MAIN) { throw new IllegalArgumentException("Unknown URI " + uri); } ContentValues values; if (initialValues != null) { values=new ContentValues(initialValues); } else { values=new ContentValues(); } if (values.containsKey(MainTable.COLUMN_NAME_DATA) == false) { values.put(MainTable.COLUMN_NAME_DATA,""); } SQLiteDatabase db=mOpenHelper.getWritableDatabase(); long rowId=db.insert(MainTable.TABLE_NAME,null,values); if (rowId > 0) { Uri noteUri=ContentUris.withAppendedId(MainTable.CONTENT_ID_URI_BASE,rowId); getContext().getContentResolver().notifyChange(noteUri,null); return noteUri; } throw new SQLException("Failed to insert row into " + uri); }
Example 40
From project Gibberbot, under directory /robo-tests/src/info/guardianproject/otr/app/im/app/.
Source file: AccountActivityTest.java

@Before public void setUp() throws Exception { mActivity=new AccountActivity(); TestUtils.setUpApplication(mActivity); Intent intent=new Intent(mActivity,AccountActivity.class); intent.setAction(Intent.ACTION_INSERT_OR_EDIT); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(ContentUris.withAppendedId(Imps.Provider.CONTENT_URI,1)); mActivity.setIntent(intent); mActivity.onCreate(null); mEditUserAccount=(EditText)mActivity.findViewById(R.id.edtName); mEditPass=(EditText)mActivity.findViewById(R.id.edtPass); mBtnSignin=(Button)mActivity.findViewById(R.id.btnSignIn); }