android.net.Uri.decode()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(226)

本文整理了Java中android.net.Uri.decode()方法的一些代码示例,展示了Uri.decode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Uri.decode()方法的具体详情如下:
包路径:android.net.Uri
类名称:Uri
方法名:decode

Uri.decode介绍

[英]Decodes '%'-escaped octets in the given string using the UTF-8 scheme. Replaces invalid octets with the unicode replacement character ("\uFFFD").
[中]

代码示例

代码示例来源:origin: Curzibn/Luban

/**
 * <b>BuildTime:</b> 2014年10月23日<br>
 * <b>Description:</b> <br>
 *
 * @param mUri
 *
 * @return
 */
public static String getAbsolutePathFromNoStandardUri(Uri mUri) {
 String filePath = null;
 String mUriString = mUri.toString();
 mUriString = Uri.decode(mUriString);
 String pre1 = "file://" + SDCARD + File.separator;
 String pre2 = "file://" + SDCARD_MNT + File.separator;
 if (mUriString.startsWith(pre1)) {
  filePath = Environment.getExternalStorageDirectory().getPath()
    + File.separator + mUriString.substring(pre1.length());
 } else if (mUriString.startsWith(pre2)) {
  filePath = Environment.getExternalStorageDirectory().getPath()
    + File.separator + mUriString.substring(pre2.length());
 }
 return filePath;
}

代码示例来源:origin: k9mail/k-9

/**
 * Start the activity to add a phone number to an existing contact or add a new one.
 *
 * @param phoneNumber
 *         The phone number to add to a contact, or to use when creating a new contact.
 */
public void addPhoneContact(final String phoneNumber) {
  Intent addIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
  addIntent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
  addIntent.putExtra(ContactsContract.Intents.Insert.PHONE, Uri.decode(phoneNumber));
  addIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  mContext.startActivity(addIntent);
  clearCache();
}

代码示例来源:origin: smuyyh/BookReader

@Override
public void initDatas() {
  mFilePath = Uri.decode(getIntent().getDataString().replace("file://", ""));
  mFileName = mFilePath.substring(mFilePath.lastIndexOf("/") + 1, mFilePath.lastIndexOf("."));
}

代码示例来源:origin: smuyyh/BookReader

@Override
public void initToolBar() {
  String filePath = Uri.decode(getIntent().getDataString().replace("file://", ""));
  String fileName = filePath.substring(filePath.lastIndexOf("/") + 1, filePath.lastIndexOf("."));
  mCommonToolbar.setTitle(fileName);
  mCommonToolbar.setNavigationIcon(R.drawable.ab_back);
}

代码示例来源:origin: smuyyh/BookReader

@Override
public void initToolBar() {
  chmFilePath = Uri.decode(getIntent().getDataString().replace("file://", ""));
  chmFileName = chmFilePath.substring(chmFilePath.lastIndexOf("/") + 1, chmFilePath.lastIndexOf("."));
  mCommonToolbar.setTitle(chmFileName);
  mCommonToolbar.setNavigationIcon(R.drawable.ab_back);
}

代码示例来源:origin: seven332/EhViewer

@Override
  public File getFileForUri(Uri uri) {
    String path = uri.getEncodedPath();
    final int splitIndex = path.indexOf('/', 1);
    final String tag = Uri.decode(path.substring(1, splitIndex));
    path = Uri.decode(path.substring(splitIndex + 1));
    final File root = mRoots.get(tag);
    if (root == null) {
      throw new IllegalArgumentException("Unable to find configured root for " + uri);
    }
    File file = new File(root, path);
    try {
      file = file.getCanonicalFile();
    } catch (IOException e) {
      throw new IllegalArgumentException("Failed to resolve canonical path for " + file);
    }
    if (!file.getPath().startsWith(root.getPath())) {
      throw new SecurityException("Resolved path jumped beyond configured root");
    }
    return file;
  }
}

代码示例来源:origin: smuyyh/BookReader

@Override
public void initDatas() {
  if (Intent.ACTION_VIEW.equals(getIntent().getAction())) {
    String filePath = Uri.decode(getIntent().getDataString().replace("file://", ""));
    PDFViewPager pdfViewPager = new PDFViewPager(this, filePath);
    llPdfRoot.addView(pdfViewPager);
  }
}

代码示例来源:origin: ankidroid/Anki-Android

/**
 * Percent-escape UTF-8 characters in local image filenames.
 * @param string The string to search for image references and escape the filenames.
 * @return The string with the filenames of any local images percent-escaped as UTF-8.
 */
public String escapeImages(String string, boolean unescape) {
  for (Pattern p : Arrays.asList(fImgRegExpQ, fImgRegExpU)) {
    Matcher m = p.matcher(string);
    // NOTE: python uses the named group 'fname'. Java doesn't have named groups, so we have to determine
    // the index based on which pattern we are using
    int fnameIdx = p.equals(fImgRegExpU) ? 2 : 3;
    while (m.find()) {
      String tag = m.group(0);
      String fname = m.group(fnameIdx);
      if (fRemotePattern.matcher(fname).find()) {
        //dont't do any escaping if remote image
      } else {
        if (unescape) {
          string = string.replace(tag,tag.replace(fname, Uri.decode(fname)));
        } else {
          string = string.replace(tag,tag.replace(fname, Uri.encode(fname, "/")));
        }
      }
    }
  }
  return string;
}

代码示例来源:origin: journeyapps/zxing-android-embedded

name = Uri.decode(name);
    text = "";
  } else {
    name = Uri.decode(name);
    text = query.substring(equ + 1);
    text = text.replace('+', ' '); // Preemptively decode +
    text = Uri.decode(text);
  name = Uri.decode(name);
  if (!map.containsKey(name)) {
    map.put(name, "");
name = Uri.decode(name);
String text = query.substring(equ + 1, amp);
text = text.replace('+', ' '); // Preemptively decode +
text = Uri.decode(text);
if (!map.containsKey(name)) {
  map.put(name, text);

代码示例来源:origin: smuyyh/BookReader

String filePath = Uri.decode(getIntent().getDataString().replace("file://", ""));
String fileName;
if (filePath.lastIndexOf(".") > filePath.lastIndexOf("/")) {

代码示例来源:origin: k9mail/k-9

public static MailTo parse(Uri uri) throws NullPointerException, IllegalArgumentException {
  if (uri == null || uri.toString() == null) {
    throw new NullPointerException("Argument 'uri' must not be null");
  }
  if (!isMailTo(uri)) {
    throw new IllegalArgumentException("Not a mailto scheme");
  }
  String schemaSpecific = uri.getSchemeSpecificPart();
  int end = schemaSpecific.indexOf('?');
  if (end == -1) {
    end = schemaSpecific.length();
  }
  CaseInsensitiveParamWrapper params =
      new CaseInsensitiveParamWrapper(Uri.parse("foo://bar?" + uri.getEncodedQuery()));
  // Extract the recipient's email address from the mailto URI if there's one.
  String recipient = Uri.decode(schemaSpecific.substring(0, end));
  List<String> toList = params.getQueryParameters(TO);
  if (recipient.length() != 0) {
    toList.add(0, recipient);
  }
  List<String> ccList = params.getQueryParameters(CC);
  List<String> bccList = params.getQueryParameters(BCC);
  Address[] toAddresses = toAddressArray(toList);
  Address[] ccAddresses = toAddressArray(ccList);
  Address[] bccAddresses = toAddressArray(bccList);
  String subject = getFirstParameterValue(params, SUBJECT);
  String body = getFirstParameterValue(params, BODY);
  return new MailTo(toAddresses, ccAddresses, bccAddresses, subject, body);
}

代码示例来源:origin: curtis2/SuperVideoPlayer

/**
 * Get the path for the file:/// only
 * 
 * @param uri
 * @return
 */
public static String getPath(String uri) {
  Log.i("FileUtils#getPath(%s)", uri);
  if (TextUtils.isEmpty(uri))
    return null;
  if (uri.startsWith("file://") && uri.length() > 7)
    return Uri.decode(uri.substring(7));
  return Uri.decode(uri);
}

代码示例来源:origin: mattprecious/telescope

@Override public File getFileForUri(Uri uri) {
  String path = uri.getEncodedPath();
  final int splitIndex = path.indexOf('/', 1);
  final String tag = Uri.decode(path.substring(1, splitIndex));
  path = Uri.decode(path.substring(splitIndex + 1));
  final File root = mRoots.get(tag);
  if (root == null) {
   throw new IllegalArgumentException("Unable to find configured root for " + uri);
  }
  File file = new File(root, path);
  try {
   file = file.getCanonicalFile();
  } catch (IOException e) {
   throw new IllegalArgumentException("Failed to resolve canonical path for " + file);
  }
  if (!file.getPath().startsWith(root.getPath())) {
   throw new SecurityException("Resolved path jumped beyond configured root");
  }
  return file;
 }
}

代码示例来源:origin: skjolber/ndef-tools-for-android

final String getDecoded() {
  @SuppressWarnings("StringEquality")
  boolean hasDecoded = decoded != NOT_CACHED;
  return hasDecoded ? decoded : (decoded = decode(encoded));
}

代码示例来源:origin: xugaoxiang/VLCAndroidMultiWindow

public static File URItoFile(String URI) {
  if(URI == null) return null;
  return new File(Uri.decode(URI).replace("file://",""));
}

代码示例来源:origin: gpfduoduo/AirPlay-Receiver-on-Android

public static boolean isNative(String uri) {
  uri = Uri.decode(uri);
  return uri != null && (uri.startsWith("/") || uri.startsWith("content:") || uri.startsWith("file:"));
}

代码示例来源:origin: vpaliy/SoundCloud-API

private void query(){
  if(next_href!=null){
    int index=next_href.indexOf("&q=")+3;
    if(next_href.length()>index){
      int lastIndex=next_href.indexOf("&",index);
      query=next_href.substring(index,lastIndex!=-1?lastIndex:next_href.length());
      query=Uri.decode(query);
    }
  }
}

代码示例来源:origin: konradrenner/kolabnotes-android

@Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
    String decode = Uri.decode(url);
    //really really dirty hack to fix issue 174
    decode = decode.replaceAll("\\+","&plus;");
    return super.shouldOverrideUrlLoading(view, decode);
  }
}

代码示例来源:origin: gpfduoduo/AirPlay-Receiver-on-Android

/**
 * Get the path for the file:/// only
 * 
 * @param uri
 * @return
 */
public static String getPath(String uri) {
  Log.i("FileUtils#getPath(%s)", uri);
  if (StringUtils.isBlank(uri))
    return null;
  if (uri.startsWith("file://") && uri.length() > 7)
    return Uri.decode(uri.substring(7));
  return Uri.decode(uri);
}

代码示例来源:origin: appnexus/mobile-sdk-android

private void open(ArrayList<Pair<String, String>> parameters) {
  String uri = null;
  for (Pair<String, String> bnvp : parameters) {
    if (bnvp.first.equals("uri")) {
      uri = Uri.decode(bnvp.second);
    }
  }
  if (!StringUtil.isEmpty(uri)) {
    this.owner.handleClickUrl(uri);
  }
}

相关文章