我正在尝试为Facebook建立一个链接,但我完全迷失了:) 你能帮我吗?我从互联网上获得了代码!
代码:
public void addListenerOnButton() {
natilink = (Button) findViewById(R.id.nati);
natilink .setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
try {
String uri = "fb://page/" + natgeo;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
}catch (ActivityNotFoundException ex){
String uri = "http://touch.facebook.com/pages/x/" + natgeo;
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uriMobile));
startActivity(i);
}};
答案 0 :(得分:0)
试试这个。我希望我能帮助你。手机上的Facebook包名为#34; com.facebook.kantana"。复制&粘贴以下内容。
Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage("com.facebook.katana");
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
}
更新
将它放在你的onClick方法中:
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setClassName("com.facebook.kantana,
"com.xxx.your_class_name");//Add your class Name here
startActivity(i);