[英]Get Facebook User ID OnMapLongClickListener android
我想通過意圖傳遞谷歌地圖中的facebook ID。
我有一個OnMapLongClickListener來獲取Latlng並通過意圖傳遞,我也想傳遞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");
}
}
我找到了解決方案...
即時通訊使用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);
謝謝
我沒有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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.