获取Facebook用户ID OnMapLongClickListener android

时间:2015-04-23 00:39:43

标签: android facebook google-maps

我想在谷歌地图中通过意图传递facebook ID。

我有一个OnMapLongClickListener来获取Latlng并通过intent传递,我也想传递facebook用户ID ...我该怎么做?

OnMapLongClickListener

googlemap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
        @Override
        public void onMapLongClick(final LatLng latlng) {


            Intent intent = new Intent(MainActivity.this,newEvent.class);
            LatLng posicao = latlng;
            LatLng posicao1 = latlng;
            intent.putExtra("posicao", posicao);
            Bundle args = new Bundle();
            args.putParcelable("posicao1", posicao1);
            intent.putExtra("bundle", args);

            startActivity(intent);
        }
    });

我在这个方法中检索facebook id

  // METHODS FACEBOOK
public void onSessionStateChanged(final Session session, SessionState state, Exception exception){
    if(session != null && session.isOpened()){

        Toast.makeText(getBaseContext(),"Conectado!!", Toast.LENGTH_LONG).show();
        Request.newMeRequest(session, new Request.GraphUserCallback() {
            @Override
            public void onCompleted(GraphUser user, Response response) {
                if(user != null){  
                //final TextView tv = (TextView) findViewById(R.id.idface);

                    //tv.setText(user.getId());

                    Log.i("Script", "Usuário conectado " + user.getId());
                    getFriends(session);
                }
            }
        }).executeAsync();
    }
    else{
        Log.i("Script", "Usuario não conectado");
    }
}

2 个答案:

答案 0 :(得分:0)

我找到了解决方案......

即时使用SharedPreferences

 SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
                    p.edit().putString("FB_ID", loginId).commit();

然后

    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
                final String username = p.getString("FB_ID", "");
Bundle args = new Bundle();
args.putString("facebook", username);
                intent.putExtra("facebook", args);

感谢

答案 1 :(得分:0)

我没有Android或Java开发环境,所以这可能无法编译,但这应该会给你一个想法。 facebook用户ID存储在名为userId的字段中。我已将您的活动称为MyActivity - 我认为您的代码位于活动中

class MyActivity extends Activity implements OnMapLongClickListener
{
    private String userId;

    @Override
    public void onMapLongClick(final LatLng latlng) {
        Intent intent = new Intent(MainActivity.this,newEvent.class);
        LatLng posicao = latlng;
        LatLng posicao1 = latlng;
        intent.putExtra("posicao", posicao);
        intent.putExtra("userId", userId);
        Bundle args = new Bundle();
        args.putParcelable("posicao1", posicao1);
        intent.putExtra("bundle", args);

        startActivity(intent);
    }

    public void onSessionStateChanged(final Session session, SessionState state, Exception exception){
    if(session != null && session.isOpened()){
        Toast.makeText(getBaseContext(),"Conectado!!", Toast.LENGTH_LONG).show();
        Request.newMeRequest(session, new Request.GraphUserCallback() {

            @Override
            public void onCompleted(GraphUser user, Response response) {
                if(user != null){  
                    //final TextView tv = (TextView) findViewById(R.id.idface);

                    userId = user.getId();

                    Log.i("Script", "Usuário conectado " + user.getId());
                    getFriends(session);
                }
            }
        }).executeAsync();
    }
    else{
        Log.i("Script", "Usuario não conectado");
    }
}

以下代码将从您Activity

中的某个位置开始调用
googlemap.setOnMapLongClickListener(this);