毕加索有时不下载照片并使我的应用程序崩溃
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", "");
}
});
当我尝试使用 Picasso 下载照片时,有时我的应用程序会崩溃 而无需 访问 onSuccess、onError 函数!我的 logcat
里有这个
(W/Settings﹕ Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.)
我搜索了一下我发现我应该导入 :
import static android.provider.Settings.System.AIRPLANE_MODE_ON;
并编写这个函数
static boolean isAirplaneModeOn(Context context) {
ContentResolver contentResolver = context.getContentResolver();
return Settings.System.getInt(contentResolver, AIRPLANE_MODE_ON, 0) != 0;
}
其实我不知道写在哪里**
您收到警告的原因是,从 Jelly Bean 4.2 及更高版本开始,飞行模式设置已移至 Settings.Global
。
使用此功能检查飞行模式:
/**
* 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;
}
}
但是,我需要更多详细信息来帮助解决崩溃问题。
这是使用此功能的方法:
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?
}
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", "");
}
});
当我尝试使用 Picasso 下载照片时,有时我的应用程序会崩溃 而无需 访问 onSuccess、onError 函数!我的 logcat
里有这个(W/Settings﹕ Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.)
我搜索了一下我发现我应该导入 :
import static android.provider.Settings.System.AIRPLANE_MODE_ON;
并编写这个函数
static boolean isAirplaneModeOn(Context context) {
ContentResolver contentResolver = context.getContentResolver();
return Settings.System.getInt(contentResolver, AIRPLANE_MODE_ON, 0) != 0;
}
其实我不知道写在哪里**
您收到警告的原因是,从 Jelly Bean 4.2 及更高版本开始,飞行模式设置已移至 Settings.Global
。
使用此功能检查飞行模式:
/**
* 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;
}
}
但是,我需要更多详细信息来帮助解决崩溃问题。
这是使用此功能的方法:
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?
}