VenomVendor
VenomVendor

Reputation: 15382

How to select browser from my App?

I have an App in which i have an URL, I dont want to load this in WebView, instead i use

Intent i = new Intent(Intent.ACTION_VIEW, 
Uri.parse("http://VenomVendor.blogspot.com/search/label/Android"));
startActivity(i);

I want users to view this site only in specific browser, let's say i want to open this URL only in Firefox. If user has not installed i have to tell him to download Firefox & after downloading i have to load this URL.

Note: My app should not exit unless the user exits.

Upvotes: 0

Views: 249

Answers (1)

Dheeresh Singh
Dheeresh Singh

Reputation: 15701

1- to check package's exits

 

public booleand isPackageExists(String targetPackage){
        List<ApplicationInfo> packages;
        PackageManager pm;
            pm = getPackageManager();        
            packages = pm.getInstalledApplications(0);
            for (ApplicationInfo packageInfo : packages) {
        if(packageInfo.packageName.equals(targetPackage)) return true;
        }        
        return false;
    }

2- use action or ComponentName (package name and class name) to specific browser

 like for default ComponentName arg will be  "com.android.browser", "com.android.browser.BrowserActivity"

 public void onClick(View v) {
             Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
             myWebLink.setComponent(new ComponentName("pkg","cls"));
             myWebLink.setData(Uri.parse("http://google.com"));
             startActivity(myWebLink);
       }

Upvotes: 1

Related Questions