0
我正在製作一個按鈕,當我點擊它時,它直接從瀏覽器中獲取我的東西,我希望它可以轉到instagram應用程序,如果它不在我的手機,它應該去瀏覽器。Instagram去瀏覽器
我嘗試了兩種,兩者都帶我直接在瀏覽器
第一碼:
inslink.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
try {
Uri uri = Uri.parse("http://instagram.com/natgeo");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
catch (Exception e) {
Uri uri = Uri.parse("http://instagram.com/natgeo");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
}
});
第二個代碼:
inslink.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (uri.contains("https://i.instagram.com/")) {
String natgeo = "natgeo";
String uri = "instagram://Page/" + natgeo;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
} else {
String natgeo = "natgeo";
String uri = "https://i.instagram.com/" + natgeo;
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);
}
}
});