Skip to content

Instantly share code, notes, and snippets.

@t4kemyh4nd
Created July 19, 2021 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t4kemyh4nd/5add2336de85c5f19cebad11b914762d to your computer and use it in GitHub Desktop.
Save t4kemyh4nd/5add2336de85c5f19cebad11b914762d to your computer and use it in GitHub Desktop.
public static Intent parseActivity(Context context, Uri uri) {
if (uri == null || !FeatureConstants.SCHEME.equals(uri.getScheme())) {
return null;
}
String authority = uri.getAuthority();
IDeviceCompat deviceCompat = IApplicationHelper.CC.getInstance().getDeviceCompat();
if ("settings".equals(authority)) {
Intent intent = new Intent(context, deviceCompat.getActivityClass(1));
intent.setData(uri);
intent.setPackage(context.getPackageName());
return intent;
} else if ("web".equals(authority)) {
boolean booleanQueryParameter = uri.getBooleanQueryParameter(FeatureConstants.PARAM_BROWSER_VIEW, false);
String queryParameter = uri.getQueryParameter("url");
if (!booleanQueryParameter || TextUtils.isEmpty(queryParameter)) {
return null;
}
return new Intent("android.intent.action.VIEW", Uri.parse(queryParameter));
} else if (!FeatureConstants.AUTHORITY_OUT_BROWSER.equals(authority)) {
return null;
} else {
Intent intent2 = new Intent("android.intent.action.VIEW", Uri.parse(uri.getQueryParameter("url")));
intent2.setFlags(268435456);
String queryParameter2 = uri.getQueryParameter(FeatureConstants.PARAM_PACKAGE);
if (!TextUtils.isEmpty(queryParameter2)) {
intent2.setPackage(queryParameter2);
}
if (!Utils.isIntentExist(context, intent2)) {
intent2.setPackage(null);
}
return intent2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment