List of usage examples for android.net Uri getLastPathSegment
@Nullable public abstract String getLastPathSegment();
From source file:org.openbmap.services.MasterBrainService.java
/** * Opens new session//from www .j a v a 2 s . c o m */ private int setupNewSession() { // invalidate all active session mDataHelper.invalidateActiveSessions(); // Create a new session and activate it // Then start HostActivity. HostActivity onStart() and onResume() check active session // and starts services for active session final Session active = new Session(); active.setCreatedAt(System.currentTimeMillis()); active.setLastUpdated(System.currentTimeMillis()); active.setDescription("No description yet"); active.isActive(true); // id can only be set after session has been stored to database. final Uri result = mDataHelper.storeSession(active); final int id = Integer.valueOf(result.getLastPathSegment()); active.setId(id); return id; }
From source file:com.android.mms.transaction.ReadRecTransaction.java
public void run() { MmsLog.d(MmsApp.TXN_TAG, "ReadRecTransaction: process()"); // prepare for ReadRec int readReportState = 0; String messageId = null;/*from w w w.j a v a2s. c o m*/ long msgId = 0; EncodedStringValue[] sender = new EncodedStringValue[1]; Cursor cursor = null; cursor = SqliteWrapper.query(mContext, mContext.getContentResolver(), mUri, new String[] { Mms.MESSAGE_ID, Mms.READ_REPORT, Mms._ID }, null, null, null); if (cursor != null) { try { if (cursor.moveToFirst()) { messageId = cursor.getString(0); readReportState = cursor.getInt(1); msgId = cursor.getLong(2); } // if curosr==null, this means the mms is deleted during // processing. // exception will happened. catched by out catch clause. // so do not catch exception here. } finally { cursor.close(); } } MmsLog.d(MmsApp.TXN_TAG, "messageid:" + messageId + ",and readreport flag:" + readReportState + ", mSubId = " + mSubId); cursor = null; cursor = SqliteWrapper.query(mContext, mContext.getContentResolver(), Uri.parse("content://mms/" + msgId + "/addr"), new String[] { Mms.Addr.ADDRESS, Mms.Addr.CHARSET }, Mms.Addr.TYPE + " = " + PduHeaders.FROM, null, null); if (cursor != null) { try { if (cursor.moveToFirst()) { String address = cursor.getString(0); int charSet = cursor.getInt(1); MmsLog.d(MmsApp.TXN_TAG, "find address:" + address + ",charset:" + charSet); sender[0] = new EncodedStringValue(charSet, PduPersister.getBytes(address)); } // if cursor == null exception will catched by out catch clause. } finally { cursor.close(); } } try { ReadRecInd readRecInd = new ReadRecInd( new EncodedStringValue(PduHeaders.FROM_INSERT_ADDRESS_TOKEN_STR.getBytes()), messageId.getBytes(), PduHeaders.CURRENT_MMS_VERSION, PduHeaders.READ_STATUS_READ, // always // set // read. sender); readRecInd.setDate(System.currentTimeMillis() / 1000); Uri uri = PduPersister.getPduPersister(mContext).persist(readRecInd, Mms.Outbox.CONTENT_URI, true, MmsPreferenceActivity.getIsGroupMmsEnabled(mContext), null); byte[] datas = new PduComposer(mContext, readRecInd).make(); mPduFile = createPduFile(datas, READREP_REQ_NAME + uri.getLastPathSegment()); if (mPduFile == null) { Log.e(MmsApp.TXN_TAG, "create pdu file req failed!"); return; } //Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED); //intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId); //intent.putExtra(TransactionBundle.URI, mUri.toString()); Log.d(MmsApp.TXN_TAG, "ReadRecTransaction mUri:" + mUri); final Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED, mUri, mContext, MmsReceiver.class); intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId); PendingIntent sentIntent = PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Uri pduFileUri = FileProvider.getUriForFile(mContext, MMS_FILE_PROVIDER_AUTHORITIES, mPduFile); SmsManager.getSmsManagerForSubscriptionId(mSubId).sendMultimediaMessage(mContext, pduFileUri, null, null, sentIntent); } catch (InvalidHeaderValueException e) { Log.e(TAG, "Invalide header value", e); getState().setState(FAILED); getState().setContentUri(mUri); notifyObservers(); } catch (MmsException e) { Log.e(TAG, "Persist message failed", e); getState().setState(FAILED); getState().setContentUri(mUri); notifyObservers(); } catch (Throwable t) { Log.e(TAG, Log.getStackTraceString(t)); getState().setState(FAILED); getState().setContentUri(mUri); notifyObservers(); } }
From source file:com.amazon.android.tv.tenfoot.ui.fragments.ContentDetailsFragment.java
/** * Check if there is a global search intent. *///from w ww . ja v a 2 s.c om private boolean checkGlobalSearchIntent() { Log.v(TAG, "checkGlobalSearchIntent called."); Intent intent = getActivity().getIntent(); String intentAction = intent.getAction(); String globalSearch = getString(R.string.global_search); if (globalSearch.equalsIgnoreCase(intentAction)) { Uri intentData = intent.getData(); Log.d(TAG, "action: " + intentAction + " intentData:" + intentData); int selectedIndex = Integer.parseInt(intentData.getLastPathSegment()); ContentContainer contentContainer = ContentBrowser.getInstance(getActivity()).getRootContentContainer(); int contentTally = 0; if (contentContainer == null) { return false; } for (Content content : contentContainer) { ++contentTally; if (selectedIndex == contentTally) { mSelectedContent = content; return true; } } } return false; }
From source file:com.android.messaging.mmslib.util.PduCache.java
/** * @param uri The Uri to be normalized./*from w ww. j a v a 2s .com*/ * @return Uri The normalized key of cached entry. */ private Uri normalizeKey(Uri uri) { int match = URI_MATCHER.match(uri); Uri normalizedKey = null; switch (match) { case MMS_ALL_ID: normalizedKey = uri; break; case MMS_INBOX_ID: case MMS_SENT_ID: case MMS_DRAFTS_ID: case MMS_OUTBOX_ID: String msgId = uri.getLastPathSegment(); normalizedKey = Uri.withAppendedPath(Mms.CONTENT_URI, msgId); break; default: return null; } if (LOCAL_LOGV) { Log.v(TAG, uri + " -> " + normalizedKey); } return normalizedKey; }
From source file:com.stoneapp.ourvlemoodle2.tasks.EventSync.java
public void addCalendarEvent(MoodleEvent event) { Calendar cal = Calendar.getInstance(); Uri EVENTS_URI = Uri.parse("content://com.android.calendar/" + "events"); //creates a new uri for calendar ContentResolver cr = context.getContentResolver(); // event insert ContentValues values = new ContentValues(); values.put("calendar_id", 1); values.put("_id", event.getEventid()); values.put("title", event.getName()); values.put("allDay", 0); values.put("dtstart", (long) event.getTimestart() * 1000); values.put("dtend", (long) event.getTimestart() * 1000 + ((long) event.getTimeduration() * 1000)); values.put("description", Html.fromHtml(event.getDescription()).toString().trim()); values.put("hasAlarm", 1); values.put("eventTimezone", "UTC/GMT -5:00"); Uri calevent = cr.insert(EVENTS_URI, values); // reminder insert Uri REMINDERS_URI = Uri.parse("content://com.android.calendar/" + "reminders"); values = new ContentValues(); ContentValues values2 = new ContentValues(); ContentValues values3 = new ContentValues(); values.put("event_id", Long.parseLong(calevent.getLastPathSegment())); values.put("method", 1); values.put("minutes", 10); values2.put("event_id", Long.parseLong(calevent.getLastPathSegment())); values2.put("method", 1); values2.put("minutes", 60); values3.put("event_id", Long.parseLong(calevent.getLastPathSegment())); values3.put("method", 1); values3.put("minutes", 60 * 24); cr.insert(REMINDERS_URI, values); cr.insert(REMINDERS_URI, values2); cr.insert(REMINDERS_URI, values3); }
From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java
public void showNotification(Bundle settings, Intent intent) { Uri uri = intent.getData(); int uriCode = URI_MATCHER.match(uri); if (uriCode != C.REQUEST_CODE_LOCALNOTIFICATION) { Log.w(C.TAG, "Notification with invalid uri: " + uri); return;/*from w ww. j a v a 2 s. c om*/ } String idString = uri.getLastPathSegment(); if (idString == null) { Log.w(C.TAG, "Just got a notification with no data"); return; } Log.i(C.TAG, "LocalNotificationsBackend.showNotification: " + settings + " keys: " + settings.keySet()); String key = PREFS_PREFIX + idString; JSONObject obj = getJSONNotificationObject(key); if (obj == null) { // return; obj = new JSONObject(); try { obj.put("vibrate", false); obj.put("sound", false); obj.put("title", "A test notification"); obj.put("body", "New job: fix Mr. Gluck's hazy TV, PDQ!"); obj.put("id", 42); obj.put("timeMillisSince1970", System.currentTimeMillis()); } catch (JSONException e) { Log.e(C.TAG, "Erm not thought possible"); } } Notification n = createNotification(settings, obj); if (n != null) { NotificationManager nm = (NotificationManager) mContext.getSystemService(Service.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_MASK | obj.optInt("id"), n); } mPrefs.edit().remove(key).commit(); }
From source file:de.hshannover.f4.trust.ironcontrol.view.AdvancedRequestFragment.java
public String saveSearch(String savedName) { if (!isNameValid(savedName)) { return null; }/*from w w w.j av a 2 s .co m*/ String id = getExistSearchId(savedName); if (id != null) { return id; } String startIdentifier = sStartIdentifier.getSelectedItem().toString(); String startIdentifierValue = etStartIdentifier.getText().toString(); String matchLinks = etMatchLinks.getText().toString(); String resultFilter = etResultFilter.getText().toString(); int maxDepth = sbMaxDepth.getProgress(); int maxSize = sbMaxSize.getProgress() * 1000; String terminalIdentifiers = terminalIdentifierTypesToString(); ContentValues publishValues = new ContentValues(); publishValues.put(Requests.COLUMN_NAME, savedName); publishValues.put(Requests.COLUMN_IDENTIFIER1, startIdentifier); publishValues.put(Requests.COLUMN_IDENTIFIER1_Value, startIdentifierValue); publishValues.put(Requests.COLUMN_MATCH_LINKS, matchLinks); publishValues.put(Requests.COLUMN_RESULT_FILTER, resultFilter); publishValues.put(Requests.COLUMN_MAX_DEPTH, maxDepth); publishValues.put(Requests.COLUMN_MAX_SITZ, maxSize); publishValues.put(Requests.COLUMN_TERMINAL_IDENTIFIER_TYPES, terminalIdentifiers); Uri returnUri = getActivity().getContentResolver().insert(DBContentProvider.SEARCH_URI, publishValues); return returnUri.getLastPathSegment(); }
From source file:com.dropbox.android.sample.DBRoulette.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CHOOSE_FILE) { // return from file upload if (resultCode == Activity.RESULT_OK) { Uri uri = null; if (data != null) { uri = data.getData();//from w w w . j av a2 s. c o m } if (uri != null) { String path = uri.getPath(); System.out.println(uri.getLastPathSegment()); if (path.startsWith("/file")) path = path.replace("/file", ""); operations.UploadFile(MyDropbox_DIR, new File(path), mList); } } else { Log.w(TAG, "Unknown Activity Result from mediaImport: " + resultCode); } } }
From source file:org.wheelmap.android.activity.POIDetailActivity.java
private void executeIntent(Intent intent) { if (intent == null) { return;// w w w. j a va 2 s . co m } // check if this intent is started via custom scheme link if (Intent.ACTION_VIEW.equals(intent.getAction())) { Uri uri = intent.getData(); if (uri == null) { Log.d(TAG, "uri has no data - cant extract wmID"); showErrorMessage(getString(R.string.error_noid_title), getString(R.string.error_noid_message)); return; } wmID = uri.getLastPathSegment(); try { Long.parseLong(wmID); } catch (NumberFormatException e) { Log.e(TAG, " wmID = " + wmID, e); finish(); return; } showDetailForWmId(wmID); return; } Long poiId = intent.getLongExtra(Extra.POI_ID, Extra.ID_UNKNOWN); showDetailFragment(poiId); setIntent(null); }
From source file:com.trail.octo.UploadDocs.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.e("Check", "ActivityResult"); Bitmap image = null;//from ww w . ja va2 s. c o m if (resultCode == RESULT_OK) { if (requestCode == REQUEST_CAMERA) { image = (Bitmap) data.getExtras().get("data"); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, bytes); byte[] objects = bytes.toByteArray(); encodedmessage = Base64.encodeToString(objects, Base64.DEFAULT); } else if (requestCode == SELECT_FILE) { Uri selectedImageUri = data.getData(); Log.e("Check", "uri obtained"); file_name = selectedImageUri.getLastPathSegment(); String[] projection = { MediaStore.MediaColumns.DATA }; Log.e("Check", "Projection Obtained"); Cursor cursor = managedQuery(selectedImageUri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); cursor.moveToFirst(); String selectedImagePath = cursor.getString(column_index); Bitmap temp; Log.e("Check", "Path " + selectedImagePath); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(selectedImagePath, options); final int REQUIRED_SIZE = 200; int scale = 1; while (options.outWidth / scale / 2 >= REQUIRED_SIZE && options.outHeight / scale / 2 >= REQUIRED_SIZE) scale *= 2; options.inSampleSize = scale; options.inJustDecodeBounds = false; temp = BitmapFactory.decodeFile(selectedImagePath, options); Log.e("Check", "Decoded"); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); temp.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); byte[] objects = byteArrayOutputStream.toByteArray(); encodedmessage = Base64.encodeToString(objects, Base64.DEFAULT); image = temp; } SharedPreferences sharedPreferences = getSharedPreferences("docs_data", MODE_APPEND); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(file_type, encodedmessage); editor.commit(); Intent intent = new Intent(getApplicationContext(), DocumentUploadPreview.class); intent.putExtra("file_type", file_type); intent.putExtra("file_name", file_name); //intent.putExtra("encodedmessage",encodedmessage); startActivity(intent); // popupWindow_document_preview.showAtLocation(view_preview, Gravity.CENTER, 0, 40); // popup_imageView_document.setImageBitmap(image); } }