No funciona correctamente en el fragmento de Android
Estoy trabajando con google + login a mi aplicación y cuando lo hice con una actividad de su encanto de trabajo y después de que mueva mi código en un fragmento y después de eso cuando intento iniciar sesión en google + no funciona tengo que abrir la actividad de fragmento 2 veces para iniciar sesión en el google + puede alguien decirme lo que sucede el código del fragmento se añade a continuación
public class GooglePluseFragment extends Fragment implements ConnectionCallbacks, OnConnectionFailedListener { private static final int RC_SIGN_IN = 0; private static final String TAG = "MainActivity"; private static final int PROFILE_PIC_SIZE = 800; private GoogleApiClient mGoogleApiClient; private boolean mIntentInProgress; private boolean mSignInClicked; private ConnectionResult mConnectionResult; private SignInButton btnSignIn; private Button btnSignOut; private Context mContext; private Activity mActivity; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mActivity = getActivity(); mContext = getActivity().getApplicationContext(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.compund_google_pluse_fragment, container, false); btnSignIn = (SignInButton) view.findViewById(R.id.btn_sign_in); btnSignOut = (Button) view.findViewById(R.id.btn_sign_out); sharedPref = view.getContext().getSharedPreferences( Constantz.SHEARED_PREFEREANCE, Context.MODE_PRIVATE); mGoogleApiClient = new GoogleApiClient.Builder(view.getContext()) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this).addApi(Plus.API, null) .addScope(Plus.SCOPE_PLUS_LOGIN).build(); btnSignIn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { signInWithGplus(); } }); btnSignOut.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { signOutFromGplus(); } }); return view; } @Override public void onStart() { super.onStart(); mGoogleApiClient.connect(); } @Override public void onStop() { super.onStop(); if (mGoogleApiClient.isConnected()) { mGoogleApiClient.disconnect(); } } @Override public void onActivityResult(int requestCode, int responseCode, Intent intent) { if (requestCode == RC_SIGN_IN) { if (responseCode != Activity.RESULT_OK) { mSignInClicked = false; } mIntentInProgress = false; if (!mGoogleApiClient.isConnecting()) { mGoogleApiClient.connect(); } } } @Override public void onConnectionFailed(ConnectionResult result) { if (!result.hasResolution()) { GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), mActivity, 0).show(); Log.e(TAG, "" + result.getErrorCode()); return; } if (!mIntentInProgress) { mConnectionResult = result; if (mSignInClicked) { Log.e(TAG, "" + result.getErrorCode()); resolveSignInError(); } } } @Override public void onConnected(Bundle arg0) { mSignInClicked = false; getProfileInformation(); updateUI(true); } @Override public void onConnectionSuspended(int arg0) { mGoogleApiClient.connect(); updateUI(false); } private void updateUI(boolean isSignedIn) { if (isSignedIn) { btnSignIn.setVisibility(View.GONE); btnSignOut.setVisibility(View.VISIBLE); } else { btnSignIn.setVisibility(View.VISIBLE); btnSignOut.setVisibility(View.GONE); } } /** * Sign-in into google * */ private void signInWithGplus() { if (!mGoogleApiClient.isConnecting()) { mSignInClicked = true; resolveSignInError(); } } /** * Method to resolve any signin errors * */ private void resolveSignInError() { if (mConnectionResult.hasResolution()) { try { mIntentInProgress = true; mConnectionResult.startResolutionForResult(mActivity, RC_SIGN_IN); } catch (SendIntentException e) { mIntentInProgress = false; mGoogleApiClient.connect(); } } } /** * Fetching user's information name, email, profile pic * */ private void getProfileInformation() { try { if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) { Person currentPerson = Plus.PeopleApi .getCurrentPerson(mGoogleApiClient); String personName = currentPerson.getDisplayName(); String personPhotoUrl = currentPerson.getImage().getUrl(); String personGooglePlusProfile = currentPerson.getUrl(); String email = Plus.AccountApi.getAccountName(mGoogleApiClient); Log.e(TAG, "Name: " + personName + ", plusProfile: " + personGooglePlusProfile + ", email: " + email + ", Image: " + personPhotoUrl + " user id:" + currentPerson.getId()); } else { Toast.makeText(mContext, "Person information is null", Toast.LENGTH_LONG).show(); } } catch (Exception e) { e.printStackTrace(); } } /** * Sign-out from google * */ private void signOutFromGplus() { if (mGoogleApiClient.isConnected()) { Plus.AccountApi.clearDefaultAccount(mGoogleApiClient); mGoogleApiClient.disconnect(); mGoogleApiClient.connect(); updateUI(false); } }
}
- Widget de cuadrícula Android de Google+ para el tutorial de tableta
- Google inicia sesión y termina sesión en android con la última API de g-plus
- Android / Google Plus - No puedo compartir la imagen de mi proveedor de contenido
- Google api gettoken (Context, String, String) ahora está obsoleto
- ¿Cómo solucionar la conexión fallida en el inicio de sesión de Google+ en android?
Así es como agregué framgent en la actividad del fragmento
pluseFragment = new GooglePluseFragment(); FragmentManager manager = getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.add(R.id.pluse_frame_layout, pluseFragment); transaction.commit();
Alguien puede decirme lo que he hecho mal? Por qué tengo que abrir la actividad dos veces para iniciar sesión gracias
- Obtener token de acceso para mi aplicación desde GoogleApiClient en Android
- Google Android signo más en el problema. HandleSignInResult devuelve False
- Regeneración del "código de autorización único" para Google+ en Android
- ¿Cómo desconectar un usuario de Google en mi aplicación de Android en botón Haga clic en Java?
- Cómo obtener vídeos (no locales) de la aplicación Google Fotos
- ¿Cómo integrar Amazon Cognito con Google Plus para Android?
- Nueva interfaz de la tarjeta Google Now y Google+
- statusCode = DEVELOPER_ERROR en google login
Finalmente encontró la respuesta, el problema fue cuando la actividad de resultado llamada en el fragmento fue capturado por la actividad de los padres por lo que tiene que redireccionar manualmente el resultado a su fragmento. Solo tienes que agregar esta línea en tu Actividad de Fragmentos de Padres
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == GooglePluseFragment.RC_SIGN_IN) { GooglePluseFragment fragment = (GooglePluseFragment) getSupportFragmentManager() .findFragmentById(R.id.pluse_frame_layout); fragment.onActivityResult(requestCode, resultCode, data); } else { super.onActivityResult(requestCode, resultCode, data); } }
Solución sencilla para esto: sólo cree el método estático en el fragmento "
public static myOnActivityResult(int requestCode, int resultCode, Intent data){ .....Enter same code }
y
Llamar a este método de Parant Activity en
protected void onActivityResult(int requestCode, int resultCode, Intent data) { ..... MyFragment.myOnActivityResult(requestCode,resultCode,data) }
Eso es
- ¿Cuál es la diferencia entre ImageView.setBackgroundResource y ImageView.setImageResource?
- Retrofit con un servicio de la vieja escuela