List of usage examples for android.content ContentUris parseId
public static long parseId(Uri contentUri)
From source file:cz.maresmar.sfm.view.credential.LoginListActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == PORTAL_PICKER_REQUEST && resultCode == Activity.RESULT_OK) { Uri portalUri = data.getData();/*from w w w.j ava2 s . c o m*/ if (portalUri != null) { long portalId = ContentUris.parseId(portalUri); // Try to find credentials with this portal try (Cursor cursor = getContentResolver().query(mPortalsUri, new String[] { ProviderContract.Portal.CREDENTIAL_ID }, ProviderContract.Portal.PORTAL_ID + " == " + portalId, null, null)) { // Has already data if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); long credentialId = cursor.getLong(0); Uri credentialUri = ContentUris.withAppendedId( Uri.withAppendedPath(mUserUri, ProviderContract.CREDENTIALS_PATH), credentialId); startCredentialDetailActivity(portalUri, credentialUri, LoginDetailActivity.CREDENTIAL_TAB); } else { startCredentialDetailActivity(portalUri, null, LoginDetailActivity.CREDENTIAL_TAB); } } } else { // Create new portal startCredentialDetailActivity(portalUri, null, LoginDetailActivity.PORTAL_TAB); } } }
From source file:com.bangz.smartmute.services.LocationMuteService.java
private void handleAddGeofence(Uri uri) { LogUtils.LOGD(TAG, "Handling add one geofence id = " + ContentUris.parseId(uri)); if (PrefUtils.isEnableSmartMute(this) == false) { LogUtils.LOGD(TAG, "Smart Mute is disabled by user. quit add one geofdence"); return;//from w ww .j a v a 2s .com } ContentResolver cr = getContentResolver(); Cursor cursor = cr.query(uri, PROJECTS, SELECT_STRING, DEF_SELECT_ARGUMENTS, RulesColumns._ID); if (cursor.getCount() == 0) { cursor.close(); LogUtils.LOGD(TAG, "handleAddGeofence: no record selected,but id = " + ContentUris.parseId(uri)); return; } List<Geofence> geofences = fillGeofences(cursor); cursor.close(); boolean b = addGeofences(geofences); LogUtils.LOGD(TAG, (b ? "Successful" : "Failed") + " add one geofence id = " + ContentUris.parseId(uri)); }
From source file:me.vancexu.sunshine.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/*from www . jav a 2 s . co m*/ * @param lon the longitude of the city * @return the row ID of the added location. */ private long addLocation(String locationSetting, String cityName, double lat, double lon) { long rowId; Log.v(LOG_TAG, "inserting " + cityName + ", with coord: " + lat + ", " + lon); // First, check if the location with this city name exists in the db Cursor cursor = mContext.getContentResolver().query(LocationEntry.CONTENT_URI, new String[] { LocationEntry._ID }, LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (cursor.moveToFirst()) { Log.v(LOG_TAG, "Found it in the database!"); int locationIdIndex = cursor.getColumnIndex(LocationEntry._ID); rowId = cursor.getLong(locationIdIndex); cursor.close(); return rowId; } else { Log.v(LOG_TAG, "Didn't find it in the database, inserting now!"); cursor.close(); ContentValues locationValues = new ContentValues(); locationValues.put(LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(LocationEntry.COLUMN_COORD_LONG, lon); Uri locationInsertUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, locationValues); return ContentUris.parseId(locationInsertUri); } }
From source file:org.awesomeapp.messenger.ui.AccountViewFragment.java
private void initFragment() { Intent i = getIntent();//from w ww . j a va 2s . c o m mApp = (ImApp) getActivity().getApplication(); String action = i.getAction(); if (i.hasExtra("isSignedIn")) isSignedIn = i.getBooleanExtra("isSignedIn", false); final ProviderDef provider; mSignInHelper = new SignInHelper(getActivity(), new SimpleAlertHandler(getActivity())); SignInHelper.SignInListener signInListener = new SignInHelper.SignInListener() { @Override public void connectedToService() { } @Override public void stateChanged(int state, long accountId) { if (state == ImConnection.LOGGED_IN) { // mSignInHelper.goToAccount(accountId); // finish(); isSignedIn = true; } else { isSignedIn = false; } } }; mSignInHelper.setSignInListener(signInListener); ContentResolver cr = getActivity().getContentResolver(); Uri uri = i.getData(); // check if there is account information and direct accordingly if (Intent.ACTION_INSERT_OR_EDIT.equals(action)) { if ((uri == null) || !Imps.Account.CONTENT_ITEM_TYPE.equals(cr.getType(uri))) { action = Intent.ACTION_INSERT; } else { action = Intent.ACTION_EDIT; } } if (Intent.ACTION_INSERT.equals(action) && uri.getScheme().equals("ima")) { ImPluginHelper helper = ImPluginHelper.getInstance(getActivity()); String authority = uri.getAuthority(); String[] userpass_host = authority.split("@"); String[] user_pass = userpass_host[0].split(":"); mUserName = user_pass[0].toLowerCase(Locale.getDefault()); String pass = user_pass[1]; mDomain = userpass_host[1].toLowerCase(Locale.getDefault()); mPort = 0; final boolean regWithTor = i.getBooleanExtra("useTor", false); Cursor cursor = openAccountByUsernameAndDomain(cr); boolean exists = cursor.moveToFirst(); long accountId; if (exists) { accountId = cursor.getLong(0); mAccountUri = ContentUris.withAppendedId(Imps.Account.CONTENT_URI, accountId); pass = cursor.getString(ACCOUNT_PASSWORD_COLUMN); setAccountKeepSignedIn(true); mSignInHelper.activateAccount(mProviderId, accountId); mSignInHelper.signIn(pass, mProviderId, accountId, true); // setResult(RESULT_OK); cursor.close(); // finish(); return; } else { mProviderId = helper.createAdditionalProvider(helper.getProviderNames().get(0)); //xmpp FIXME accountId = ImApp.insertOrUpdateAccount(cr, mProviderId, -1, mUserName, mUserName, pass); mAccountUri = ContentUris.withAppendedId(Imps.Account.CONTENT_URI, accountId); mSignInHelper.activateAccount(mProviderId, accountId); createNewAccount(mUserName, pass, accountId, regWithTor); cursor.close(); return; } } else if (Intent.ACTION_INSERT.equals(action)) { mOriginalUserAccount = ""; // TODO once we implement multiple IM protocols mProviderId = ContentUris.parseId(uri); provider = mApp.getProvider(mProviderId); } else if (Intent.ACTION_EDIT.equals(action)) { if ((uri == null) || !Imps.Account.CONTENT_ITEM_TYPE.equals(cr.getType(uri))) { LogCleaner.warn(ImApp.LOG_TAG, "<AccountActivity>Bad data"); return; } isEdit = true; Cursor cursor = cr.query(uri, ACCOUNT_PROJECTION, null, null, null); if (cursor == null) { return; } if (!cursor.moveToFirst()) { cursor.close(); return; } mAccountId = cursor.getLong(cursor.getColumnIndexOrThrow(BaseColumns._ID)); mProviderId = cursor.getLong(ACCOUNT_PROVIDER_COLUMN); provider = mApp.getProvider(mProviderId); Cursor pCursor = cr.query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(mProviderId) }, null); Imps.ProviderSettings.QueryMap settings = new Imps.ProviderSettings.QueryMap(pCursor, cr, mProviderId, false /* don't keep updated */, null /* no handler */); try { mOriginalUserAccount = cursor.getString(ACCOUNT_USERNAME_COLUMN) + "@" + settings.getDomain(); mEditUserAccount.setText(mOriginalUserAccount); mEditPass.setText(cursor.getString(ACCOUNT_PASSWORD_COLUMN)); //mRememberPass.setChecked(!cursor.isNull(ACCOUNT_PASSWORD_COLUMN)); //mUseTor.setChecked(settings.getUseTor()); mBtnQrDisplay.setVisibility(View.VISIBLE); } finally { settings.close(); cursor.close(); } } else { LogCleaner.warn(ImApp.LOG_TAG, "<AccountActivity> unknown intent action " + action); return; } setupUIPost(); }
From source file:mobisocial.musubi.ui.FeedPannerActivity.java
void loadInitialFeed() { if (mFeeds.size() == 0) { Toast.makeText(this, "No feeds to view!", Toast.LENGTH_SHORT).show(); App.setCurrentFeed(this, null); finish();/*from www . j av a2s. c o m*/ return; } if (mFeedUri == null) { Toast.makeText(this, "No feed selected!", Toast.LENGTH_SHORT).show(); return; } long desired_feed = ContentUris.parseId(mFeedUri); int size = mFeeds.size(); for (int i = 0; i < size; ++i) { if (mFeeds.get(i) == desired_feed) { mFeedViewPager.setCurrentItem(i); break; } } }
From source file:com.ternup.caddisfly.activity.SurveyActivity.java
private long saveData() { if (isFormIncomplete()) { return -1; }/* w w w. j a v a2s . com*/ MainApp mainApp = (MainApp) getApplicationContext(); ContentValues values = new ContentValues(); values.put(LocationTable.COLUMN_DATE, (new Date().getTime())); String featureName = mainApp.address.getFeatureName(); if (featureName == null || featureName.isEmpty()) { return -1; } values.put(LocationTable.COLUMN_NAME, featureName); values.put(LocationTable.COLUMN_STREET, mainApp.address.getThoroughfare() == null ? "" : mainApp.address.getThoroughfare()); values.put(LocationTable.COLUMN_TOWN, mainApp.address.getSubLocality() == null ? "" : mainApp.address.getSubLocality()); values.put(LocationTable.COLUMN_CITY, mainApp.address.getLocality() == null ? "" : mainApp.address.getLocality()); values.put(LocationTable.COLUMN_STATE, mainApp.address.getAdminArea() == null ? "" : mainApp.address.getAdminArea()); values.put(LocationTable.COLUMN_COUNTRY, mainApp.address.getCountryName() == null ? "" : mainApp.address.getCountryName()); values.put(LocationTable.COLUMN_LONGITUDE, mainApp.location.getLongitude()); values.put(LocationTable.COLUMN_LATITUDE, mainApp.location.getLatitude()); values.put(LocationTable.COLUMN_ACCURACY, mainApp.location.getAccuracy()); Bundle bundle = mainApp.address.getExtras(); int sourceType = bundle.getInt("sourceType", 0); String notes = ""; if (mNotesFragment != null) { notes = mNotesFragment.getNotes(); } values.put(LocationTable.COLUMN_SOURCE, sourceType); values.put(LocationTable.COLUMN_NOTES, notes); Uri uri = getContentResolver().insert(LocationContentProvider.CONTENT_URI, values); long id = ContentUris.parseId(uri); PreferencesUtils.setLong(this, R.string.currentLocationId, id); mainApp.address = new Address(Locale.getDefault()); mainApp.location = new Location(LocationManager.GPS_PROVIDER); File file = new File(FileUtils.getStoragePath(this, 0, "", true) + "photo"); FileUtils.deleteFolder(this, id, ""); file.renameTo(new File(FileUtils.getStoragePath(this, id, "", true) + "photo")); return id; }
From source file:com.renjunzheng.vendingmachine.MyGcmListenerService.java
private void updatePurchaseInfo(String purchaseInfo) { try {//from ww w . j a v a 2 s .com DataDbHelper dbHelper = new DataDbHelper(this); SQLiteDatabase database = dbHelper.getWritableDatabase(); database.delete(DataContract.PurchasedEntry.TABLE_NAME, null, null); database.execSQL( "DELETE FROM SQLITE_SEQUENCE WHERE NAME = '" + DataContract.PurchasedEntry.TABLE_NAME + "'"); JSONArray valueArray = new JSONArray(purchaseInfo); Log.i(TAG, "the valueArray length: " + Integer.toString(valueArray.length())); for (int lc = 0; lc < valueArray.length(); ++lc) { JSONObject infoJson = valueArray.getJSONObject(lc); String item_name = infoJson.getString("item_name"); database.execSQL("DELETE FROM SQLITE_SEQUENCE WHERE NAME = '" + DataContract.PurchasedEntry.TABLE_NAME + "'"); //query based on this item_name and get item id //currently if queried has no such item in current database then don't insert to purchase table //find user id using the stored email Cursor itemIDCursor; int waitTime = 0; boolean breaked = false; do { String[] itemProj = new String[] { DataContract.ItemEntry._ID }; String[] itemSelArgs = new String[] { item_name }; itemIDCursor = database.query(DataContract.ItemEntry.TABLE_NAME, itemProj, DataContract.ItemEntry.COLUMN_ITEM_NAME + " = ?", itemSelArgs, null, null, null); if (waitTime != 0) { // if the item is not yet exists in the item table, probably means update purchase get called before update storage. So wait until find SystemClock.sleep(1000); if (++waitTime > 30) { breaked = true; break; } } else if (waitTime == 0) { waitTime = 1; } } while (itemIDCursor == null || itemIDCursor.getCount() == 0); if (!breaked) { itemIDCursor.moveToNext(); int itemID = itemIDCursor.getInt(0); itemIDCursor.close(); String[] userProj = new String[] { DataContract.UserEntry._ID }; String user_email = infoJson.getString("email"); String[] userSelArgs = new String[] { user_email }; Cursor userIDCursor = database.query(DataContract.UserEntry.TABLE_NAME, userProj, DataContract.UserEntry.COLUMN_EMAIL + " = ?", userSelArgs, null, null, null); userIDCursor.moveToNext(); Log.i(TAG, "userID: " + user_email); int userID = userIDCursor.getInt(0); Log.i(TAG, "itemID: " + itemID); Log.i(TAG, "userID: " + userID); userIDCursor.close(); ContentValues newValues = new ContentValues(); newValues.put(DataContract.PurchasedEntry.COLUMN_ITEM_KEY, itemID); newValues.put(DataContract.PurchasedEntry.COLUMN_USER_KEY, userID); newValues.put(DataContract.PurchasedEntry.COLUMN_ORDER_TIME, infoJson.getString("order_time")); newValues.put(DataContract.PurchasedEntry.COLUMN_PICK_UP_TIME, infoJson.getString("pickup_time")); newValues.put(DataContract.PurchasedEntry.COLUMN_QUANTITY, infoJson.getString("quantity")); newValues.put(DataContract.PurchasedEntry.COLUMN_RECEIPT_NUM, infoJson.getString("receipt")); Uri returnedUri = getContentResolver().insert(DataContract.PurchasedEntry.CONTENT_URI, newValues); Log.i(TAG, "inserted row num " + ContentUris.parseId(returnedUri)); } } database.close(); dbHelper.close(); } catch (JSONException e) { Log.e(TAG, "error when parsing Json"); } }
From source file:org.dmfs.tasks.notification.NotificationUpdaterService.java
private void updatePinnedNotifications(ArrayList<ContentSet> tasksToPin, boolean isReboot, boolean withSound, boolean withHeadsUpNotification) { ArrayList<Uri> pinnedTaskUris = TaskNotificationHandler.getPinnedTaskUris(this); // show notifications NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); for (ContentSet taskContentSet : tasksToPin) { boolean isAlreadyShown = pinnedTaskUris.contains(taskContentSet.getUri()); Integer taskId = TaskFieldAdapters.TASK_ID.get(taskContentSet); notificationManager.notify(taskId, makePinNotification(this, mBuilder, taskContentSet, !isAlreadyShown || withSound, !isAlreadyShown || withSound, withHeadsUpNotification)); }/*from w w w . j a v a 2 s.co m*/ // remove old notifications if (!isReboot) { for (Uri uri : pinnedTaskUris) { if (uri == null || uri.toString().equals("null")) { break; } long taskId = ContentUris.parseId(uri); if (taskId > -1 == !containsTask(tasksToPin, uri)) { Integer notificationId = Long.valueOf(ContentUris.parseId(uri)).intValue(); if (notificationId != null) { notificationManager.cancel(notificationId); } } } } TaskNotificationHandler.savePinnedTasks(this, tasksToPin); }
From source file:com.bangz.smartmute.services.LocationMuteService.java
private void handleRemoveGeofence(Uri uri) { long id = ContentUris.parseId(uri); LogUtils.LOGD(TAG, "Handling Remove one Geofence id = " + id); List<String> removeids = new ArrayList<String>(); removeids.add(String.valueOf(id)); ConnectionResult cr = mGoogleApiClient.blockingConnect(); if (cr.isSuccess() == false) { LogUtils.LOGD(TAG, "GoogleApiClient.blockconnect failed! message: " + cr.toString()); return;/*from www . j a v a 2 s . c om*/ } Status result = LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient, removeids).await(); mGoogleApiClient.disconnect(); LogUtils.LOGD(TAG, (result.isSuccess() ? "Successful" : "Failed") + " remove on geofence id = " + id); }
From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java
/** Insert a new plugin provider to the provider table. */ private static long insertProviderRow(ContentResolver cr, String providerName, String providerFullName, String signUpUrl) {/* w w w . j a va 2 s. c o m*/ ContentValues values = new ContentValues(3); values.put(Imps.Provider.NAME, providerName); values.put(Imps.Provider.FULLNAME, providerFullName); values.put(Imps.Provider.CATEGORY, ImApp.IMPS_CATEGORY); values.put(Imps.Provider.SIGNUP_URL, signUpUrl); Uri result = cr.insert(Imps.Provider.CONTENT_URI, values); return ContentUris.parseId(result); }