List of usage examples for android.net Uri getPath
@Nullable public abstract String getPath();
From source file:mobisocial.noteshere.util.UriImage.java
public UriImage(Context context, Uri uri) { if ((null == context) || (null == uri)) { throw new IllegalArgumentException(); }//from www .ja v a 2 s. c o m mRotation = rotationForImage(context, uri); String scheme = uri.getScheme(); if (scheme.equals("content")) { try { initFromContentUri(context, uri); } catch (Exception e) { Log.w(TAG, "last-ditch image params"); mPath = uri.getPath(); mContentType = context.getContentResolver().getType(uri); } } else if (uri.getScheme().equals("file")) { initFromFile(context, uri); } else { mPath = uri.getPath(); } mSrc = mPath.substring(mPath.lastIndexOf('/') + 1); if (mSrc.startsWith(".") && mSrc.length() > 1) { mSrc = mSrc.substring(1); } // Some MMSCs appear to have problems with filenames // containing a space. So just replace them with // underscores in the name, which is typically not // visible to the user anyway. mSrc = mSrc.replace(' ', '_'); mContext = context; mUri = uri; }
From source file:com.andrewshu.android.reddit.submit.SubmitLinkActivity.java
/** * Enable the UI after user is logged in. *///from www. ja v a2s. c o m private void start() { // Intents can be external (browser share page) or from Reddit is fun. String intentAction = getIntent().getAction(); if (Intent.ACTION_SEND.equals(intentAction)) { // Share Bundle extras = getIntent().getExtras(); if (extras != null) { String url = extras.getString(Intent.EXTRA_TEXT); final EditText submitLinkUrl = (EditText) findViewById(R.id.submit_link_url); final EditText submitLinkReddit = (EditText) findViewById(R.id.submit_link_reddit); final EditText submitTextReddit = (EditText) findViewById(R.id.submit_text_reddit); submitLinkUrl.setText(url); submitLinkReddit.setText(""); submitTextReddit.setText(""); mSubmitUrl = Constants.REDDIT_BASE_URL + "/submit"; } } else { String submitPath = null; Uri data = getIntent().getData(); if (data != null && Util.isRedditUri(data)) submitPath = data.getPath(); if (submitPath == null) submitPath = "/submit"; // the URL to do HTTP POST to mSubmitUrl = Util.absolutePathToURL(submitPath); // Put the subreddit in the text field final EditText submitLinkReddit = (EditText) findViewById(R.id.submit_link_reddit); final EditText submitTextReddit = (EditText) findViewById(R.id.submit_text_reddit); Matcher m = SUBMIT_PATH_PATTERN.matcher(submitPath); if (m.matches()) { String subreddit = m.group(1); if (StringUtils.isEmpty(subreddit)) { submitLinkReddit.setText(""); submitTextReddit.setText(""); } else { submitLinkReddit.setText(subreddit); submitTextReddit.setText(subreddit); } } } final Button submitLinkButton = (Button) findViewById(R.id.submit_link_button); submitLinkButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (validateLinkForm()) { final EditText submitLinkTitle = (EditText) findViewById(R.id.submit_link_title); final EditText submitLinkUrl = (EditText) findViewById(R.id.submit_link_url); final EditText submitLinkReddit = (EditText) findViewById(R.id.submit_link_reddit); final EditText submitLinkCaptcha = (EditText) findViewById(R.id.submit_link_captcha); new SubmitLinkTask(submitLinkTitle.getText().toString(), submitLinkUrl.getText().toString(), submitLinkReddit.getText().toString(), Constants.SUBMIT_KIND_LINK, submitLinkCaptcha.getText().toString()).execute(); } } }); final Button submitTextButton = (Button) findViewById(R.id.submit_text_button); submitTextButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (validateTextForm()) { final EditText submitTextTitle = (EditText) findViewById(R.id.submit_text_title); final EditText submitTextText = (EditText) findViewById(R.id.submit_text_text); final EditText submitTextReddit = (EditText) findViewById(R.id.submit_text_reddit); final EditText submitTextCaptcha = (EditText) findViewById(R.id.submit_text_captcha); new SubmitLinkTask(submitTextTitle.getText().toString(), submitTextText.getText().toString(), submitTextReddit.getText().toString(), Constants.SUBMIT_KIND_SELF, submitTextCaptcha.getText().toString()).execute(); } } }); // Check the CAPTCHA new MyCaptchaCheckRequiredTask().execute(); }
From source file:com.jefftharris.passwdsafe.file.PasswdFileUri.java
/** Constructor */ private PasswdFileUri(Uri uri, Context ctx) { itsUri = uri;// w w w . j a v a2 s . c o m itsType = getUriType(uri); switch (itsType) { case FILE: { itsFile = new File(uri.getPath()); resolveFileUri(); break; } case GENERIC_PROVIDER: { itsFile = null; resolveGenericProviderUri(ctx); break; } case SYNC_PROVIDER: { itsFile = null; resolveSyncProviderUri(ctx); break; } case EMAIL: //noinspection UnnecessaryDefault default: { itsFile = null; itsWritableInfo = new Pair<>(false, null); itsIsDeletable = false; break; } } }
From source file:com.fvd.nimbus.MainActivity.java
@SuppressLint("NewApi") @Override//from w ww .jav a2s .c o m protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == TAKE_PHOTO) { if (resultCode == -1) { try { if (data != null) { if (data.hasExtra("data")) { Bitmap bm = data.getParcelableExtra("data"); photoFileName = appSettings.saveTempBitmap(bm); bm.recycle(); } } else { if (outputFileUri != null) photoFileName = outputFileUri.getPath(); else photoFileName = getImagePath(); } if (appSettings.isFileExists(photoFileName)) { Intent iPaint = new Intent(); iPaint.putExtra("temp", true); iPaint.putExtra("path", photoFileName); iPaint.setClassName("com.fvd.nimbus", "com.fvd.nimbus.PaintActivity"); startActivity(iPaint); } showProgress(false); } catch (Exception e) { appSettings.appendLog("main:onActivityResult: exception - " + e.getMessage()); showProgress(false); } } else showProgress(false); } else if (requestCode == TAKE_PICTURE) { if (resultCode == -1 && data != null) { boolean temp = false; try { Uri resultUri = data.getData(); String drawString = resultUri.getPath(); String galleryString = getGalleryPath(resultUri); if (galleryString != null && galleryString.length() > 0) { drawString = galleryString; } else { try { InputStream input = getApplicationContext().getContentResolver() .openInputStream(resultUri); Bitmap bm = BitmapFactory.decodeStream(input); drawString = appSettings.saveTempBitmap(bm); bm.recycle(); temp = true; } catch (Exception e) { drawString = ""; showProgress(false); } } if (drawString.length() > 0 && drawString.indexOf("/exposed_content/") == -1) { try { Intent iPaint = new Intent(); iPaint.putExtra("temp", temp); iPaint.putExtra("path", drawString); iPaint.setClassName("com.fvd.nimbus", "com.fvd.nimbus.PaintActivity"); startActivity(iPaint); } catch (Exception e) { } } showProgress(false); } catch (Exception e) { appSettings.appendLog("main:onActivityResult " + e.getMessage()); showProgress(false); } } else showProgress(false); } else if (requestCode == 5) { if (resultCode == RESULT_OK) { userMail = data.getStringExtra("userMail"); userPass = data.getStringExtra("userPass"); serverHelper.getInstance().sendOldRequest("user_register", String.format( "{\"action\": \"user_register\",\"email\":\"%s\",\"password\":\"%s\",\"_client_software\": \"ff_addon\"}", userMail, userPass), ""); } } else if (requestCode == 6) { showLogin(); } else if (requestCode == SHOW_SETTINGS) { switch (resultCode) { case RESULT_FIRST_USER + 1: Intent i = new Intent(getApplicationContext(), PrefsActivity.class); startActivity(i); //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up ); overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out); break; case RESULT_FIRST_USER + 2: if (appSettings.sessionId.length() == 0) showLogin(); else { if (true || appSettings.service == "") { appSettings.sessionId = ""; Editor e = prefs.edit(); e.putString("userMail", userMail); e.putString("userPass", ""); e.putString("sessionId", appSettings.sessionId); e.commit(); showLogin(); } else { i = new Intent(getApplicationContext(), loginWithActivity.class); i.putExtra("logout", "true"); i.putExtra("service", appSettings.service); startActivity(i); overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out); } } break; case RESULT_FIRST_USER + 3: try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getApplicationInfo().packageName))); } catch (Exception e) { } case RESULT_FIRST_USER + 4: Uri uri = Uri.parse( "http://help.everhelper.me/customer/portal/articles/1376820-nimbus-clipper-for-android---quick-guide"); Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it); //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up ); overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out); break; case RESULT_FIRST_USER + 5: final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); alertDialogBuilder.setMessage(getScriptContent("license.txt")).setCancelable(false) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // no alert dialog shown //alertDialogShown = null; // canceled setResult(RESULT_CANCELED); // and finish //finish(); } }); // create alert dialog final AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.setTitle(getString(R.string.license_title)); // and show //alertDialogShown = alertDialog; try { alertDialog.show(); } catch (final java.lang.Exception e) { // nothing to do } catch (final java.lang.Error e) { // nothing to do } break; default: break; } } }
From source file:com.github.guwenk.smuradio.SignInDialog.java
public String getFileName(Uri uri) { String result = null;/*from w ww. j av a2 s .c o m*/ if (uri.getScheme().equals("content")) { Cursor cursor = getActivity().getContentResolver().query(uri, null, null, null, null); try { if (cursor != null && cursor.moveToFirst()) { result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); } } finally { cursor.close(); } } if (result == null) { result = uri.getPath(); int cut = result.lastIndexOf('/'); if (cut != -1) { result = result.substring(cut + 1); } } return result; }
From source file:com.google.cloud.solutions.smashpix.MainActivity.java
public String getPathFromData(Uri uri) { try {//from w ww . j av a2 s .c o m String[] filePathData = {MediaStore.Images.Media.DATA}; Cursor cursor = getContentResolver().query(uri, filePathData, null, null, null); cursor.moveToFirst(); int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA); String picturePath = cursor.getString(dataColumnIndex); cursor.close(); return picturePath; } catch (Exception e) { Log.e(Constants.APP_NAME, e.getMessage()); } return uri.getPath(); }
From source file:com.openerp.addons.messages.MessageComposeActivty.java
public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // app icon in action bar clicked; go home finish();// ww w .j a v a 2 s.c o m return true; case R.id.menu_message_compose_add_attachment_images: requestForAttachmentIntent(ATTACHMENT_TYPE.IMAGE); return true; case R.id.menu_message_compose_add_attachment_files: requestForAttachmentIntent(ATTACHMENT_TYPE.TEXT_FILE); return true; //?? case R.id.menu_message_compose_send: EditText edtSubject = (EditText) findViewById(R.id.edtMessageSubject); EditText edtBody = (EditText) findViewById(R.id.edtMessageBody); edtSubject.setError(null); edtBody.setError(null); if (selectedPartners.size() == 0) { Toast.makeText(this, "", Toast.LENGTH_LONG).show(); } else if (TextUtils.isEmpty(edtSubject.getText())) { edtSubject.setError("? !"); } else if (TextUtils.isEmpty(edtBody.getText())) { edtBody.setError("?!"); } else { Toast.makeText(this, "??...", Toast.LENGTH_LONG).show(); String subject = edtSubject.getText().toString(); String body = edtBody.getText().toString(); //oe? Ir_AttachmentDBHelper attachment = new Ir_AttachmentDBHelper(MainActivity.context); JSONArray newAttachmentIds = new JSONArray(); for (Uri file : file_uris) { // oe????? File fileData = new File(file.getPath()); ContentValues values = new ContentValues(); values.put("datas_fname", getFilenameFromUri(file)); values.put("res_model", "mail.compose.message"); values.put("company_id", scope.User().getCompany_id()); values.put("type", "binary"); values.put("res_id", 0); values.put("file_size", fileData.length()); values.put("db_datas", Base64Helper.fileUriToBase64(file, getContentResolver())); values.put("name", getFilenameFromUri(file)); int newId = attachment.create(attachment, values); newAttachmentIds.put(newId); } // TASK: sending mail HashMap<String, Object> values = new HashMap<String, Object>(); values.put("subject", subject); if (is_note_body) { values.put("body", Html.toHtml(edtBody.getText())); } else { values.put("body", body); } values.put("partner_ids", getPartnersId()); values.put("attachment_ids", newAttachmentIds); if (is_reply) { SendMailMessageReply sendMessageRply = new SendMailMessageReply(values); sendMessageRply.execute((Void) null); } else { SendMailMessage sendMessage = new SendMailMessage(values); sendMessage.execute((Void) null); } } return true; default: return super.onOptionsItemSelected(item); } }
From source file:key.secretkey.SettingsActivity.java
/** * Opens a key generator to generate a public/private key pair */// w ww. j av a 2 s. c o m // public void makeSshKey(boolean fromPreferences) { // Intent intent = new Intent(getApplicationContext(), SshKeyGen.class); // startActivity(intent); // if (!fromPreferences) { // setResult(RESULT_OK); // finish(); // } // } // private void copySshKey(Uri uri) throws IOException { // InputStream sshKey = this.getContentResolver().openInputStream(uri); // byte[] privateKey = IOUtils.toByteArray(sshKey); // FileUtils.writeByteArrayToFile(new File(getFilesDir() + "/.ssh_key"), privateKey); // sshKey.close(); // } // Returns whether the autofill service is enabled // private boolean isServiceEnabled() { // AccessibilityManager am = (AccessibilityManager) this // .getSystemService(Context.ACCESSIBILITY_SERVICE); // List<AccessibilityServiceInfo> runningServices = am // .getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_GENERIC); // for (AccessibilityServiceInfo service : runningServices) { // if ("com.zeapo.pwdstore/.autofill.AutofillService".equals(service.getId())) { // return true; // } // } // return false; // } protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { switch (requestCode) { // case IMPORT_SSH_KEY: { // try { // final Uri uri = data.getData(); // // if (uri == null) { // throw new IOException("Unable to open file"); // } // copySshKey(uri); // Toast.makeText(this, this.getResources().getString(R.string.ssh_key_success_dialog_title), Toast.LENGTH_LONG).show(); // SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); // SharedPreferences.Editor editor = prefs.edit(); // editor.putBoolean("use_generated_key", false); // editor.apply(); // // //delete the public key from generation // File file = new File(getFilesDir() + "/.ssh_key.pub"); // file.delete(); // // setResult(RESULT_OK); // finish(); // } catch (IOException e) { // new AlertDialog.Builder(this). // setTitle(this.getResources().getString(R.string.ssh_key_error_dialog_title)). // setMessage(this.getResources().getString(R.string.ssh_key_error_dialog_text) + e.getMessage()). // setPositiveButton(this.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialogInterface, int i) { // // pass // } // }).show(); // } // } // break; // case EDIT_GIT_INFO: { // // } // break; // case SELECT_GIT_DIRECTORY: { // final Uri uri = data.getData(); // // if (uri.getPath().equals(Environment.getExternalStorageDirectory().getPath())) { // // the user wants to use the root of the sdcard as a store... // new AlertDialog.Builder(this). // setTitle("SD-Card root selected"). // setMessage("You have selected the root of your sdcard for the store. " + // "This is extremely dangerous and you will lose your data " + // "as its content will, eventually, be deleted"). // setPositiveButton("Remove everything", new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) // .edit() // .putString("git_external_repo", uri.getPath()) // .apply(); // } // }). // setNegativeButton(R.string.dialog_cancel, null).show(); // } else { // PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) // .edit() // .putString("git_external_repo", uri.getPath()) // .apply(); // } // } // break; case EXPORT_PASSWORDS: { final Uri uri = data.getData(); final File repositoryDirectory = PasswordStorage.getRepositoryDirectory(getApplicationContext()); SimpleDateFormat fmtOut = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.US); Date date = new Date(); String password_now = "/password_store_" + fmtOut.format(date); final File targetDirectory = new File(uri.getPath() + password_now); if (repositoryDirectory != null) { try { FileUtils.copyDirectory(repositoryDirectory, targetDirectory, true); } catch (IOException e) { Log.d("PWD_EXPORT", "Exception happened : " + e.getMessage()); } } } break; default: break; } } }
From source file:com.android.nsboc.ComposeFragment.java
public String getPath(Uri uri) { // just some safety built in if (uri == null) { return null; }/*from w ww. ja v a 2s . c om*/ // try to retrieve the image from the media store first // this will only work for images selected from gallery String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = getActivity().managedQuery(uri, projection, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } // this is our fallback here return uri.getPath(); }
From source file:com.ximai.savingsmore.save.activity.BusinessMyCenterActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode != RESULT_OK) { return;//w w w . j av a2 s . co m } else if (requestCode == PICK_FROM_CAMERA || requestCode == PICK_FROM_IMAGE) { Uri uri = null; if (null != intent && intent.getData() != null) { uri = intent.getData(); } else { String fileName = PreferencesUtils.getString(this, "tempName"); uri = Uri.fromFile(new File(FileSystem.getCachesDir(this, true).getAbsolutePath(), fileName)); } if (uri != null) { cropImage(uri, CROP_PHOTO_CODE); } } else if (requestCode == CROP_PHOTO_CODE) { Uri photoUri = intent.getParcelableExtra(MediaStore.EXTRA_OUTPUT); if (isslinece) { MyImageLoader.displayDefaultImage("file://" + photoUri.getPath(), slience_image); zhizhao_path = photoUri.toString(); try { upLoadImage(new File((new URI(photoUri.toString()))), "BusinessLicense"); } catch (URISyntaxException e) { e.printStackTrace(); } } else if (isZhengshu) { MyImageLoader.displayDefaultImage("file://" + photoUri.getPath(), zhengshu_iamge); xukezheng_path = photoUri.toString(); try { upLoadImage(new File((new URI(photoUri.toString()))), "LicenseKey"); } catch (URISyntaxException e) { e.printStackTrace(); } } else if (isheadImage) { MyImageLoader.displayDefaultImage("file://" + photoUri.getPath(), head_image); tuoxiang_path = photoUri.toString(); try { upLoadImage(new File((new URI(photoUri.toString()))), "Photo"); } catch (URISyntaxException e) { e.printStackTrace(); } //upLoadImage(new File((new URI(photoUri.toString()))), "Photo"); } else if (isItem) { if (imagePath.size() + images.size() < 10) { shangpu_path.add(photoUri.toString()); try { upLoadImage(new File((new URI(photoUri.toString()))), "Seller"); } catch (URISyntaxException e) { e.printStackTrace(); } //imagePath.add(photoUri.getPath()); } else { Toast.makeText(BusinessMyCenterActivity.this, "?9", Toast.LENGTH_SHORT).show(); } } //addImage(imagePath); } }