Android open URL onclick certain button
Button rate = (Button)findViewById(R.id.rate);
rate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i2=new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=yourpackagename"));
startActivity(i2);
}
});
// Enter package name of application in place of yourpackagename
In my signin.xml
file I put this code:
<Button
android:id="@+id/privacypolicylink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginBottom="50dp"
android:background="@android:color/transparent"
android:onClick="performSingUpMethod"
android:text="Política de Privacidad"
android:textColor="#A9A9A9"
android:textSize="15dp"
android:textStyle="bold" />
In my signin.java
file I used this:
findViewById(R.id.privacypolicylink).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String url = "https://example.net/privacy_policy";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
It works for me. It displays a text in the grey color that I want it. The text is underlined and it is a link. The is the way it looks:
When I click on it, I see this:
Then I can open the link using a web browser on the phone and everything works correctly the way I needed it.
findViewById(R.id.ratebutton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String url = "market://details?id=<package_name>";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});