Я пытаюсь интегрировать возможности Facebook в свое приложение для Android. Итак, у меня есть адаптер, который будет отображать список элементов. Когда пользователь нажимает кнопку, он запускает процесс аутентификации / авторизации. Но у меня есть ошибки в моем коде. Я пропустил какие-либо заявления или что-нибудь? Я следую примеру от здесь
Error 1: MODE_PRIVATE cannot be resolved to a variable
Error 2: The method onActivityResult(int, int, Intent) is undefined for the type BaseAdapter
Adapter.java
public class LazyAdapter extends BaseAdapter {
Facebook facebook = new Facebook("132789674563789674");
private Activity activity;
private String[] data;
private String[] text;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
private static final String APP_ID = "132789674563789674";
private ProgressDialog mProgress;
private Handler mRunOnUi = new Handler();
String FILENAME = "AndroidSSO_data";
private SharedPreferences mPrefs;
public LazyAdapter(Activity a, String[] d, String[] t) {
activity = a;
data=d;
text = t;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder{
public TextView text;
public ImageView image;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View vi=convertView;
ViewHolder holder;
if(convertView==null){
vi = inflater.inflate(R.layout.item, null);
holder=new ViewHolder();
holder.text=(TextView)vi.findViewById(R.id.text);;
holder.image=(ImageView)vi.findViewById(R.id.image);
vi.setTag(holder);
ImageButton fbBtn = (ImageButton) vi.findViewById(R.id.fb);
fbBtn.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v)
{
/*
* Get existing access_token if any
*/
mPrefs = getPreferences(MODE_PRIVATE); <--- MODE_PRIVATE cannot be resolved to a variable
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if(access_token != null) {
facebook.setAccessToken(access_token);
}
if(expires != 0) {
facebook.setAccessExpires(expires);
}
/*
* Only call authorize if the access_token has expired.
*/
if(!facebook.isSessionValid()) {
facebook.authorize(activity, new String[] {"publish_stream", "publish_checkins"}, new DialogListener() {
@Override
public void onComplete(Bundle values)
{
//postToFacebook(String image);
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
}
@Override
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
});
}
}
}
);
}
else
holder=(ViewHolder)vi.getTag();
holder.text.setText(text[position]);
holder.image.setTag(data[position]);
imageLoader.DisplayImage(data[position], activity, holder.image);
return vi;
postToFacebook("");
}//close getView
private void postToFacebook(String data) {
mProgress.setMessage("Posting ...");
mProgress.show();
AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(facebook);
Bundle params = new Bundle();
params.putString("message", "Visit me here!");
params.putString("name", "My Name");
params.putString("caption", "google.com");
params.putString("link", "http://www.google.com");
params.putString("description", "Visit the search engine");
params.putString("image", data);
mAsyncFbRunner.request("me/feed", params, "POST", new WallPostListener());
}//close posttofacebook
private final class WallPostListener extends BaseRequestListener {
public void onComplete(final String response) {
mRunOnUi.post(new Runnable() {
@Override
public void run() {
mProgress.cancel();
Toast.makeText(activity, "Posted to Facebook", Toast.LENGTH_SHORT).show();
}
});
}//close oncomplete
}//close wallpostlistener
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); <----- The method onActivityResult(int, int, Intent) is undefined for the type BaseAdapter
facebook.authorizeCallback(requestCode, resultCode, data);
}
}