[英]How to get values from a facebook login button and pass it to another activity
public class LoginActivity extends AppCompatActivity {
LoginButton fbloginButton;
CallbackManager callbackManager;
private static final String TAG = "LoginActivity";
private static final int REQUEST_SIGNUP = 0;
@BindView(R.id.input_email) EditText _emailText;
@BindView(R.id.input_password) EditText _passwordText;
@BindView(R.id.btn_login) Button _loginButton;
@BindView(R.id.link_signup) TextView _signupLink;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
fbloginButton=(LoginButton)findViewById(R.id.login_button);
fbloginButton.setReadPermissions("email","public_profile");
callbackManager = CallbackManager.Factory.create();
fbloginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
String userid=loginResult.getAccessToken().getUserId();
GraphRequest graphRequest=GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
displayUserInfo(object);
}
});
Bundle parameters=new Bundle();
parameters.putString("fields","first_name,last_name,email");
graphRequest.setParameters(parameters);
graphRequest.executeAsync();
}
public void displayUserInfo(JSONObject object)
{
String first_name="",last_name="",email="";
try {
***first_name=object.getString(first_name);
***last_name=object.getString(last_name);
***email=object.getString(email);
} catch (JSONException e) {
e.printStackTrace();
}
}
This is my code which is LoginActivity.java 这是我的代码,即LoginActivity.java
i want to get values specified *** and pass it to next actvity in the respective fields. 我想获取指定的值***并将其传递给各个字段中的下一个活动。 The next activity has five fields which are name,address,email, mobile number and password.
下一个活动有五个字段,分别是名称,地址,电子邮件,手机号码和密码。 i want to get the values first name and last name and pass it to name field and email address to email field.
我想获取值的名字和姓氏,并将其传递给名称字段,并将电子邮件地址传递给电子邮件字段。
I am a beginner in android developing. 我是android开发的初学者。
You need to define a listener that will start the next activity; 您需要定义一个侦听器,该侦听器将开始下一个活动。 for example, do you want the next activity to start at the onComplete() or at onSuccess() or somewhere else?
例如,您是否希望下一个活动从onComplete()或onSuccess()或其他地方开始? Anywhere you want to trigger the next activity, put the below code there;
在您要触发下一个活动的任何地方,将以下代码放在此处;
startActivity(new Intent(LoginActivity.this, NextActivity.class)
.putExtra("firstName", first_name)
.putExtra("lastName",last_name)
.putExtra("email",email)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.