Java 尝试/捕获运行facebook应用程序
我有两个链接。。一是如果我有facebook应用程序,它会在上面运行;二是如果我没有facebook应用程序,它会在浏览器上运行 代码如下:Java 尝试/捕获运行facebook应用程序,java,android,eclipse,facebook,Java,Android,Eclipse,Facebook,我有两个链接。。一是如果我有facebook应用程序,它会在上面运行;二是如果我没有facebook应用程序,它会在浏览器上运行 代码如下: try { String natgeo = "natgeo"; String uri = "fb://Page/" + natgeo; Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(ur
try {
String natgeo = "natgeo";
String uri = "fb://Page/" + natgeo;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
}
catch (ActivityNotFoundException ex){
String natgeo = "natgeo";
String uri = "https://www.facebook.com/" + natgeo;
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);
}
现在两个运行正常,但一个运行不正常,它在我的帐户上运行facebook应用程序,我如何使它在facebook应用程序上运行
编辑
doclink.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(!uri.contains("https://www.facebook.com/")) {
String natgeo = "natgeo";
String uri = "fb://Page/" + natgeo;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
}
else{
String natgeo = "natgeo";
String uri = "https://www.facebook.com/" + natgeo;
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);
}
};
重新编辑
这是一种错误的看法谢谢!有这样的示例吗?非常感谢,我稍后会尝试一下:我使用了代码,希望没有问题,但是}和/或..中有一个错误。。我试了很多,但都没用。。代码已编辑。对不起,我无法理解错误。请您解释一下好吗?代码已再次编辑,那里有错误,您能告诉我是什么吗?
package com.example.a;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
Button dadclink;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton() {
dadclink = (Button) findViewById(R.id.dadclink);
dadclink.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(!uri.contains("https://www.facebook.com/")) {
String natgeo = "natgeo";
String uri = "fb://Page/" + natgeo;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
}
else{
String natgeo = "natgeo";
String uri = "https://www.facebook.com/" + natgeo;
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);
}
)};
}
}
if(!uri.contains("https://www.facebook.com/")) {
String natgeo = "natgeo";
String uri = "fb://Page/" + natgeo;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
}
else{
String natgeo = "natgeo";
String uri = "https://www.facebook.com/" + natgeo;
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);
}