我从服务器作为位图下载一个图像转换现在我想用这个作为绘制的通知图标来绘制的。但我无法做到这一点。这里是我的code:
I download a image from server as bitmap and convert it to drawable now i want to use this drawable as notification icon. But i am unable to do that. here is my code:
Notification notification = new NotificationCompat.Builder(context)
.setContentTitle(title)
.setContentText(message)
.setContentIntent(intent)
.setSmallIcon(bitmap)
.setWhen(when)
.build();
但图标是一个资源int值,所以当我用它提示错误。任何帮助
but icon is a Resources int value so when i used it it gives error. Any help
编辑:
现在更新我的code,现在我做这样的:
Now i update my code and now i am doing like that :
Notification notification = new NotificationCompat.Builder(context)
.setContentTitle(title)
.setContentText(message)
.setContentIntent(intent)
.setSmallIcon(icon)
.setLargeIcon(bitmap)
.setWhen(when)
.build();
但它给在左边和小图标右侧的大图标。我不希望这样呢为了这个,我删除setSmallIcon线运行我的code,但它不显示我的通知
but it gives large icon on left side and small icon on right side. I don't want this so for this i remove setSmallIcon line and run my code but it not showing me the notifications
推荐答案
如果你看过具体到Notification.Builder你会看到,setSmallIcon(int图标) 需要的在绘制的应用程序包的资源ID使用的。
If you read the developer documents specific to Notification.Builder
you will see that setSmallIcon(int icon)
needs a A resource ID in the application's package of the drawable to use.
下载图像,转换为位图,然后将其设置为 setSmallIcon()
还是想给你一个错误。
Downloading an image, converting to a bitmap and then setting it to the setSmallIcon()
is still going to give you an error.
即使你的位图
转换为绘制对象
这样的,例如:
Even if you were to convert the Bitmap
to a Drawable
like this for instance:
Drawable d = new BitmapDrawable(getResources(), bmpFinal);
但还是想给你一个错误,因为绘制对象
确实不存在在你的应用程序包。
it is still going to give you an error because that Drawable
does not exist in your application package.
唯一可能的解决办法是使用绘制对象
资源存在于你的包
键,将其设置为 setSmallIcon()
方法。典型应用:
The only possible solution is to use a Drawable
resource that exists in your package
and set it to the setSmallIcon()
method. Typical usage:
builder.setSmallIcon(R.drawable.ic_launcher);
另外,在setLargeIcon (位图图标) 需要一个位图实例。而无需进行在当前code任何其他变化(因为你已经有一个位图
),您可以使用,因为它是,如果它符合您的要求。
Alternatively, the setLargeIcon (Bitmap icon)
requires a Bitmap instance. Without having to make any additional changes in your current code (since you already have a Bitmap
), you can use that as it is, if it fits your requirement.
如果没有,则pretty的多少必须使用绘制对象
的资源,已经是present中的绘制一个
文件夹。
If not, you pretty much have to use a Drawable
resource that is already present in one of the drawable
folders.
相关推荐
最新文章