【问题标题】:Picasso sometimes not download photos and crash my application毕加索有时不下载照片并使我的应用程序崩溃
【发布时间】:2015-06-20 23:32:52
【问题描述】:
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:设置 plane_mode_on 已从 android.provider.Settings.System 移至 android.provider.Settings.Global,返回只读值。)

我搜索了一下发现应该导入:

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;
}

其实我不知道在哪里写**

【问题讨论】:

  • “在没有访问 onSuccess, onError 函数的情况下崩溃了!我的 logcat 中有这个”——如果你崩溃了,将会有一个与该崩溃相关的 Java 堆栈跟踪。您引用的警告不是 Java 堆栈跟踪的一部分。关注 Java 堆栈跟踪,以确定崩溃的位置和原因。
  • 你认为毕加索不是崩溃的原因吗??
  • 您能否发布您的日志猫,以便我们进一步协助:)
  • “飞行模式”警告与坠机无关。当毕加索正常工作时,我也看到了。这只是在最新的 Android 版本中移动的东西,而毕加索尚未为此更新。但我很确定这与你的崩溃无关。正如 CommonsWare 所说,LogCat 中应该有一些堆栈跟踪。

标签: android picasso airplane


【解决方案1】:

您收到警告的原因是从 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?
}

【讨论】:

  • 在哪里可以设置这个功能??
  • @AyaRadwan 我想你的意思是你怎么称呼它?
  • 其实我不会怎么用
  • 请您向我解释一下如何使用完整的示例:)
  • 这是什么意思? @TargetApi
猜你喜欢
  • 1970-01-01
  • 2014-10-30
  • 1970-01-01
  • 2018-08-26
  • 2015-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-28
相关资源
最近更新 更多