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

The following examples show how to use android.net.Uri#getQueryParameter() . 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: RequestHandler.java    From AndroidDemo with MIT License 6 votes vote down vote up
private String updateTableDataAndGetResponse(String route) {
    UpdateRowResponse response;
    try {
        Uri uri = Uri.parse(URLDecoder.decode(route, "UTF-8"));
        String tableName = uri.getQueryParameter("tableName");
        String updatedData = uri.getQueryParameter("updatedData");
        List<RowDataRequest> rowDataRequests = mGson.fromJson(updatedData, new TypeToken<List<RowDataRequest>>() {
        }.getType());
        if (Constants.APP_SHARED_PREFERENCES.equals(mSelectedDatabase)) {
            response = PrefHelper.updateRow(mContext, tableName, rowDataRequests);
        } else {
            response = DatabaseHelper.updateRow(mDatabase, tableName, rowDataRequests);
        }
        return mGson.toJson(response);
    } catch (Exception e) {
        e.printStackTrace();
        response = new UpdateRowResponse();
        response.isSuccessful = false;
        return mGson.toJson(response);
    }
}
 
Example 2
Source File: RegistrationActivity.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    if(Intent.ACTION_VIEW.equals(intent.getAction())) {
        Uri uri = intent.getData();
        String path = uri.getPath();
        if(!(path.startsWith("/"+BuildConfig.APPLICATION_ID)||path.startsWith("/auth"))
         || System.currentTimeMillis()-oauth2Requested > 3*60*60*1000) {
            return; // timeout after some hours or a request belonging to a bad path.
        }

        // back in business after we passed control to the browser in (**)
        String code = uri.getQueryParameter("code");
        if(!TextUtils.isEmpty(code)) {
            passwordInput.setText(code);
            authMethod.setSelection(1/*OAuth2*/);
            onLogin();
        }
    }
}
 
Example 3
Source File: IntentUtils.java    From Shield with MIT License 6 votes vote down vote up
public static byte getByteParam(String name, byte defaultValue, Fragment fragment) {
    if (fragment.getArguments() != null && fragment.getArguments().containsKey(name)) {
        return fragment.getArguments().getByte(name);
    }

    Intent i = fragment.getActivity().getIntent();
    try {
        Uri uri = i.getData();
        if (uri != null) {
            String val = uri.getQueryParameter(name);
            if (!TextUtils.isEmpty(val))
                return Byte.parseByte(val);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return i.getByteExtra(name, defaultValue);
}
 
Example 4
Source File: StartActivityUri.java    From jpHolo with MIT License 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void onCreate(final Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	super.init();
	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
		if ( 0 != ( getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE ) ) {
			WebView.setWebContentsDebuggingEnabled(true);
		}
	}
	final SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
	final SharedPreferences.Editor editor = settings.edit();
	final Uri data = getIntent().getData();
	// final String scheme = data.getScheme(); // Not needed
	// final String host = data.getHost(); // Not needed
	// final String path = data.getPath(); // Not needed
	final String message = data.getQueryParameter("message");
	editor.putString("UriMessage", message);
	editor.commit();
	if (checkScreenSize().equals("large") || checkScreenSize().equals("xlarge")) {
		initiateApp("tablet");
	} else {
		initiateApp("smartphone");
	}
}
 
Example 5
Source File: RequestHandler.java    From Android-Debug-Database with Apache License 2.0 6 votes vote down vote up
private String deleteTableDataAndGetResponse(String route) {
    UpdateRowResponse response;
    try {
        Uri uri = Uri.parse(URLDecoder.decode(route, "UTF-8"));
        String tableName = uri.getQueryParameter("tableName");
        String updatedData = uri.getQueryParameter("deleteData");
        List<RowDataRequest> rowDataRequests = mGson.fromJson(updatedData, new TypeToken<List<RowDataRequest>>() {
        }.getType());
        if (Constants.APP_SHARED_PREFERENCES.equals(mSelectedDatabase)) {
            response = PrefHelper.deleteRow(mContext, tableName, rowDataRequests);
        } else {
            response = DatabaseHelper.deleteRow(sqLiteDB, tableName, rowDataRequests);
        }
        return mGson.toJson(response);
    } catch (Exception e) {
        e.printStackTrace();
        response = new UpdateRowResponse();
        response.isSuccessful = false;
        return mGson.toJson(response);
    }
}
 
Example 6
Source File: LoginActivity.java    From open with GNU General Public License v3.0 6 votes vote down vote up
private void setAccessToken(Intent intent) {
    Uri uri = intent.getData();
    verifier = new Verifier(uri.getQueryParameter(OSM_VERIFIER_KEY));
    (new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            try {
                app.setAccessToken(app.getOsmOauthService()
                        .getAccessToken(requestToken, verifier));
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "Unable to log in", Toast.LENGTH_LONG).show();
            }

            return null;
        }
    }).execute();
}
 
Example 7
Source File: ServerUrl.java    From sa-sdk-android with Apache License 2.0 6 votes vote down vote up
public ServerUrl(String url) {
    this.url = url;
    if (!TextUtils.isEmpty(url)) {
        Uri uri = Uri.parse(url);
        try {
            host = uri.getHost();
            token = uri.getQueryParameter("token");
            project = uri.getQueryParameter("project");
        } catch (Exception e) {
            com.sensorsdata.analytics.android.sdk.SALog.printStackTrace(e);
        } finally {
            if (TextUtils.isEmpty(host)) {
                host = "";
            }
            if (TextUtils.isEmpty(project)) {
                project = "default";
            }
            if (TextUtils.isEmpty(token)) {
                token = "";
            }
        }
    }
}
 
Example 8
Source File: ToastWidget.java    From rexxar-android with MIT License 6 votes vote down vote up
@Override
public boolean handle(WebView view, String url) {
    if (TextUtils.isEmpty(url)) {
        return false;
    }
    Uri uri = Uri.parse(url);
    if (TextUtils.equals(uri.getPath(), getPath())) {
        String message = Uri.decode(uri.getQueryParameter(KEY_MESSAGE));
        String level = uri.getQueryParameter(KEY_LEVEL);
        Toast.makeText(view.getContext(), message, Toast.LENGTH_LONG).show();
        LogUtils.i(TAG,
                String.format("handle toast success, message = %1$s ", message));
        return true;
    }
    return false;
}
 
Example 9
Source File: RequestHandler.java    From AndroidDemo with MIT License 6 votes vote down vote up
private String updateTableDataAndGetResponse(String route) {
    UpdateRowResponse response;
    try {
        Uri uri = Uri.parse(URLDecoder.decode(route, "UTF-8"));
        String tableName = uri.getQueryParameter("tableName");
        String updatedData = uri.getQueryParameter("updatedData");
        List<RowDataRequest> rowDataRequests = mGson.fromJson(updatedData, new TypeToken<List<RowDataRequest>>() {
        }.getType());
        if (Constants.APP_SHARED_PREFERENCES.equals(mSelectedDatabase)) {
            response = PrefHelper.updateRow(mContext, tableName, rowDataRequests);
        } else {
            response = DatabaseHelper.updateRow(mDatabase, tableName, rowDataRequests);
        }
        return mGson.toJson(response);
    } catch (Exception e) {
        e.printStackTrace();
        response = new UpdateRowResponse();
        response.isSuccessful = false;
        return mGson.toJson(response);
    }
}
 
Example 10
Source File: WeatherContract.java    From Advanced_Android_Development with Apache License 2.0 5 votes vote down vote up
public static long getStartDateFromUri(Uri uri) {
    String dateString = uri.getQueryParameter(COLUMN_DATE);
    if (null != dateString && dateString.length() > 0)
        return Long.parseLong(dateString);
    else
        return 0;
}
 
Example 11
Source File: LinkRouterActivity.java    From blog-app-android with MIT License 5 votes vote down vote up
private void openAuthor(Uri data) {
  String remoteId = data.getQueryParameter("remote_id");

  if (remoteId != null) {
    remoteId = LinkGenerator.decode(remoteId);
    startActivity(new Intent(this, PostListActivity.class)
        .putExtra(Intents.EXTRA_REMOTE_ID, remoteId));
  }
}
 
Example 12
Source File: DispatcherActivity.java    From JIMU with Apache License 2.0 5 votes vote down vote up
@Override
protected Uri transferUri(Uri uri) {
    String target = uri.getQueryParameter("target");
    if (!TextUtils.isEmpty(target))
        return Uri.parse("ddcompo://" + target);
    return uri;
}
 
Example 13
Source File: AuthorizationException.java    From AppAuth-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an exception from an OAuth redirect URI that describes an authorization failure.
 */
public static AuthorizationException fromOAuthRedirect(
        @NonNull Uri redirectUri) {
    String error = redirectUri.getQueryParameter(PARAM_ERROR);
    String errorDescription = redirectUri.getQueryParameter(PARAM_ERROR_DESCRIPTION);
    String errorUri = redirectUri.getQueryParameter(PARAM_ERROR_URI);
    AuthorizationException base = AuthorizationRequestErrors.byString(error);
    return new AuthorizationException(
            base.type,
            base.code,
            error,
            errorDescription != null ? errorDescription : base.errorDescription,
            errorUri != null ? Uri.parse(errorUri) : base.errorUri,
            null);
}
 
Example 14
Source File: EDSLocationBase.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
public static Location getContainerLocationFromUri(Uri locationUri, LocationsManagerBase lm) throws Exception
{
	String uriString = locationUri.getQueryParameter(LOCATION_URI_PARAM);
	if (uriString == null)
		//maybe it's a legacy container
		uriString = locationUri.getQueryParameter("container_location");
	return lm.getLocation(Uri.parse(uriString));
}
 
Example 15
Source File: MainActivity.java    From MCPELauncher with Apache License 2.0 5 votes vote down vote up
protected void loginLaunchCallback(Uri launchUri) {
	loginDialog.dismiss();
	String session = launchUri.getQueryParameter("sessionId");
	if (session == null)
		return;
	String profileName = launchUri.getQueryParameter("profileName");
	String refreshToken = launchUri.getQueryParameter("identity");
	String accessToken = launchUri.getQueryParameter("accessToken");
	String clientToken = launchUri.getQueryParameter("clientToken");
	String profileUuid = launchUri.getQueryParameter("profileUuid");
	nativeLoginData(accessToken, clientToken, profileUuid, profileName);
}
 
Example 16
Source File: ImageManager.java    From droidddle with Apache License 2.0 5 votes vote down vote up
public static IImageList makeImageList(ContentResolver cr, Uri uri, int sort) {
    String uriString = (uri != null) ? uri.toString() : "";

    if (uriString.startsWith("content://media/external/video")) {
        return makeImageList(cr, DataLocation.EXTERNAL, INCLUDE_VIDEOS, sort, null);
    } else if (isSingleImageMode(uriString)) {
        return makeSingleImageList(cr, uri);
    } else {
        String bucketId = uri.getQueryParameter("bucketId");
        return makeImageList(cr, DataLocation.ALL, INCLUDE_IMAGES, sort, bucketId);
    }
}
 
Example 17
Source File: NotificationImageProvider.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Nullable
@Override
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException {
	if (!"r".equals(mode)) {
		throw new SecurityException("Can only open files for read");
	}
	if (matcher.match(uri) == 1) {
		List<String> path = uri.getPathSegments();
		int account = Integer.parseInt(path.get(1));
		String name = path.get(2);
		String finalPath = uri.getQueryParameter("final_path");
		String fallbackPath = uri.getQueryParameter("fallback");
		File finalFile = new File(finalPath);
		ApplicationLoader.postInitApplication();
		if (AndroidUtilities.isInternalUri(Uri.fromFile(finalFile))) {
			throw new SecurityException("trying to read internal file");
		}
		if (finalFile.exists()) {
			return ParcelFileDescriptor.open(finalFile, ParcelFileDescriptor.MODE_READ_ONLY);
		} else {
			Long _startTime = fileStartTimes.get(name);
			long startTime = _startTime != null ? _startTime : System.currentTimeMillis();
			if (_startTime == null) {
				fileStartTimes.put(name, startTime);
			}
			while (!finalFile.exists()) {
				if (System.currentTimeMillis() - startTime >= 3000) {
					if (BuildVars.LOGS_ENABLED) {
						FileLog.w("Waiting for " + name + " to download timed out");
					}
					if (TextUtils.isEmpty(fallbackPath)) {
						throw new FileNotFoundException("Download timed out");
					}
					File file = new File(fallbackPath);
					if (AndroidUtilities.isInternalUri(Uri.fromFile(file))) {
						throw new SecurityException("trying to read internal file");
					}
					return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
				}
				synchronized (sync) {
					waitingForFiles.add(name);
					try {
						sync.wait(1000);
					} catch (InterruptedException ignore) {
					}
				}
			}
			if (AndroidUtilities.isInternalUri(Uri.fromFile(finalFile))) {
				throw new SecurityException("trying to read internal file");
			}
			return ParcelFileDescriptor.open(finalFile, ParcelFileDescriptor.MODE_READ_ONLY);
		}
	}
	throw new FileNotFoundException("Invalid URI");
}
 
Example 18
Source File: AndroidUtilities.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public static boolean handleProxyIntent(Activity activity, Intent intent) {
    if (intent == null) {
        return false;
    }
    try {
        if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) {
            return false;
        }
        Uri data = intent.getData();
        if (data != null) {
            String user = null;
            String password = null;
            String port = null;
            String address = null;
            String secret = null;
            String scheme = data.getScheme();
            if (scheme != null) {
                if ((scheme.equals("http") || scheme.equals("https"))) {
                    String host = data.getHost().toLowerCase();
                    if (host.equals("telegram.me") || host.equals("t.me") || host.equals("telegram.dog")) {
                        String path = data.getPath();
                        if (path != null) {
                            if (path.startsWith("/socks") || path.startsWith("/proxy")) {
                                address = data.getQueryParameter("server");
                                port = data.getQueryParameter("port");
                                user = data.getQueryParameter("user");
                                password = data.getQueryParameter("pass");
                                secret = data.getQueryParameter("secret");
                            }
                        }
                    }
                } else if (scheme.equals("tg")) {
                    String url = data.toString();
                    if (url.startsWith("tg:proxy") || url.startsWith("tg://proxy") || url.startsWith("tg:socks") || url.startsWith("tg://socks")) {
                        url = url.replace("tg:proxy", "tg://telegram.org").replace("tg://proxy", "tg://telegram.org").replace("tg://socks", "tg://telegram.org").replace("tg:socks", "tg://telegram.org");
                        data = Uri.parse(url);
                        address = data.getQueryParameter("server");
                        port = data.getQueryParameter("port");
                        user = data.getQueryParameter("user");
                        password = data.getQueryParameter("pass");
                        secret = data.getQueryParameter("secret");
                    }
                }
            }
            if (!TextUtils.isEmpty(address) && !TextUtils.isEmpty(port)) {
                if (user == null) {
                    user = "";
                }
                if (password == null) {
                    password = "";
                }
                if (secret == null) {
                    secret = "";
                }
                showProxyAlert(activity, address, port, user, password, secret);
                return true;
            }
        }
    } catch (Exception ignore) {

    }
    return false;
}
 
Example 19
Source File: ImageLoader.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public ArtworkLoadTask(CacheImage cacheImage) {
    this.cacheImage = cacheImage;
    Uri uri = Uri.parse(cacheImage.imageLocation.path);
    small = uri.getQueryParameter("s") != null;
}
 
Example 20
Source File: TrayContentProvider.java    From tray with Apache License 2.0 2 votes vote down vote up
/**
 * checks the uri for the backup param. default is that
 *
 * @param uri contentUri
 * @return default true or false for {@code /the/uri&backup=false}
 */
boolean shouldBackup(@NonNull final Uri uri) {
    final String backup = uri.getQueryParameter("backup");
    return !"false".equals(backup);
}