0

After reading some posts related with this subject I cannot solve my doubt.

In my app, I log in with Facebook (Registration.class) and app starts in MainActivity.class .

In this class, I want to get some information about user like 'user_ID' to get image profile user and 'user_first_name', both are useful to put this information in the Navigation Drawer.

My problem is that I get this information in Registration.class with this code:

profileTracker = new ProfileTracker() {
            @Override
            protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
                // App code
                Log.i("PERFIL_NAME", Profile.getCurrentProfile().getFirstName());                   
                Log.i("PERFIL_FOTO", Profile.getCurrentProfile().getProfilePictureUri(100, 100).toString());
                Log.i("USER_ID", Profile.getCurrentProfile().getId());          
            }
        };

but I do not know how I have to get it in MainActivity.class.

If I use this in the same way I get null. Also, I have tested with an Intent and it does not work because it is null too (I suppose that Intent is executed before than profileTracker()).

Moreover, I have tried some methods in MainActivity like:

public void putImageProfile() {
    URL imgUrl = null;
    try {
        imgUrl = new URL("http://graph.facebook.com/'user_ID'/picture?type=large");
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    InputStream in = null;
    try {
        in = (InputStream) imgUrl.getContent();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Bitmap  bitmap = BitmapFactory.decodeStream(in);
    img_profile.setImageBitmap(bitmap); //ImageView in NavDrawer
}

('user_ID' is my user ID profile Facebook written manually 1000098...) and it does not work well.

In conclusion, I want to get 'user_ID' and 'user_name' in MainActivity.class ... and after, to get the image profile with the 'user_ID'.

Thank so much.

ghost talker
  • 402
  • 5
  • 15
KryNaC
  • 379
  • 4
  • 21
  • http://stackoverflow.com/questions/30317540/how-do-i-fetch-name-and-email-using-facebook-sdk/30318174#30318174 – Tufan Jun 03 '15 at 12:37
  • check it it can help you – Tufan Jun 03 '15 at 12:37
  • @Tufan I have tested the code in your link but, if I put that code in Registration.class how I get info in MainActivity.class?? – KryNaC Jun 03 '15 at 12:51
  • thats realy crucial ..what you can do when u get your information you can saved in sharedpreferences ..nd play with it – Tufan Jun 03 '15 at 12:56
  • but then with your link I get info which I already knew with 'profileTracker()' ... how I make that with SharedPreferences in both classes? Thanks – KryNaC Jun 03 '15 at 12:59
  • I get null when I getSharedPreferences in MainActivity.class ... why these values from Registration.class cannot be passed? – KryNaC Jun 03 '15 at 14:06

0 Answers0