【发布时间】:2016-08-10 20:48:29
【问题描述】:
我想在我的应用中引用我的 Facebook 页面 因此,当用户按下按钮时,他将被定向到我在 fb 应用程序中的 fb 页面 否则他将在浏览器中被定向到我的 fb 页面 我不知道这是如何工作的,所以我处理了代码 来自这篇文章
但我在 (this) 中遇到错误,我似乎无法理解问题所在 这是代码
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.Button;
public class info_popup extends Activity {
public static String FACEBOOK_URL = "https://www.facebook.com/ahmednageebobiad";
public static String FACEBOOK_PAGE_ID = "Ahmed Nageeb";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_info_popup);
DisplayMetrics DM = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(DM);
int Width = DM.widthPixels;
int Hieght = DM.heightPixels;
getWindow().setLayout((int) (Width * .8), (int) (Hieght * .6));
Button button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent facebookIntent = new Intent(Intent.ACTION_VIEW);
String facebookUrl = getFacebookPageURL(this);
facebookIntent.setData(Uri.parse(facebookUrl));
startActivity(facebookIntent);
}
});
//method to get the right URL to use in the intent
}
public String getFacebookPageURL(Context context) {
PackageManager packageManager = context.getPackageManager();
try {
int versionCode = packageManager.getPackageInfo("com.facebook.katana", 0).versionCode;
if (versionCode >= 3002850) { //newer versions of fb app
return "fb://facewebmodal/f?href=" + FACEBOOK_URL;
} else { //older versions of fb app
return "fb://page/" + FACEBOOK_PAGE_ID;
}
} catch (PackageManager.NameNotFoundException e) {
return FACEBOOK_URL; //normal web url
}
}
}
这是错误
Error:(50, 38) error: method getFacebookPageURL in class info_popup cannot be applied to given types;
required: Context
found: <anonymous OnClickListener>
reason: actual argument <anonymous OnClickListener> cannot be converted to Context by method invocation conversion
【问题讨论】:
标签: android facebook facebook-graph-api