私はFacebookのユーザーが最初にログインした後、別のマップアクティビティに移動するアプリケーションを構築しています。別のアクティビティプラス私は私のクライアントの電子メールを保存したい。Androidの共有共有設定とユーザーのfacebookログインの電子メールを取得する4
SharedPreferences preferencesPut = getSharedPreferences("KEY", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("nameKEY", "name");
editor.putString("emailKEY", "email");
editor.putBoolean("done", true);
editor.commit();
これはあなたの名前とメールアドレスを保存します: - ここに私のコードです
public class MainActivity extends AppCompatActivity {
private TextView info;
private LoginButton loginButton;
private CallbackManager callbackManager;
SharedPreferences sp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_main);
sp = getPreferences(MODE_PRIVATE);
String access_token = sp.getString("access_token",null);
long expires = sp.getLong("access_expires",0);
if (access_token != null){
}
info = (TextView) findViewById(R.id.info);
loginButton = (LoginButton) findViewById(R.id.login_button);
List<String> permissionNeeds = Arrays.asList("email", "user_birthday", "public_profile");
loginButton.setReadPermissions(permissionNeeds);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
String token = loginResult.getAccessToken().getToken();
Log.d("LOGIN_SUCCESS", "Success");
loginButton.setVisibility(View.INVISIBLE); //<- IMPORTANT
Intent intent = new Intent(MainActivity.this,MapsActivity.class);
startActivity(intent);
finish();//<- IMPORTANT
}
@Override
public void onCancel() {
info.setText("Login attempt Canceled");
}
@Override
public void onError(FacebookException error) {
info.setText("Login attempt failed");
}
});
AccessTokenTracker accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(
AccessToken oldAccessToken,
AccessToken currentAccessToken) {
// Set the access token using `q
// currentAccessToken when it's loaded or set.
}
};
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode,resultCode,data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
public void imageView (View v) {
ImageView img = (ImageView) findViewById(R.id.loofreLogo);
if (img != null) {
img.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("http://www.loofre.com"));
startActivity(intent);
}
});
}
}
public void InsOnclick(View args0) {
if (args0.getId()==R.id.Bins){
Intent intent = new Intent(this,instructionSlide.class);
this.startActivity(intent);
}
}
public void AboutUs (View args1){
if (args1.getId()==R.id.Babout){
Intent intent = new Intent(this,AboutUs.class);
this.startActivity(intent);
}
}
}
共有設定を使用してデータを保存しようとしましたか? –
@BhaveshMisri私はそれを行う方法を知らない... youtubeとstackoverflowからいくつかのチュートリアルを試みたが、それを理解することができません...だから私は別の活動を作成する必要がありますか?ログイン私はこのアクティビティのみ –