0
Picasso.with(getActivity().getApplicationContext()).load(imageString).resize(250, 250)
    .into(image, new Callback() {
        @Override
        public void onSuccess() {
            Log.e("profilepicsucess", "");
        }

        @Override
        public void onError() {
            Log.e("profilepicfalse :3", "");
        }
});

When I try to download photo using Picasso, SOMETIMES my application crashed WITHOUT accessing onSuccess, onError Functions! and I have this in my logcat

(W/Settings﹕ Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.)

I searched for it I found that I should import :

import static android.provider.Settings.System.AIRPLANE_MODE_ON;

and write this function

static boolean isAirplaneModeOn(Context context) {
    ContentResolver contentResolver = context.getContentResolver();
    return Settings.System.getInt(contentResolver, AIRPLANE_MODE_ON, 0) != 0;
}

Actually I don't know WHERE to write it**

beresfordt
  • 5,088
  • 10
  • 35
  • 43
Aya Radwan
  • 181
  • 5
  • 17
  • "crashed WITHOUT accessing onSuccess, onError Functions! and I have this in my logcat " -- if you are crashing, there will be a Java stack trace associated with that crash. The warning that you cite is not part of a Java stack trace. Focus on the Java stack trace, to determine where and why you are crashing. – CommonsWare Jun 20 '15 at 23:50
  • do you think that picasso not the reason for crashing ?? – Aya Radwan Jun 20 '15 at 23:53
  • 1
    Can you post your logcat, so that we can assist further `:)` – David Passmore Jun 21 '15 at 17:43
  • The 'airplane mode' warning has nothing to do with the crash. I see it also when picasso works correctly. It's just something that got moved in latest Android versions and Picasso it not yet updated for that. But I'm pretty sure it has nothing to do with your crashes. As CommonsWare said, there should be some stack trace in LogCat. – Ridcully Jun 21 '15 at 17:47

1 Answers1

0

The reason you are getting the warning is because from Jelly Bean 4.2 and up, the airplane mode settings have moved to Settings.Global.

Use this function to check the airplane mode:

/**
 * Gets the state of Airplane Mode.
 * 
 * @param context
 * @return true if enabled.
 */
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static boolean isAirplaneModeOn(Context context) {        
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return Settings.System.getInt(context.getContentResolver(), 
                Settings.System.AIRPLANE_MODE_ON, 0) != 0;          
    } else {
        return Settings.Global.getInt(context.getContentResolver(), 
                Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
    }       
}

However, I would need more detail to assist with the crashes.

This is how to use this function:

if(!isAirplaneModeOn(getActivity().getApplicationContext()){   
    //Picasso Code
    Picasso.with(getActivity().getApplicationContext()).load(imageString).resize(250, 250)
        .into(image, new Callback() {
            @Override
            public void onSuccess() {
                Log.e("profilepicsucess", "");
            }

            @Override
            public void onError() {
                Log.e("profilepicfalse :3", "");
            }
    });
}else{
    //do something else?
}
David Passmore
  • 6,089
  • 4
  • 46
  • 70