如何使用Glide在Notifications 和 AppWidgets中load图片
来源:互联网 发布:传智大数据百度云 编辑:程序博客网 时间:2024/05/16 10:36
在普通的view中我们可以使用SimpleTarget下载Bitmap图片。那么在Remoteview中该如何使用Glide呢?是否有对应的Target类呢?答案是有的。
下面分开说一下
在 Notifications 中读取图片
在Notification中可以使用NotificationTarget来下载显示图片。
下面来看下具体的代码:
Notification的布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white" android:orientation="vertical"> <ImageView android:id="@+id/remoteview_notification_icon" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginRight="2dp" android:layout_weight="0" android:scaleType="centerCrop"/></LinearLayout>
首先是不实用Glide的方式读取图片
final RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.remoteview_notification);rv.setImageViewResource(R.id.remoteview_notification_icon, R.mipmap.future_studio_launcher);// build notificationNotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.mipmap.future_studio_launcher) .setContentTitle("Content Title") .setContentText("Content Text") .setContent(rv) .setPriority( NotificationCompat.PRIORITY_MIN);final Notification notification = mBuilder.build();// set big content view for newer androidsif (android.os.Build.VERSION.SDK_INT >= 16) { notification.bigContentView = rv;}NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(NOTIFICATION_ID, notification);
我们再来看一下用Glide的方式:
private NotificationTarget notificationTarget;...notificationTarget = new NotificationTarget( context, rv, R.id.remoteview_notification_icon, notification, NOTIFICATION_ID);
Glide .with( context.getApplicationContext() ) // safer! .load( eatFoodyImages[3] ) .asBitmap() .into( notificationTarget );
这样就可以使用Glide在Notification中读取图片了。
在 App Widgets 中读取图片
跟Notification类似,在App Widget 中使用AppWidgetTarget来读取图片。具体直接看代码:
public class FSAppWidgetProvider extends AppWidgetProvider { private AppWidgetTarget appWidgetTarget; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.custom_view_futurestudio); appWidgetTarget = new AppWidgetTarget( context, rv, R.id.custom_view_image, appWidgetIds ); Glide .with( context.getApplicationContext() ) // safer! .load( GlideExampleActivity.eatFoodyImages[3] ) .asBitmap() .into( appWidgetTarget ); pushWidgetUpdate(context, rv); } public static void pushWidgetUpdate(Context context, RemoteViews rv) { ComponentName myWidget = new ComponentName(context, FSAppWidgetProvider.class); AppWidgetManager manager = AppWidgetManager.getInstance(context); manager.updateAppWidget(myWidget, rv); }}
0 0
- 如何使用Glide在Notifications 和 AppWidgets中load图片
- 在RecyclerView中使用Glide和CircleImageView加载圆形图片时出现图片错乱
- 如何使用glide在加载成功图片时,截取屏幕
- Glide图片家在框架的使用
- 在GridView或者ListView的Adapter中使用Glide加载图片,图片被拉伸问题
- 使用glide图片加载框架将网络图片展示并在listview中
- 在Windows窗体中如何使用透明图片和标签
- Glide使用和图片变形问题
- 使用glide 时候在listview 或者 grideview 中图片自动拉伸问题
- glide:如何旋转图片
- Glide命令,如何使用glide,glide.lock
- AppWidgets
- zookeeper中Watcher和Notifications
- zookeeper中Watcher和Notifications
- Notifications和NotificationsCenter的使用
- 使用Glide下载图片
- 使用Glide下载图片
- 使用glide加载图片
- spring 路径变量 重定向后出错
- linux中shell条件判断if中的-a到-z的意思
- Ionic2跨平台项目(五)热修复(正儿八经Android)
- springmvc支持json和jsonp类型数据
- qschedule server
- 如何使用Glide在Notifications 和 AppWidgets中load图片
- Android:聊聊我所理解的MVP
- 校招准备系列:每天一道算法题(1)
- MindManager导图美化——边界
- 《收获,不止Oracle》读书笔记(一):索引优化
- Jsoncpp 在各平台的的安装使用
- 浅谈软件测试
- eclipse配置
- MarkDown快速入门