2
登錄時需要很長的時間,我已經使用Facebook的SDK 3.5 android系統中創建自定義登錄按鈕,點擊後會得到Facebook的詳細信息,然後發送到服務器,然後再進入下一個意圖(屏幕)。我已經創建了下面的代碼並使用它,但進度對話框需要很長時間去Facebook onCompletemethod()也有時timedOut.I發佈了下面的代碼,請讓我知道是否有更好的方式登錄比下面的,如果我可以減少登錄Facebook所需的時間。我真的很感謝你的幫助。提前感謝。Facebook登錄在
public class MainActivity extends Activity {
private ProgressDialog progressDialog;
static String email;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Wait...");
Button bt=(Button)findViewById(R.id.button1);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
runOnUiThread(new Runnable() {
@Override
public void run() {
progressDialog.show();
}
});
Session.openActiveSession(MainActivity.this, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
Request.newMeRequest(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
progressDialog.dismiss();
email= (String) response.getGraphObject().getProperty("email");
Log.d("email", email);
new FetchTask().execute();
}
}
}).executeAsync();
}
}
});
}});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(Session.getActiveSession() != null)
{
Session.getActiveSession().onActivityResult(MainActivity.this, requestCode, resultCode, data);
}
}