1

I want to fix my Android app up to show 12s clips of videos with the ability to click on a button to go to the webpage built for each specific clip. Then, revert back to the Starplayer (monoboom.co) app.

My question is...how to specify Firefox as the browser to use. Perhaps Explorer or Chrome.

Then there will be a Flash video and lots of fun stuff related to each specific preview, but that's beside the point.

When a jpeg sprite sheet containing 144 images at 12fps and a button is there to see more, then retreat, (and a "Next!" button, of course) how do I specify the browser?

2 Answers2

1

In my opinion, it is better to let the user select which browser to use when opening a webpage or a link.

You can broadcast an intent(with the link that you want it to go to) like so:

String url = "";//your url
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);

Sources: Link1, Link2

Answering your question though, I think it is possible. I did some quick reasearch and I saw this answer. This answer is shorter but might fullfill your needs. Basically, you will create an intent like so:

Intent intent = getPackageManager()
    .getLaunchIntentForPackage("browser.package.name");
String url = "";//your url
intent.setData(Uri.parse(url));
startActivity(intent);

For the package names, firefox package name is:

org.mozilla.firefox

I got this from their Google Play page

Google Chrome's package name is:

com.android.chrome

Also from their Google Play page

Bonus: Opera Mini :D

com.opera.mini.android

From their Google Play page

For the default android Browser:

com.google.android.browser or com.android.browser

I got this from this answer.

Now before launching your intent, we must do a little checking if the browser is installed. We can do this like so: (I based this on from here too)

public void launchABrowserForUrl(String url) {
    PackageManager packageManager = getPackageManager();

    // Might be better declared as constants somewhere safer,
    // But for the sake of simplicty, declared here
    String[] browserPackageNames = {
        "org.mozilla.firefox",
        "com.android.chrome",
        "com.google.android.browser",
        "com.android.browser"
    }

    for (int i = 0; i < browserPackageNames.length; i++) {
        Intent intent = getPackageManager()
            .getLaunchIntentForPackage(browserPackageNames[i]);

        List<ResolveInfo> appsThatCanLaunchThisIntent = packageManager
            .queryIntentActivities(intent, 0);

        if (appsThatCanLaunchThisIntent.size() > 0) {
            intent.setData(Uri.parse(url));
            startActivity(intent);

            return;
        }
    }

    // Code reached here, meaning for some reason no browser was detected
    // Pop an error message or something
}
Community
  • 1
  • 1
Keale
  • 3,924
  • 3
  • 29
  • 46
  • Thank you so much for the information, I'll see what I can get to work, but I definitely need to reduce resources to make it quicker. – Darrin Skonieczny Oct 28 '14 at 21:07
  • Happy I could help. If you need clarifications/explanation feel free to comment again. Welcome to StackOverflow btw :) – Keale Oct 28 '14 at 23:28
  • Thank you for the welcome...I have too many clarifications etc. to ask, so I'd sum it up with one question... "What's the best way to go about this?": I just want to put animations on the ""smartphone because that's what everybody uses today, with music and basically focus on that rather than get involved with gaming, and keep a simple program that could be developed in other directions using OpenGL. I like the idea of animated music videos because it's the right sized projects. I'll share code and anything to get it to work. I've got a basic start that works but I'm new to Java. – Darrin Skonieczny Oct 31 '14 at 19:04
  • I'm stuck in a loop right now using your code works in one spot if it's static but then can't use this in a static...ugh! – Darrin Skonieczny Oct 31 '14 at 19:28
  • So in this answer I answered your question _how to specify Firefox as the browser to use? Perhaps Explorer or Chrome?_ Your follow up comment about being stuck in a loop and the static static stuff, can you elaborate on that? I will edit and explain in my answer to help you understand. – Keale Oct 31 '14 at 22:34
  • Now you also have another question, _What's the best way to go about this?_ If I will answer this question in my answer, it will be off topic because the basic question that brought me here is the __Link to web with specific browser__ question. This is how _this site_ works, by keeping the Questions and Answers on topic. Maybe you can ask another question here on StackOverflow? But be careful! It might be closed because it is too broad or off topic. (It might generate discussions which is not good for this site.) – Keale Oct 31 '14 at 22:42
  • @DarrinSkonieczny My advice though is you discuss it (the best way to go about your app) with your friends/colleagues which are smartphone users. Ask them what they like in an app, what amazes them, what piques their interest, etc. Also consider your skill, the cost, the time it will take etc. As you can see there are many factors to consider here. Btw thanks for the feedback :) – Keale Oct 31 '14 at 22:50
  • I don't have any friends/colleagues, and I know this site is set up to answer specific questions so I'll back off for a while. Thank you for the help! The code will be on monoboom.co and the idea is to have a basic program to put animation on the smartphone...that's all! ...and sound. ...and a way to generate revenue. – Darrin Skonieczny Nov 03 '14 at 15:54
  • The app is called starplayer and the code will now be on flownuts.com/starplayer/ once I figure that out. You can look at flownuts.com/riffs/ (and listen too). I never fixed up the content of the app, but it shows its purpose. Thanks, I should have posted it a long time ago... – Darrin Skonieczny Apr 19 '22 at 05:11
0

This answers your question.

Key/Relevant information:

To do this using opera mini as an example browser to open:

String packageName = "com.opera.mini.android";
String className = "com.opera.mini.android.Browser";
Intent internetIntent = new Intent(Intent.ACTION_VIEW);
internetIntent.addCategory(Intent.CATEGORY_LAUNCHER);
internetIntent.setClassName(packageName, className);
startActivity(internetIntent);

For other browsers, you can find the package and class name by doing the following:

  • connect android phone to pc
  • open Android Logcat
  • launch the browser from the mobile phone

In Android Logcat, you will see something like this:

07-22 14:06:14.662: INFO/ActivityManager(148): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.opera.mini.android/.Browser }

The class name will be shown in the 'cmp' attribute: cmp=com.opera.mini.android/.Browser

In this case, the package name is com.opera.mini.android and the class name is com.opera.mini.android.Browser.

Example I (Karma Hunter) wrote of the activity's class if you are opening it by use of a button:

package com.company.name;

import android.view.View;
import android.view.View.OnClickListener;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;


public class ActivityName extends Activity {

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        openOpera();
    }

    public void openOpera() {

        final Context context = this;

        button = (Button) findViewById(R.id.buttonid);

        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View argument1) {

                String packageName = "com.opera.mini.android";
                String className = "com.opera.mini.android.Browser";
                Intent internetIntent = new Intent(Intent.ACTION_VIEW);
                internetIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                internetIntent.setClassName(packageName, className);
                startActivity(internetIntent);   

            }

        });

    }
Community
  • 1
  • 1
Karma Hunter
  • 391
  • 2
  • 9