Java 通知在使用矢量绘图时引发错误
当我使用vector drawable设置通知的小图标时,会出现以下异常: android.app.RemoteServiceException:从包com.qbes.xxx发布的错误通知:无法创建图标:StatusBarIcon(pkg=com.qbes.xxxuser=0 id=0x7f020082 level=0 visible=true num=0) 这是我的密码:Java 通知在使用矢量绘图时引发错误,java,android,android-support-library,android-notifications,android-appcompat,Java,Android,Android Support Library,Android Notifications,Android Appcompat,当我使用vector drawable设置通知的小图标时,会出现以下异常: android.app.RemoteServiceException:从包com.qbes.xxx发布的错误通知:无法创建图标:StatusBarIcon(pkg=com.qbes.xxxuser=0 id=0x7f020082 level=0 visible=true num=0) 这是我的密码: mNotificationBuilder = new android.support.v4.app.Notificatio
mNotificationBuilder = new android.support.v4.app.NotificationCompat.Builder(this)
.setDefaults(android.support.v4.app.NotificationCompat.DEFAULT_LIGHTS)
.setSound(null)
.setSmallIcon(R.drawable.logo_white)
.setColor(getResources().getColor(R.color.colorPrimary))
.setCategory(android.support.v4.app.NotificationCompat.CATEGORY_PROGRESS)
.setContentTitle("Trip in Progress...")
.setAutoCancel(false)
.setProgress(0, 0, progress)
.setOngoing(true)
.setPriority(android.support.v4.app.NotificationCompat.PRIORITY_MAX)
.setOnlyAlertOnce(true)
.setContentIntent(pendingIntent);
mNotificationBuilder.setContentText(body);
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification note = mNotificationBuilder.build();
mNotificationManager.notify(Constants.NOTIFICATION_ID_Dash, note);
和我的build.gradle
(仅相关部分):
PS:当我使用png或jpg图像可绘制时,代码运行良好,但当使用矢量可绘制时代码中断
我已经找了一整天了,但找不到适合我的东西。任何想法。您正在使用矢量可绘制支持包。这很好,但这只适用于你的应用程序。在API级别21之前,平台不知道如何使用矢量可绘制文件,对于
通知
,平台是呈现资源的平台
您可以将向量自己绘制到由
位图
支持的画布
,然后在通知中使用该位图
。或者,您一般可以使用vector backport库,但对于少量的通知
图标,请为它们生成PNG文件,并在旧设备上使用它们,较新的设备将使用vector drawables,而较旧的设备将使用PNG。您正在测试哪一版本的Android?一般来说,您使用的是support library backport,但我认为这不适用于通知
,因为平台是试图使用资源的平台。我正在API 19上进行测试。我会检查其他版本中是否存在此问题。我检查了sdk版本,并避免调用setSmallIcon来检查api版本21之前的版本。还有一件事。小图标的首选dp大小是多少?@ShahiM:24dp
,我想。当PNG用于旧设备时,为什么还要再次使用向量?!启动图标也一样吗?@SeshuVinay:是的,因为你不能假设主屏幕实现知道如何使用矢量绘图。我试了一下,遇到了各种各样的问题。
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.qbes.xxx"
minSdkVersion 16
targetSdkVersion 22
versionCode 720
versionName "0.7.20"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
}