Android设置图标以通知

时间:2015-04-18 07:38:53

标签: java android icons

我试图在我的android app上设置图标图片(.bmp)但由于某种原因它在notifyObj.setLargeIcon(BitmapFactory.decodeResource(R.drawable.icon, NOTIFY_ME_ID));

给我错误

就像.icon是int类型,但它是一个图像类型bmp。

public void triggerNotification(View v) {
//Notification notifyObj=new Notification(R.drawable.whatsappicon2,      "Notification message!",System.currentTimeMillis());
  Context context = getApplicationContext();   
    PendingIntent i=PendingIntent.getActivity(this, 0, new Intent(this, NotifyActivity.class), 0);
    Notification.Builder notifyObj = new Notification.Builder(this)
    .setContentTitle("content title")
    .setContentText("http://android-er.blogspot.com/")
    .setTicker("Notification!")
    .setWhen(System.currentTimeMillis())
    .setContentIntent(i)
    .setDefaults(Notification.DEFAULT_SOUND)
    .setDefaults(Notification.DEFAULT_VIBRATE)
    .setAutoCancel(false)
    .setSmallIcon(R.drawable.whatsappicon2)
    .setWhen(System.currentTimeMillis());
 Notification mynotification1 = notifyObj.getNotification();
 notifyObj.setLargeIcon(BitmapFactory.decodeResource(R.drawable.icon, NOTIFY_ME_ID));   
notifyObj.setNumber(++countmsg);
countconv=convnum(countmsg);

notifyMgr.notify(NOTIFY_ME_ID, mynotification1);
}

1 个答案:

答案 0 :(得分:0)

试试这个,这是将资源图像转换为Android位图的好方法:

Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.large_icon);
notBuilder.setLargeIcon(largeIcon);