ekawas ekawas - 9 months ago 26
Android Question

How to launch browser when a preference is selected

I am creating a preference menu and would like to launch a browser (with a specific url) when a particular preference is clicked on. I know this can be done, but I cant seem to get it to work right now.

Any ideas?

Thanks

######SOLUTION

So after my brain fart disappeared, this is what i did:

getPreferenceManager()
.findPreference("my_preference_key")
.setOnPreferenceClickListener(
new Preferences.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://some_url_here"));
startActivity(intent);
return true;
}
});

Answer Source
getPreferenceManager()
   .findPreference("my_preference_key")
   .setOnPreferenceClickListener(
      new Preferences.OnPreferenceClickListener() {
    @Override
    public boolean onPreferenceClick(Preference preference) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("http://some_url_here"));
        startActivity(intent);
        return true;
    }
});

enter code here