Example usage for android.content Intent CATEGORY_BROWSABLE

List of usage examples for android.content Intent CATEGORY_BROWSABLE

Introduction

In this page you can find the example usage for android.content Intent CATEGORY_BROWSABLE.

Prototype

String CATEGORY_BROWSABLE

To view the source code for android.content Intent CATEGORY_BROWSABLE.

Click Source Link

Document

Activities that can be safely invoked from a browser must support this category.

Usage

From source file:Main.java

public static void link(Context context, String url) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    intent.setData(Uri.parse(url));//from  w  ww .j  a  v  a2 s.co  m
    context.startActivity(intent);
}

From source file:Main.java

public static void launchWeb(Context activityContext, String url) {
    //Log.d(TAG, "launchWeb::"+url);
    Intent in = new Intent();
    in.setAction(Intent.ACTION_VIEW);/* w w w.  j  av  a2 s  .c o m*/
    in.addCategory(Intent.CATEGORY_BROWSABLE);
    in.setData(Uri.parse(url));
    activityContext.startActivity(in);
}

From source file:Main.java

/**
 * Open an URL in a message./*from   ww  w . ja va 2s .  c  om*/
 *
 * This is intended to mirror the operation of the original
 * (see android.webkit.CallbackProxy) with one addition of intent flags
 * "FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET".  This improves behavior when sublaunching
 * other apps via embedded URI's.
 *
 * We also use this hook to catch "mailto:" links and handle them locally.
 *
 * @param activity parent activity
 * @param url URL to open
 * @param senderAccountId if the URL is mailto:, we use this account as the sender.
 *        TODO When MessageCompose implements the account selector, this won't be necessary.
 *        Pass {@link Account#NO_ACCOUNT} to use the default account.
 * @return true if the URI has successfully been opened.
 */
public static boolean openUrlInMessage(Activity activity, String url, long senderAccountId) {
    // hijack mailto: uri's and handle locally
    //***
    //if (url != null && url.toLowerCase().startsWith("mailto:")) {
    //    return MessageCompose.actionCompose(activity, url, senderAccountId);
    //}

    // Handle most uri's via intent launch
    boolean result = false;
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    try {
        activity.startActivity(intent);
        result = true;
    } catch (ActivityNotFoundException ex) {
        // No applications can handle it.  Ignore.
    }
    return result;
}

From source file:ng.uavp.ch.ngusbterminal.AboutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.about, container, false);
    ImageView img = (ImageView) view.findViewById(R.id.imageViewNG);
    img.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse("http://ng.uavp.ch"));
            startActivity(intent);//from www . ja v a  2s.  c om
        }
    });

    TextView txt1 = (TextView) view.findViewById(R.id.textView1);
    String versionName = "?";
    try {
        versionName = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(),
                0).versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    txt1.setText(getText(R.string.app_name) + " V" + versionName);

    return view;
}

From source file:fr.hbuyse.accrodestournois.Contact.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_contact);

    getActionBar().setDisplayHomeAsUpEnabled(true);

    em_hb = (TableRow) findViewById(R.id.email_hb);
    gh_hb = (TableRow) findViewById(R.id.github_hb);

    fb = (ImageView) findViewById(R.id.facebook_adt);
    tw = (ImageView) findViewById(R.id.twitter_adt);
    gp = (ImageView) findViewById(R.id.googleplus_adt);
    em = (ImageView) findViewById(R.id.email_adt);
    wb = (ImageView) findViewById(R.id.website_adt);

    em_hb.setOnClickListener(new View.OnClickListener() {
        @Override/* w w  w  .j  av  a2 s . com*/
        public void onClick(View view) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.addCategory(Intent.CATEGORY_BROWSABLE);
            i.setData(Uri.parse(getResources().getString(R.string.dev_mail_addr)));
            startActivity(i);
        }
    });

    gh_hb.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.addCategory(Intent.CATEGORY_BROWSABLE);
            i.setData(Uri.parse(getResources().getString(R.string.dev_github_addr)));
            startActivity(i);
        }
    });

    fb.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.addCategory(Intent.CATEGORY_BROWSABLE);
            try {
                i.setData(Uri.parse(getResources().getString(R.string.facebook_addr)));
                startActivity(i);
            } catch (android.content.ActivityNotFoundException e) {
                i.setData(Uri.parse(getResources().getString(R.string.facebook_addr2)));
                startActivity(i);
            }

        }
    });

    tw.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.addCategory(Intent.CATEGORY_BROWSABLE);
            i.setData(Uri.parse(getResources().getString(R.string.twitter_addr)));
            startActivity(i);
        }
    });

    gp.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.addCategory(Intent.CATEGORY_BROWSABLE);
            i.setData(Uri.parse(getResources().getString(R.string.googleplus_addr)));
            startActivity(i);
        }
    });

    em.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.addCategory(Intent.CATEGORY_BROWSABLE);
            i.setData(Uri.parse(getResources().getString(R.string.email_addr)));
            startActivity(i);
        }
    });

    wb.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.addCategory(Intent.CATEGORY_BROWSABLE);
            i.setData(Uri.parse(getResources().getString(R.string.website_addr)));
            startActivity(i);
        }
    });
}

From source file:DetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);

    detector = new GestureDetector(this, new GalleryGestureDetector());
    listener = new View.OnTouchListener() {

        @Override//from  w  w w . j av  a 2  s .co  m
        public boolean onTouch(View v, MotionEvent event) {
            return detector.onTouchEvent(event);
        }
    };

    ImageIndex = 0;

    detailImage = (ImageView) findViewById(R.id.detail_image);
    detailImage.setOnTouchListener(listener);

    TextView detailName = (TextView) findViewById(R.id.detail_name);
    TextView detailDistance = (TextView) findViewById(R.id.detail_distance);
    TextView detailText = (TextView) findViewById(R.id.detail_text);
    detailText.setMovementMethod(new ScrollingMovementMethod());
    ImageView detailWebLink = (ImageView) findViewById(R.id.detail_web_link);

    int i = MainActivity.currentItem;
    Random n = new Random();
    int m = n.nextInt((600 - 20) + 1) + 20;
    setTitle(getString(R.string.app_name) + " - " + MainData.nameArray[i]);
    detailImage.setImageResource(MainData.detailImageArray[i]);
    detailName.setText(MainData.nameArray[i]);
    detailDistance.setText(String.valueOf(m) + " miles");
    detailText.setText(MainData.detailTextArray[i]);

    detailWebLink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse(MainData.detailWebLink[MainActivity.currentItem]));
            startActivity(intent);
        }
    });
}

From source file:de.sourcestream.movieDB.About.java

/**
 * Fired when clicked on Sourcestream or TMDB logo.
 *
 * @param v the view from which the event has been fired.
 */// w ww. ja v  a 2  s.  c o  m
@Override
public void onClick(View v) {
    //Get url from tag
    if (v.getId() == R.id.aboutSupportMail) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("message/rfc822");
        intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "info@sourcestream.de" });
        intent.putExtra(Intent.EXTRA_SUBJECT, res.getString(R.string.MailSubject));
        intent.putExtra(Intent.EXTRA_TEXT, res.getString(R.string.MailDesc));
        startActivity(Intent.createChooser(intent, res.getString(R.string.MailSend)));
    } else {
        String url = (String) v.getTag();

        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.addCategory(Intent.CATEGORY_BROWSABLE);

        //pass the url to intent data
        intent.setData(Uri.parse(url));

        startActivity(intent);
    }
}

From source file:com.recursionlabs.thecommuter.AboutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_about, container, false);

    mDrawerLayout = (DrawerLayout) rootView.findViewById(R.id.drawer_layout);
    AboutActivity.mDrawerLayout = mDrawerLayout;

    navigationView = (NavigationView) rootView.findViewById(R.id.nav_view);
    navigationView.getMenu().getItem(3).setChecked(true);

    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*from ww w  .  ja  va2s  .c o m*/
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            int id = menuItem.getItemId();
            Intent intent;

            if (id == R.id.nav_favorites) {
                intent = new Intent(getActivity(), FavoritesActivity.class);
                startActivity(intent);
            } else if (id == R.id.nav_home) {
                intent = new Intent(getActivity(), MainActivity.class);
                startActivity(intent);
            } else if (id == R.id.nav_settings) {
                intent = new Intent(getActivity(), SettingsActivity.class);
                startActivity(intent);
            }

            mDrawerLayout.closeDrawers();
            return true;
        }
    });

    TextView international = (TextView) rootView.findViewById(R.id.international_4_0);
    international.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse("https://creativecommons.org/licenses/by-sa/4.0/deed.en"));
            startActivity(intent);
        }
    });

    TextView unported = (TextView) rootView.findViewById(R.id.unported_3_0);
    unported.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse("https://creativecommons.org/licenses/by-sa/3.0/deed.en"));
            startActivity(intent);
        }
    });

    TextView generic_2_5 = (TextView) rootView.findViewById(R.id.generic_2_5);
    generic_2_5.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse("https://creativecommons.org/licenses/by-sa/2.5/deed.en"));
            startActivity(intent);
        }
    });

    TextView generic_2_0 = (TextView) rootView.findViewById(R.id.generic_2_0);
    generic_2_0.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse("https://creativecommons.org/licenses/by-sa/2.0/deed.en"));
            startActivity(intent);
        }
    });

    TextView generic_1_0 = (TextView) rootView.findViewById(R.id.generic_1_0);
    generic_1_0.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse("https://creativecommons.org/licenses/by-sa/1.0/deed.en"));
            startActivity(intent);
        }
    });

    Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
    if (toolbar != null) {
        toolbar.setTitle("About");
        ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
        ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        ((AppCompatActivity) getActivity()).getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_hamburger);
    }

    return rootView;
}

From source file:org.apache.cordova.CordovaUriHelper.java

/**
 * Give the host application a chance to take over the control when a new url
 * is about to be loaded in the current WebView.
 *
 * @param view          The WebView that is initiating the callback.
 * @param url           The url to be loaded.
 * @return              true to override, false for default behavior
 *//*from  w  ww .jav  a2s.  co  m*/
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    // The WebView should support http and https when going on the Internet
    if (url.startsWith("http:") || url.startsWith("https:")) {
        // Check if it's an exec() bridge command message.
        if (NativeToJsMessageQueue.ENABLE_LOCATION_CHANGE_EXEC_MODE
                && url.startsWith(CORDOVA_EXEC_URL_PREFIX)) {
            handleExecUrl(url);
        }
        // We only need to whitelist sites on the Internet! 
        else if (Config.isUrlWhiteListed(url)) {
            return false;
        }
    }
    // Give plugins the chance to handle the url
    else if (this.appView.pluginManager.onOverrideUrlLoading(url)) {

    } else if (url.startsWith("file://") | url.startsWith("data:")) {
        //This directory on WebKit/Blink based webviews contains SQLite databases!
        //DON'T CHANGE THIS UNLESS YOU KNOW WHAT YOU'RE DOING!
        return url.contains("app_webview");
    } else {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setComponent(null);
            intent.setSelector(null);
            this.cordova.getActivity().startActivity(intent);
        } catch (android.content.ActivityNotFoundException e) {
            LOG.e(TAG, "Error loading url " + url, e);
        }
    }
    //Default behaviour should be to load the default intent, let's see what happens! 
    return true;
}

From source file:org.mariotaku.twidere.activity.ImageViewerActivity.java

@Override
public void onClick(final View view) {
    final Uri uri = getIntent().getData();
    switch (view.getId()) {
    case R.id.close: {
        onBackPressed();/*from w  ww . j av  a  2s  . c om*/
        break;
    }
    case R.id.refresh_stop_save: {
        final LoaderManager lm = getSupportLoaderManager();
        if (!mImageLoaded && !lm.hasRunningLoaders()) {
            loadImage(false);
        } else if (!mImageLoaded && lm.hasRunningLoaders()) {
            stopLoading();
        } else if (mImageLoaded) {
            saveImage();
        }
        break;
    }
    case R.id.share: {
        if (uri == null) {
            break;
        }
        final Intent intent = new Intent(Intent.ACTION_SEND);
        if (mImageFile != null && mImageFile.exists()) {
            intent.setType("image/*");
            intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mImageFile));
        } else {
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, uri.toString());
        }
        startActivity(Intent.createChooser(intent, getString(R.string.share)));
        break;
    }
    case R.id.open_in_browser: {
        if (uri == null) {
            break;
        }
        final String scheme = uri.getScheme();
        if ("http".equals(scheme) || "https".equals(scheme)) {
            final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            try {
                startActivity(intent);
            } catch (final ActivityNotFoundException e) {
                // Ignore.
            }
        }
        break;
    }
    }
}