Aquí podría ser tu PUBLICIDAD


¿Cómo voy a mostrar a los usuarios información después de su inicio de sesión? He hecho todo lo necesario, pero no su trabajo

votos
-2

He creado dos actividades 1. 2. MainActivity UserProfileActivity y estoy visualización de la información del usuario después de iniciar sesión en la actividad sucessfull PerfilUsuario. Pero no muestra la información del usuario. Por favor, me ayudan a superar este problema.

Este es mi archivo activity_xml

<?xml version=1.0 encoding=utf-8?>
<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
xmlns:app=http://schemas.android.com/apk/res-auto
xmlns:tools=http://schemas.android.com/tools
android:layout_width=match_parent
android:layout_height=match_parent
android:orientation=vertical
tools:context=com.example.advanced.loginactivity.MainActivity>

<TextView
  android:layout_width=wrap_content
  android:layout_height=wrap_content
  android:layout_marginLeft=20dp
  android:layout_marginTop=30dp
  android:text=Click below to Login 
  android:textSize=20sp
  app:layout_constraintBottom_toBottomOf=parent
  app:layout_constraintLeft_toLeftOf=parent
  app:layout_constraintRight_toRightOf=parent
  app:layout_constraintTop_toTopOf=parent />


<com.facebook.login.widget.LoginButton
 android:layout_margin=30dp
 android:layout_marginLeft=20dp
 android:textSize=20sp
 android:layout_marginTop=50dp
 android:id=@+id/login_button
 android:layout_width=wrap_content
 android:layout_height=wrap_content
 />

 </LinearLayout>

Este es mi archivo MainActivity.java

package com.example.advanced.loginactivity;

import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TextView;
    import android.widget.Toast;

    import com.facebook.CallbackManager;
    import com.facebook.FacebookCallback;
    import com.facebook.FacebookException;
    import com.facebook.GraphRequest;
    import com.facebook.GraphResponse;
    import com.facebook.appevents.AppEventsLogger;
    import com.facebook.login.LoginResult;
    import com.facebook.login.widget.LoginButton;

    import org.json.JSONObject;


     public class MainActivity extends AppCompatActivity {

     private LoginButton loginButton;
     private CallbackManager callbackManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        loginButton = (LoginButton) findViewById(R.id.login_button);
        loginButton.setReadPermissions(email);
        // If using in a fragment
        // Other app specific specialization
        callbackManager = CallbackManager.Factory.create();
        // Callback registration
        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                // App code
                Toast.makeText(MainActivity.this, Logged in Successfully, Toast.LENGTH_SHORT).show();
                Log.e(Logged in, Logged in successfully);
                getUserDetails(loginResult);
            }

            @Override
            public void onCancel() {
                // App code
            }

            @Override
            public void onError(FacebookException exception) {
                Log.e(Logged in, Error);
                // App code
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        callbackManager.onActivityResult(requestCode, resultCode, data);
    }

    //pasting newer code here

    protected void getUserDetails(LoginResult loginResult) {
        GraphRequest data_request = GraphRequest.newMeRequest(
                loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(
                            JSONObject json_object,
                            GraphResponse response) {
                        Intent intent = new Intent(MainActivity.this, UserProfile.class);
                        intent.putExtra(userProfile, json_object.toString());
                        startActivity(intent);
                    }

                });
        Bundle permission_param = new Bundle();
        permission_param.putString(fields, id,name,email,picture.width(120).height(120));
        data_request.setParameters(permission_param);
        data_request.executeAsync();

    }

    protected void onResume() {
        super.onResume();
        // Logs 'install' and 'app activate' App Events.
        AppEventsLogger.activateApp(this);
    }
    @Override
    protected void onPause() {
        super.onPause();
        // Logs 'app deactivate' App Event.
        AppEventsLogger.deactivateApp(this);
    }

    }

This is my activity_user_profle.xml file

           <?xml version=1.0 encoding=utf-8?>
    <RelativeLayout 
     xmlns:android=http://schemas.android.com/apk/res/android
    xmlns:app=http://schemas.android.com/apk/res-auto
    xmlns:tools=http://schemas.android.com/tools
    android:layout_width=match_parent
    android:layout_height=match_parent
    tools:context=com.example.advanced.loginactivity.UserProfile>


    <ImageView
        android:layout_width=wrap_content
        android:layout_height=wrap_content
        android:id=@+id/profilePic/>

    <TextView
        android:layout_width=wrap_content
        android:layout_height=wrap_content
        android:layout_below=@+id/profilePic
        android:id=@+id/UserName
        />

    <TextView
        android:layout_width=wrap_content
        android:layout_height=wrap_content
        android:id=@+id/email
        android:layout_below=@+id/UserName
        />

     </RelativeLayout>


This is my Userprofile.java file   

           package com.example.advanced.loginactivity;

     import android.content.Intent;
     import android.support.v7.app.AppCompatActivity;
     import android.os.Bundle;
     import android.util.Log;
     import android.widget.ImageView;
     import android.widget.TextView;

     import com.squareup.picasso.Picasso;

     import org.json.JSONObject; 
      public class UserProfile extends AppCompatActivity {

    JSONObject response, profile_pic_data, profile_pic_url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_profile);
        Intent intent = getIntent();
        String jsondata = intent.getStringExtra(userProfile);
        //Log.w(Jsondata, jsondata);
        TextView user_name = (TextView) findViewById(R.id.UserName);
        ImageView user_picture = (ImageView) findViewById(R.id.profilePic);
        TextView user_email = (TextView) findViewById(R.id.email);

        Log.w(Jsondata, jsondata);

        try {
            response = new JSONObject(jsondata);
            user_email.setText(response.get(email).toString());
            user_name.setText(response.get(name).toString());
            profile_pic_data = new JSONObject(response.get(picture).toString());
            profile_pic_url = new       JSONObject(profile_pic_data.getString(data));
            Picasso.with(this).load(profile_pic_url.getString(url))
                    .into(user_picture);

        } catch(Exception e){
            e.printStackTrace();
        }
    }
    }  


This is my gradle.app file


         apply plugin: 'com.android.application'

    android {
        compileSdkVersion 27
        defaultConfig {
            applicationId com.example.advanced.loginactivity
            minSdkVersion 15
            targetSdkVersion 27
            versionCode 1
            versionName 1.0
            testInstrumentationRunner android.support.test.runner.AndroidJUnitRunner
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:27.1.1'
        implementation 'com.android.support.constraint:constraint-layout:1.1.2'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

        //facebook sdk dependence
        implementation 'com.facebook.android:facebook-login:4.36.0'
        //image picasso dependence
        implementation 'com.squareup.picasso:picasso:2.5.2'

       }
Publicado el 02/09/2018 a las 05:00
fuente por usuario ashwin kushwah
En otros idiomas...        العربية       

1 respuestas

votos
0

Por favor, intente esto, en busca de Identificación, el correo electrónico y el uso de género JSONObject parámetro de y para el primer nombre y apellido favor parámetro de usuario GraphResponse


               public void onCompleted(JSONObject object, GraphResponse response) {

                        String id = object.getString("id");

                        String email = object.getString("email");

                        String gender = object.getString("gender");

                        String firstName = response.getJSONObject().getString("first_name");

                        String lastName = response.getJSONObject().getString("last_name");

               }
Respondida el 02/09/2018 a las 05:28
fuente por usuario jay shah


Aquí podría ser tu PUBLICIDAD