[英]facebook opening on a browser not on facebook App
I'm trying to make facebook for "someone" else opens on application, not on a browser, for example National Geography https://www.facebook.com/natgeo 我正在尝试使Facebook成为“某人”,否则将在应用程序上打开,而不是在浏览器上打开,例如National Geography https://www.facebook.com/natgeo
Here is the code I have: 这是我的代码:
ddc.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/natgeo"));
startActivity(browserIntent);
}
});
I found one on stackoverflow and I tried it and it has errors, here is the code: 我在stackoverflow上找到了一个,并尝试了它,但出现了错误,这是代码:
try {
//try to open page in facebook native app.
String uri = "fb://page/" + natgeo; //Custom URL
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
}
catch (ActivityNotFoundException ex){
//facebook native app isn't available, use browser.
String uri = "https://www.facebook.com/natgeo" + natgeo; //Normal URL
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uriMobile));
startActivity(i);
}
the thing is I want, if someone didn't have facebook App, it will open in the browser. 我要的是,如果某人没有Facebook App,它将在浏览器中打开。
Edited 已编辑
package fa;
import com.f.fa.R;
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 ddc;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_item);
addListenerOnButton();
}
public void addListenerOnButton() {
ddc = (Button) findViewById(R.id.ddc);
try {
//try to open page in facebook native app.
String uri = "fb://page/" + natgeo; //Custom URL
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
}
catch (ActivityNotFoundException ex){
//facebook native app isn't available, use browser.
String uri = "https://www.facebook.com/natgeo" + natgeo; //Normal URL
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);
}
}
}
You use a variable, which is not declared before (read compiler errors).. 您使用一个之前未声明的变量(读取编译器错误)。
Add String natgeo = "my content";
添加String natgeo = "my content";
before your try-catch block to make your code compiling. 在try-catch块之前进行代码编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.