Java Code Examples for android.net.Uri#decode()

The following examples show how to use android.net.Uri#decode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileProvider.java    From telescope with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: FileProvider.java    From letv with Apache License 2.0 6 votes vote down vote up
public File getFileForUri(Uri uri) {
    String path = uri.getEncodedPath();
    int splitIndex = path.indexOf(47, 1);
    String tag = Uri.decode(path.substring(1, splitIndex));
    path = Uri.decode(path.substring(splitIndex + 1));
    File root = (File) this.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();
        if (file.getPath().startsWith(root.getPath())) {
            return file;
        }
        throw new SecurityException("Resolved path jumped beyond configured root");
    } catch (IOException e) {
        throw new IllegalArgumentException("Failed to resolve canonical path for " + file);
    }
}
 
Example 3
Source File: ReadPDFActivity.java    From fangzhuishushenqi with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 4
Source File: DB.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@TypeConverter
public static String[] toStringArray(String value) {
    if (value == null)
        return new String[0];
    else {
        String[] result = TextUtils.split(value, " ");
        for (int i = 0; i < result.length; i++)
            result[i] = Uri.decode(result[i]);
        return result;
    }
}
 
Example 5
Source File: ANJAMImplementation.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private static void callInternalBrowser(AdWebView webView, Uri uri) {
    String urlParam = uri.getQueryParameter("url");

    if ((webView.getContext() == null)
            || (urlParam == null)
            || (!urlParam.startsWith("http"))) {
        return;
    }

    String url = Uri.decode(urlParam);
    Class<?> activity_clz = AdActivity.getActivityClass();


    Intent intent = new Intent(webView.getContext(), activity_clz);
    intent.putExtra(AdActivity.INTENT_KEY_ACTIVITY_TYPE, AdActivity.ACTIVITY_TYPE_BROWSER);

    WebView browserWebView = new WebView(webView.getContext());
    WebviewUtil.setWebViewSettings(browserWebView);
    BrowserAdActivity.BROWSER_QUEUE.add(browserWebView);
    browserWebView.loadUrl(url);

    try {
        webView.getContext().startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(webView.getContext(),
                R.string.action_cant_be_completed,
                Toast.LENGTH_SHORT).show();
        Clog.w(Clog.baseLogTag, Clog.getString(R.string.adactivity_missing,activity_clz.getName()));
        BrowserAdActivity.BROWSER_QUEUE.remove();
    }
}
 
Example 6
Source File: ReadCHMActivity.java    From BookReader with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 7
Source File: MediaInfoFragment.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    File itemFile = new File(Uri.decode(mItem.getLocation().substring(5)));
    if (!itemFile.canWrite())
        mHandler.obtainMessage(HIDE_DELETE).sendToTarget();
    long length = itemFile.length();
    mHandler.obtainMessage(NEW_SIZE, Long.valueOf(length)).sendToTarget();
    checkSubtitles(itemFile);
}
 
Example 8
Source File: ExportProvider.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public File getFileForUri(Uri uri) {
    String path = uri.getEncodedPath();
    logger.info("getFileForUri({})", path);

    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;
}
 
Example 9
Source File: CommonUtils.java    From Android_framework with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 手机图片path转uri
 */
public static Uri pathToUri(String path){
    Uri uri = null;
    if (path != null) {
        path = Uri.decode(path);
        ContentResolver cr = RootApplication.getInstance().getContentResolver();
        StringBuffer buff = new StringBuffer();
        buff.append("(").append(MediaStore.Images.ImageColumns.DATA)
                .append("=").append("'" + path + "'").append(")");
        Cursor cur = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                new String[] { MediaStore.Images.ImageColumns._ID },
                buff.toString(), null, null);
        int index = 0;
        for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
            index = cur.getColumnIndex(MediaStore.Images.ImageColumns._ID);
            index = cur.getInt(index);
        }
        if (index == 0) {
        } else {
            Uri uri_temp = Uri.parse("content://media/external/images/media/" + index);
            if (uri_temp != null) {
                uri = uri_temp;
            }
        }
    }
    return uri;
}
 
Example 10
Source File: FileUtils.java    From video-player with MIT License 5 votes vote down vote up
/**
 * 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);
}
 
Example 11
Source File: GSIDWebViewActivity.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onComplete(Bundle values) {
    CookieManager cookieManager = CookieManager.getInstance();

    String cookie = cookieManager.getCookie(SeniorUrl.SeniorUrl_SeniorLogin);
    String pubCookie = cookieManager.getCookie(SeniorUrl.SeniorUrl_Public);

    String passPortCookie = cookieManager.getCookie("https://passport.weibo.cn");

    DevLog.printLog("Weibo-CookieStr cookie: ", cookie);
    DevLog.printLog("Weibo-CookieStr pubCookie: ", pubCookie);
    DevLog.printLog("Weibo-CookieStr passPortCookie: ", passPortCookie);

    String uid = "";
    String gsid = "";

    if (!TextUtils.isEmpty(cookie)) {
        String[] cookies = cookie.split("; ");
        for (String string : cookies) {
            String oneLine = Uri.decode(Uri.decode(string));

            if (oneLine.contains("SUB=")) {
                DevLog.printLog("GSID", "" + oneLine);
                gsid = oneLine.split("SUB=")[1];
            }

            if (oneLine.contains("SSOLoginState")) {
                uid = oneLine.split("=")[1];
                DevLog.printLog("GSID-UID", uid);
            }
        }
    }

    if (!TextUtils.isEmpty(uid)) {
        AccountDatabaseManager manager = new AccountDatabaseManager(getApplicationContext());
        manager.updateAccount(AccountTable.ACCOUNT_TABLE, mAccountBean.getUid(), AccountTable.COOKIE, pubCookie);
        manager.updateAccount(AccountTable.ACCOUNT_TABLE, mAccountBean.getUid(), AccountTable.GSID, gsid);
        BeeboApplication.getInstance().updateAccountBean();

        finish();
    } else if (!TextUtils.isEmpty(uid)) {
        Toast.makeText(getApplicationContext(), "请登录昵称是[" + mAccountBean.getUsernick() + "]的微博!", Toast.LENGTH_LONG)
                .show();
        mWebView.loadUrl(SeniorUrl.SeniorUrl_SeniorLogin);
    }
}
 
Example 12
Source File: DocumentHelper.java    From a with GNU General Public License v3.0 4 votes vote down vote up
public static OutputStream getFileOutputSteam(String fileName, String rootPath, String... subDirs) {
    if (!rootPath.startsWith("content://"))
        rootPath = "file://" + Uri.decode(rootPath);
    return DocumentUtil.getFileOutputSteam(MApplication.getInstance(), fileName, rootPath, subDirs);
}
 
Example 13
Source File: DocumentHelper.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
public static OutputStream getFileOutputSteam(String fileName, String rootPath, String... subDirs) {
    if (!rootPath.startsWith("content://"))
        rootPath = "file://" + Uri.decode(rootPath);
    return DocumentUtil.getFileOutputSteam(ContextHolder.getContext(), fileName, rootPath, subDirs);
}
 
Example 14
Source File: BaseBrowserAdapter.java    From VCL-Android with Apache License 2.0 4 votes vote down vote up
public String getName() {
    return Uri.decode(name);
}
 
Example 15
Source File: DocumentHelper.java    From MyBookshelf with GNU General Public License v3.0 4 votes vote down vote up
public static OutputStream getFileOutputSteam(String fileName, String rootPath, String... subDirs) {
    if (!rootPath.startsWith("content://"))
        rootPath = "file://" + Uri.decode(rootPath);
    return DocumentUtil.getFileOutputSteam(MApplication.getInstance(), fileName, rootPath, subDirs);
}
 
Example 16
Source File: WebViewActivity.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public void onComplete(Bundle values) {
        // TODO Auto-generated method stub
        CookieManager cookieManager = CookieManager.getInstance();

        String cookie = cookieManager.getCookie(SeniorUrl.SeniorUrl_SeniorLogin);

//         setWeiboCookie(CookieStr);
        String uid = "";
        String uname = "";
        AccountDatabaseManager manager = new AccountDatabaseManager(getApplicationContext());
        if (true) {
            String[] cookies = cookie.split("; ");
            for (String string : cookies) {
                // Log.d("Weibo-Cookie", "" + Uri.decode(Uri.decode(string)));
                String oneLine = Uri.decode(Uri.decode(string));
                String uidtmp = PatternUtils.macthUID(oneLine);
                if (!TextUtils.isEmpty(uidtmp)) {
                    uid = uidtmp;
                }
                uname = PatternUtils.macthUname(oneLine);
                // Log.d("Weibo-Cookie", "" + uid);
                // Log.d("Weibo-Cookie", "" + uname);
                // Log.d("Weibo-Cookie", "in db : uid = " + mAccountBean.getUid());

                if (!TextUtils.isEmpty(uname)) {
                    manager.updateAccount(AccountTable.ACCOUNT_TABLE, uid, AccountTable.USER_NAME, uname);
                }
            }
        }

        Log.d("Weibo-Cookie", "after for : " + uid);
        if (uid.equals(mAccountBean.getUid())) {
            manager.updateAccount(AccountTable.ACCOUNT_TABLE, uid, AccountTable.COOKIE, cookie);
            cookieManager.removeSessionCookie();
            finish();
        } else if (!TextUtils.isEmpty(uid)) {
            Toast.makeText(getApplicationContext(), "请登录昵称是[" + mAccountBean.getUsernick() + "]的微博!", Toast.LENGTH_LONG)
                    .show();
            mWebView.loadUrl(SeniorUrl.SeniorUrl_SeniorLogin);
        }
    }
 
Example 17
Source File: DocumentHelper.java    From a with GNU General Public License v3.0 4 votes vote down vote up
public static boolean deleteFile(String fileName, String rootPath, String... subDirs) {
    if (!rootPath.startsWith("content://"))
        rootPath = "file://" + Uri.decode(rootPath);
    return DocumentUtil.deleteFile(MApplication.getInstance(), fileName, rootPath, subDirs);
}
 
Example 18
Source File: DocumentHelper.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
public static InputStream getFileInputSteam(String fileName, String rootPath, String... subDirs) {
    if (!rootPath.startsWith("content://"))
        rootPath = "file://" + Uri.decode(rootPath);
    return DocumentUtil.getFileInputSteam(ContextHolder.getContext(), fileName, rootPath, subDirs);
}
 
Example 19
Source File: JSWebViewActivity.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public void onComplete(Bundle values) {
        // TODO Auto-generated method stub
        CookieManager cookieManager = CookieManager.getInstance();

        String cookie = cookieManager.getCookie(url);

//         setWeiboCookie(CookieStr);
        String uid = "";
        String uname = "";
        AccountDatabaseManager manager = new AccountDatabaseManager(getApplicationContext());
        if (true) {
            String[] cookies = cookie.split("; ");
            for (String string : cookies) {
                // Log.d("Weibo-Cookie", "" + Uri.decode(Uri.decode(string)));
                String oneLine = Uri.decode(Uri.decode(string));
                String uidtmp = PatternUtils.macthUID(oneLine);
                if (!TextUtils.isEmpty(uidtmp)) {
                    uid = uidtmp;
                }
                uname = PatternUtils.macthUname(oneLine);
                // Log.d("Weibo-Cookie", "" + uid);
                // Log.d("Weibo-Cookie", "" + uname);
                // Log.d("Weibo-Cookie", "in db : uid = " + mAccountBean.getUid());

                if (!TextUtils.isEmpty(uname)) {
                    manager.updateAccount(AccountTable.ACCOUNT_TABLE, uid, AccountTable.USER_NAME, uname);
                }
            }
        }

        Log.d("Weibo-Cookie", "after for : " + uid);
        if (uid.equals(mAccountBean.getUid())) {
            manager.updateAccount(AccountTable.ACCOUNT_TABLE, uid, AccountTable.COOKIE, cookie);
            BeeboApplication.getInstance().updateAccountBean();
            finish();
        } else if (!TextUtils.isEmpty(uid)) {
            Toast.makeText(getApplicationContext(), "请登录昵称是[" + mAccountBean.getUsernick() + "]的微博!", Toast.LENGTH_LONG)
                    .show();
            mWebView.loadUrl(url);
        }
    }
 
Example 20
Source File: Multimap.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
public String decode(String s) {
    return Uri.decode(s);
}