小编Leo*_*rić的帖子

Android Glide:如果请求失败,则阻止白色图像

所以我只是感兴趣,如果提供的网址错误,我可以阻止Glide将白色(空)图像加载到ImageView中.如果找不到,我想保留我提供的XML格式的图像图像(因为用户输入可能是错误的).

我已经尝试在监听器中返回true,但我想这只是用于动画处理.非常感谢!

 public static void loadImage(String url, Context c, ImageView target) {
    Glide.with(c).load(url).listener(new RequestListener<String, GlideDrawable>() {
        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
            e.printStackTrace();
            return true;
        }

        @Override
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
            return false;
        }
    }).into(target);
}
Run Code Online (Sandbox Code Playgroud)

}

android android-glide

11
推荐指数
1
解决办法
9105
查看次数

Android:自定义通知声音无法播放

我已经在网站上尝试了几乎所有可用的答案,但不知怎的,我无法获得通知声音.我正在测试的当前代码是这样的(通知内置在警报接收器中):

public class AlarmReceiver extends BroadcastReceiver {

private static final int NOTIFICATION_ID = 0;

@Override
public void onReceive(Context context, Intent intent) {


  NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.app_name))
            .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, MainActivity_.class), 0))
            .setContentText("temporary text")
            .setAutoCancel(true)
            .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
                    + "://" + context.getPackageName() + "/raw/alert"))
            .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setWhen(System.currentTimeMillis())
            .setSmallIcon(R.drawable.ic_stat_notification);

    Notification notification = builder.build();
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, notification);
Run Code Online (Sandbox Code Playgroud)

然而,声音可以通过MediaPlayer播放,因此这里的格式不是问题.这可能与声音的长度(30秒)有关吗?谢谢您的帮助!

java audio notifications android

3
推荐指数
1
解决办法
5438
查看次数

标签 统计

android ×2

android-glide ×1

audio ×1

java ×1

notifications ×1