List of usage examples for android.net Uri getScheme
@Nullable public abstract String getScheme();
From source file:info.guardianproject.otr.app.im.app.NewChatActivity.java
private void doResolveIntent(Intent intent) { if (requireOpenDashboardOnStart(intent)) { long providerId = intent.getLongExtra(ImServiceConstants.EXTRA_INTENT_PROVIDER_ID, -1L); mLastAccountId = intent.getLongExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID, -1L); if (providerId == -1L || mLastAccountId == -1L) { finish();/*from w w w .j a va2 s.c o m*/ } else { // mChatSwitcher.open(); } return; } if (ImServiceConstants.ACTION_MANAGE_SUBSCRIPTION.equals(intent.getAction())) { long providerId = intent.getLongExtra(ImServiceConstants.EXTRA_INTENT_PROVIDER_ID, -1); mLastAccountId = intent.getLongExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID, -1L); String from = intent.getStringExtra(ImServiceConstants.EXTRA_INTENT_FROM_ADDRESS); if ((providerId == -1) || (from == null)) { finish(); } else { showSubscriptionDialog(providerId, from); } } else if (intent != null) { Uri data = intent.getData(); if (intent.getBooleanExtra("showaccounts", false)) mDrawer.openDrawer(GravityCompat.START); if (data != null) { if (data.getScheme() != null && data.getScheme().equals("immu")) { String user = data.getUserInfo(); String host = data.getHost(); String path = null; if (data.getPathSegments().size() > 0) path = data.getPathSegments().get(0); if (host != null && path != null) { IImConnection connMUC = findConnectionForGroupChat(user, host); if (connMUC != null) { startGroupChat(path, host, user, connMUC); setResult(RESULT_OK); } else { mHandler.showAlert("Connection Error", "Unable to find a connection to join a group chat from. Please sign in and try again."); setResult(Activity.RESULT_CANCELED); finish(); } } } else { String type = getContentResolver().getType(data); if (Imps.Chats.CONTENT_ITEM_TYPE.equals(type)) { long requestedContactId = ContentUris.parseId(data); Cursor cursorChats = mChatPagerAdapter.getCursor(); if (cursorChats != null) { cursorChats.moveToPosition(-1); int posIdx = 1; boolean foundChatView = false; while (cursorChats.moveToNext()) { long chatId = cursorChats.getLong(ChatView.CONTACT_ID_COLUMN); if (chatId == requestedContactId) { mChatPager.setCurrentItem(posIdx); foundChatView = true; break; } posIdx++; } if (!foundChatView) { Uri.Builder builder = Imps.Contacts.CONTENT_URI.buildUpon(); ContentUris.appendId(builder, requestedContactId); Cursor cursor = getContentResolver().query(builder.build(), ChatView.CHAT_PROJECTION, null, null, null); try { if (cursor.getCount() > 0) { cursor.moveToFirst(); openExistingChat(cursor); } } finally { cursor.close(); } } } } else if (Imps.Invitation.CONTENT_ITEM_TYPE.equals(type)) { //chatView.bindInvitation(ContentUris.parseId(data)); } } } else if (intent.hasExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID)) { //set the current account id mLastAccountId = intent.getLongExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID, -1L); //move the pager back to the first page if (mChatPager != null) mChatPager.setCurrentItem(0); } else { // refreshConnections(); } } }
From source file:net.sourceforge.servestream.service.MediaPlaybackService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { mServiceStartId = startId;/* w w w .j a va 2 s . c o m*/ mDelayedStopHandler.removeCallbacksAndMessages(null); if (intent != null) { String action = intent.getAction(); String cmd = intent.getStringExtra("command"); if (CMDNEXT.equals(cmd) || NEXT_ACTION.equals(action)) { gotoNext(true); } else if (CMDPREVIOUS.equals(cmd) || PREVIOUS_ACTION.equals(action)) { if (position() < 2000) { prev(); } else { seek(0); play(); } } else if (CMDTOGGLEPAUSE.equals(cmd) || TOGGLEPAUSE_ACTION.equals(action)) { boolean remove_status_icon = (intent.getIntExtra(CMDNOTIF, 0) != 2); if (isPlaying()) { pause(remove_status_icon); mPausedByTransientLossOfFocus = false; } else { play(); } if (!remove_status_icon) { updateNotification(true); } } else if (CMDPAUSE.equals(cmd) || PAUSE_ACTION.equals(action)) { pause(true); mPausedByTransientLossOfFocus = false; } else if (CMDPLAY.equals(cmd)) { play(); } else if (CMDSTOP.equals(cmd)) { pause(true); mPausedByTransientLossOfFocus = false; seek(0); } else if (BLUETOOTH_DEVICE_PAIRED.equals(action)) { Uri uri = TransportFactory.getUri(intent.getStringExtra("uri")); if (uri != null) { UriBean uriBean = TransportFactory.getTransport(uri.getScheme()).createUri(uri); AbsTransport transport = TransportFactory.getTransport(uriBean.getProtocol()); transport.setUri(uriBean); new DetermineActionTask(this, uriBean, this).execute(); } } } // make sure the service will shut down on its own if it was // just started but not bound to and nothing is playing mDelayedStopHandler.removeCallbacksAndMessages(null); Message msg = mDelayedStopHandler.obtainMessage(); mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY); return START_STICKY; }
From source file:de.ub0r.android.websms.WebSMS.java
/** * Parse data pushed by {@link Intent}./*from www .j a v a 2s .c o m*/ * * @param intent {@link Intent} */ private void parseIntent(final Intent intent) { final String action = intent.getAction(); Log.d(TAG, "launched with action: " + action); if (action == null) { return; } final Uri uri = intent.getData(); Log.i(TAG, "launched with uri: " + uri); if (uri != null && uri.toString().length() > 0) { // launched by clicking a sms: link, target number is in URI. final String scheme = uri.getScheme(); if (scheme != null) { if (scheme.equals("sms") || scheme.equals("smsto")) { final String s = uri.getSchemeSpecificPart(); this.parseSchemeSpecificPart(s); } else if (scheme.equals("content")) { this.parseThreadId(uri.getLastPathSegment()); } } } // check for extras String s = intent.getStringExtra("address"); if (!TextUtils.isEmpty(s)) { Log.d(TAG, "got address: " + s); this.lastTo = s; } s = intent.getStringExtra(Intent.EXTRA_TEXT); if (s == null) { Log.d(TAG, "got sms_body: " + s); s = intent.getStringExtra("sms_body"); } if (s == null) { final Uri stream = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); if (stream != null) { Log.d(TAG, "got stream: " + stream); try { InputStream is = this.getContentResolver().openInputStream(stream); final BufferedReader r = new BufferedReader(new InputStreamReader(is)); StringBuffer sb = new StringBuffer(); String line; while ((line = r.readLine()) != null) { sb.append(line + "\n"); } s = sb.toString().trim(); } catch (IOException e) { Log.e(TAG, "IO ERROR", e); } } } if (s != null) { Log.d(TAG, "set text: " + s); ((EditText) this.findViewById(R.id.text)).setText(s); this.lastMsg = s; } s = intent.getStringExtra(EXTRA_ERRORMESSAGE); if (s != null) { Log.e(TAG, "show error: " + s); Toast.makeText(this, s, Toast.LENGTH_LONG).show(); } final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this); if (p.getBoolean(PREFS_AUTOSEND, true)) { s = intent.getStringExtra(WebSMS.EXTRA_AUTOSEND); Log.d(TAG, "try autosend.."); Log.d(TAG, "s: " + s); Log.d(TAG, "lastMsg: " + this.lastMsg); Log.d(TAG, "lastTo: " + this.lastTo); if (s != null && !TextUtils.isEmpty(this.lastMsg) && !TextUtils.isEmpty(this.lastTo)) { // all data is here Log.d(TAG, "do autosend"); if (p.getBoolean(PREFS_USE_CURRENT_CON, true)) { // push it to current active connector Log.d(TAG, "use current connector"); if (prefsConnectorSpec != null && prefsSubConnectorSpec != null) { Log.d(TAG, "autosend: call send()"); if (this.send(prefsConnectorSpec, prefsSubConnectorSpec) && !this.isFinishing()) { Log.d(TAG, "sent successfully"); this.finish(); } } } else { // show connector chooser Log.d(TAG, "show connector chooser"); final AlertDialog.Builder b = new AlertDialog.Builder(this); b.setTitle(R.string.change_connector_); final ConnectorLabel[] items = this.getConnectorMenuItems(true /*isIncludePseudoConnectors*/); Log.d(TAG, "show #items: " + items.length); if (items.length > 0) { b.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { final ConnectorLabel sel = items[which]; // save old selected connector final ConnectorSpec pr0 = prefsConnectorSpec; final SubConnectorSpec pr1 = prefsSubConnectorSpec; // switch to selected WebSMS.this.saveSelectedConnector(sel.getConnector(), sel.getSubConnector()); // send message boolean sent = false; Log.d(TAG, "autosend: call send()"); if (prefsConnectorSpec != null && prefsSubConnectorSpec != null) { sent = WebSMS.this.send(prefsConnectorSpec, prefsSubConnectorSpec); } // restore old connector WebSMS.this.saveSelectedConnector(pr0, pr1); // quit if (sent && !WebSMS.this.isFinishing()) { Log.d(TAG, "sent successfully"); WebSMS.this.finish(); } } }); b.setNegativeButton(android.R.string.cancel, null); b.show(); } } } } }
From source file:kr.wdream.storyshop.AndroidUtilities.java
@SuppressLint("NewApi") public static String getPath(final Uri uri) { try {/*www. j av a 2s . c o m*/ final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; if (isKitKat && DocumentsContract.isDocumentUri(ApplicationLoader.applicationContext, uri)) { if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } } else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris .withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(ApplicationLoader.applicationContext, contentUri, null, null); } else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; switch (type) { case "image": contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; break; case "video": contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; break; case "audio": contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; break; } final String selection = "_id=?"; final String[] selectionArgs = new String[] { split[1] }; return getDataColumn(ApplicationLoader.applicationContext, contentUri, selection, selectionArgs); } } else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(ApplicationLoader.applicationContext, uri, null, null); } else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } } catch (Exception e) { FileLog.e("tmessages", e); } return null; }
From source file:com.ferdi2005.secondgram.AndroidUtilities.java
@SuppressLint("NewApi") public static String getPath(final Uri uri) { try {//from w ww. j a va2 s. com final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; if (isKitKat && DocumentsContract.isDocumentUri(ApplicationLoader.applicationContext, uri)) { if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } } else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris .withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(ApplicationLoader.applicationContext, contentUri, null, null); } else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; switch (type) { case "image": contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; break; case "video": contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; break; case "audio": contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; break; } final String selection = "_id=?"; final String[] selectionArgs = new String[] { split[1] }; return getDataColumn(ApplicationLoader.applicationContext, contentUri, selection, selectionArgs); } } else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(ApplicationLoader.applicationContext, uri, null, null); } else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } } catch (Exception e) { FileLog.e(e); } return null; }
From source file:com.wiret.arbrowser.AbstractArchitectCamActivity.java
@SuppressLint("NewApi") private String getPath(Context context, Uri uri) { final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; }// w w w . j a va2s . com // TODO handle non-primary volumes } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[] { split[1] }; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { // Return the remote address if (isGooglePhotosUri(uri)) return uri.getLastPathSegment(); return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
From source file:com.haomee.chat.activity.ChatActivity.java
/** * ??/* w ww. j a v a 2 s . c om*/ * * @param uri */ private void sendFile(Uri uri) { String filePath = null; if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { filePath = cursor.getString(column_index); } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { filePath = uri.getPath(); } File file = new File(filePath); if (file == null || !file.exists()) { MyToast.makeText(getApplicationContext(), "?", 0).show(); return; } if (file.length() > 10 * 1024 * 1024) { MyToast.makeText(getApplicationContext(), "?10M", 0).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); // ?chattype,?? if (chatType == CHATTYPE_GROUP) message.setChatType(ChatType.GroupChat); message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); conversation.addMessage(message); listView.setAdapter(adapter); adapter.refresh(); listView.setSelection(listView.getCount() - 1); setResult(RESULT_OK); }
From source file:com.amaze.filemanager.fragments.ZipViewer.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); s = getArguments().getString("path"); Uri uri = Uri.parse(s); f = new File(uri.getPath()); mToolbarContainer = getActivity().findViewById(R.id.lin); mToolbarContainer.setOnTouchListener(new View.OnTouchListener() { @Override//from w ww . j ava2 s. c om public boolean onTouch(View view, MotionEvent motionEvent) { if (stopAnims) { if ((!rarAdapter.stoppedAnimation)) { stopAnim(); } rarAdapter.stoppedAnimation = true; } stopAnims = false; return false; } }); hidemode = Sp.getInt("hidemode", 0); listView.setVisibility(View.VISIBLE); mLayoutManager = new LinearLayoutManager(getActivity()); listView.setLayoutManager(mLayoutManager); res = getResources(); mainActivity.supportInvalidateOptionsMenu(); if (mainActivity.theme1 == 1) rootView.setBackgroundColor(getResources().getColor(R.color.holo_dark_background)); else listView.setBackgroundColor(getResources().getColor(android.R.color.background_light)); gobackitem = Sp.getBoolean("goBack_checkbox", false); coloriseIcons = Sp.getBoolean("coloriseIcons", true); Calendar calendar = Calendar.getInstance(); showSize = Sp.getBoolean("showFileSize", false); showLastModified = Sp.getBoolean("showLastModified", true); showDividers = Sp.getBoolean("showDividers", true); year = ("" + calendar.get(Calendar.YEAR)).substring(2, 4); skin = PreferenceUtils.getPrimaryColorString(Sp); iconskin = PreferenceUtils.getFolderColorString(Sp); mainActivity.findViewById(R.id.buttonbarframe).setBackgroundColor(Color.parseColor(skin)); files = new ArrayList<>(); if (savedInstanceState == null && f != null) { if (f.getPath().endsWith(".rar")) { openmode = 1; SetupRar(null); } else { openmode = 0; SetupZip(null); } } else { f = new File(savedInstanceState.getString("file")); s = savedInstanceState.getString("uri"); uri = Uri.parse(s); f = new File(uri.getPath()); if (f.getPath().endsWith(".rar")) { openmode = 1; SetupRar(savedInstanceState); } else { openmode = 0; SetupZip(savedInstanceState); } } String fileName = null; try { if (uri.getScheme().equals("file")) { fileName = uri.getLastPathSegment(); } else { Cursor cursor = null; try { cursor = getActivity().getContentResolver().query(uri, new String[] { MediaStore.Images.ImageColumns.DISPLAY_NAME }, null, null, null); if (cursor != null && cursor.moveToFirst()) { fileName = cursor .getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME)); } } finally { if (cursor != null) { cursor.close(); } } } } catch (Exception e) { e.printStackTrace(); } if (fileName == null || fileName.trim().length() == 0) fileName = f.getName(); try { mainActivity.setActionBarTitle(fileName); } catch (Exception e) { mainActivity.setActionBarTitle(getResources().getString(R.string.zip_viewer)); } mainActivity.supportInvalidateOptionsMenu(); mToolbarHeight = getToolbarHeight(getActivity()); paddingTop = (mToolbarHeight) + dpToPx(72); mToolbarContainer.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { paddingTop = mToolbarContainer.getHeight(); mToolbarHeight = mainActivity.toolbar.getHeight(); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { mToolbarContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this); } else { mToolbarContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this); } } }); }
From source file:com.colorchen.qbase.utils.FileUtil.java
@TargetApi(19) public static String getPathFromUri(final Context context, final Uri uri) { final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; }// w ww. j a v a 2s . com } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[] { split[1] }; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { // Return the remote address if (isGooglePhotosUri(uri)) return uri.getLastPathSegment(); return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return ""; }