[英]Picasso sometimes not download photos and crash my application
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! 当我尝试使用毕加索下载照片时,有时我的应用程序崩溃而没有访问onSuccess和onError函数! and I have this in my logcat
我在logcat中有这个
(W/Settings﹕ Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.)
(W / Settings:Settingplane_mode_on已从android.provider.Settings.System移至android.provider.Settings.Global,返回只读值。)
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** 其实我不知道在哪里写**
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
. 收到警告的原因是因为从Jelly Bean 4.2及更高版本开始,飞行模式设置已移至
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?
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.