我想将位图图像显示为通知,但下面的代码在我出错的地方不起作用我无法找到我正在以位图形式从 url 获取图像但无法显示。
我在 NotiIcon 变量中获取位图图像,它是位图类型。我添加了获取位图图像。
提前致谢 。
public static void ShowNotification()
{
AsyncTask<Void, Void, Void> t = new AsyncTask<Void, Void, Void>(){
protected Void doInBackground(Void... p) {
String NS = Context.NOTIFICATION_SERVICE;
/* String dtitle = Title;
String dbody = body; */
Intent notificationIntent1 =new Intent(appContext, ChromeTestActivity.class);
PendingIntent contentIntent1 = PendingIntent.getActivity(appContext, 0, notificationIntent1, 0);
NotificationManager mNm = (NotificationManager) appContext.getSystemService(NS);
Notification.Builder builder = new Notification.Builder(appContext);
builder.setContentIntent(contentIntent1).setLargeIcon(NotiIcon)
.setWhen(System.currentTimeMillis())
.setAutoCancel(false)
.setContentTitle(Title)
.setContentText(body);
Notification n = builder.getNotification();
mNm.notify(NOTIFICATION_ID, n);
textTitle.setText(Title);
textBody.setText(body);
textTitle.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.v(LOGTAG, "Inside NotificationUIManager handleButtonClick");
}
});
textBody.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.v(LOGTAG, "Inside NotificationUIManager handleButtonClick");
}
});
return null;
}
};
t.execute();
}
public static Bitmap DecodeIconUrl(String paramString1)
{
NotiIcon = null;
try
{
URL iconurl = new URL(paramString1);
URLConnection conn = iconurl.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
NotiIcon = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
}
catch(IOException e){
}
return NotiIcon;
}