Tuesday, 8 April 2014

How to send URL to opposite Browsers when startActivity with ResolveInfo / ComponentName?

I'm doing an App that acts like a Browser though we wish to grant a user
to call his "second" comparison Browser with a symbol from my
Browser.Because of that, my App is a Browser, we can't call a common
ACTION_VIEW Intent, if we did that my possess App will seem on a
chooser.So, we finished a Preferences Screen that grant we to set your
comparison browser. To fill a ListPreference with a accessible Browsers we
use something like that: Uri uri = Uri.parse("http://google.com");
Intent vigilant = new Intent(Intent.ACTION_VIEW, uri); List
allActivities = ctx.getPackageManager().queryIntentActivities(intent,
0);Loop a list and build a preference, we store on SharedPreferences a
package name for after use: ((ActivityInfo)
ri.activityInfo).packageNameWhen user daub a "open my comparison browser"
symbol we plead a Browser Activity like that (I loop again by ResolveInfo
since we don't store a challenging form like an ActivityInfo:Uri uri =
Uri.parse("http://google.com");Intent vigilant = new
Intent(Intent.ACTION_VIEW, uri);List allActivities =
mContext.getPackageManager().queryIntentActivities(intent, 0);ActivityInfo
activity = null;for (ResolveInfo ri : allActivities) { String
browserAction = ((ActivityInfo) ri.activityInfo).packageName; if
(sharedPrefs.getString(Constants.KEY_PREFERRED_BROWSER,"").equals(browserAction))
{ activity = ri.activityInfo; break; } } if
(activity != null) { Log.e(TAG,finalUrl); ComponentName name = new
ComponentName(activity.applicationInfo.packageName, activity.name);
Intent i=new Intent(Intent.ACTION_MAIN, Uri.parse(finalUrl)); // TRY 1,
set URL on Intent constructor
i.putExtra(Intent.EXTRA_TEXT,Uri.parse(finalUrl)); // Try 2, put an EXTRA
with a URL :P i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); i.setComponent(name);
i.setData(Uri.parse(finalUrl)); // Try 3, set URL as Intent Data
startActivity(i);}Well... as we can see we attempted many things... I'm
contrast on a Genymotion simulator with Android default browser, Chrome
and Firefox, and wholly Chrome is loading a URL correctly.Do we know how
can we set a URL to a vigilant justly for any case? Could we infer how to
do it, for example, when user is selecting his comparison Browser in my
Preferences Screen? Maybe an easier approach? 0:-)Thank we unequivocally
much.

No comments:

Post a Comment