이름, 이메일 및 프로필 사진과 같은 사용자 세부 정보를 얻기 위해 google plus login을 통합하려고합니다.하나의 활동에서 다른 이미지로 이미지 전송 실패
지금은 내가 자신의 프로필 그림
너무Login.Java에게지고있어 같은 활동에 사용하는 경우 자신의 이름, 이메일 및 프로필 그림을 얻으려고 아래의 코드를 사용하여
public void onConnected(Bundle connectionHint) { // We've resolved any connection errors. mGoogleApiClient can be used to // access Google APIs on behalf of the user. // Get user's information getProfileInformation(); } private void getProfileInformation() { if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) { Intent i = new Intent(getApplicationContext(), MainActivity.class); Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient); String personPhotoUrl = currentPerson.getImage().getUrl(); String personGooglePlusProfile = currentPerson.getUrl(); Toast.makeText(this, personPhotoUrl, Toast.LENGTH_LONG).show(); String email = Plus.AccountApi.getAccountName(mGoogleApiClient); //new GetProfileImage(urImageView).execute(personPhotoUrl); // Create the bundle new GetProfileImage().execute(personPhotoUrl); Bundle bundle = new Bundle(); // Add your data from getFactualResults method to bundle bundle.putString("Google", "Logged in using Google Account"); bundle.putString("GoogleUsername", currentPerson.getDisplayName()); bundle.putString("GoogleEmail", email); if(resultBmp!=null) { i.putExtra("GoogleProfileImage", resultBmp); } i.putExtras(bundle); startActivity(i); } private class GetProfileImage extends AsyncTask<String, Void, Bitmap> { protected Bitmap doInBackground(String... urls) { String urldisplay = urls[0]; Bitmap mIcon11 = null; try { InputStream in = new java.net.URL(urldisplay).openStream(); mIcon11 = BitmapFactory.decodeStream(in); } catch (Exception e) { Log.e("Error", e.getMessage()); e.printStackTrace(); } return mIcon11; } protected void onPostExecute(Bitmap result) { resultBmp = result; //bmImage.setImageBitmap(result); } }
MainActivity.Java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, PlusOptions.builder().build())
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
mGoogleApiClient.connect();
Intent intent = getIntent();
if(intent.getStringExtra("Google") != null){
// 1. get passed intent
// 2. get message value from intent
String userName = intent.getStringExtra("GoogleUsername");
String email = intent.getStringExtra("GoogleEmail");
if(intent.getStringExtra("Google").equals("Logged in using Google Account")){
((TextView)findViewById(R.id.txtUser)).setText(userName);
((TextView)findViewById(R.id.txtemail)).setText(email);
Bitmap bitmap = (Bitmap)this.getIntent().getParcelableExtra("GoogleProfileImage");
//Bitmap bitmap = getIntent().getParcelableExtra("GooglePic");
ImageView imageView = (ImageView) findViewById(R.id.imgProfilePic);
imageView.setImageBitmap(bitmap);
}
}
}
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
@Override
public void onConnectionFailed(ConnectionResult result) {
// TODO Auto-generated method stub
Log.d("Debug","Connection failed");
Intent i = new Intent(this,Login.class);
startActivity(i);
finish();
//super.onConnectionFailed(result);
}
@Override
public void onConnected(Bundle connectionHint) {
// TODO Auto-generated method stub
Log.d("Debug","Connected");
//super.onConnected(connectionHint);
mGoogleApiClient.connect();
}
내가 n으로 이미지를 보내려고하는 경우 그것은 처음 로그인 할 때 내게 그림을 보여주는 ext 활동입니다. 두 번째로 로그인하거나 앱을 다시 시작하면 사진이 표시됩니다.
누구나 내 MainActivity에서 어디서 잘못 될 수 있습니까?
내가 더 좋은 방법은 imageview 경로를 전달하고 MainActivity의 경로에서 이미지를 가져 오는 것, 이미지 전달을 통과하는 것은 많은 메모리가 필요하다고 생각합니다. –
경로 대신 이미지 비트 맵을 전달할만한 이유가 있습니까? –
그 밖에 아무것도 없습니다. 나는 gmail 및 youtube와 같이 탐색 창에 로그인 한 후 사용자에게 자신의 프로필 사진을 보여줄 수 있습니다. – coder