相关疑难解决方法(0)

使用矢量drawable时,通知会引发错误

当我使用向量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.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);
Run Code Online (Sandbox Code Playgroud)

和我build.gradle(仅相关部分):

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 …
Run Code Online (Sandbox Code Playgroud)

java android android-appcompat android-notifications android-support-library

25
推荐指数
1
解决办法
3928
查看次数

如何使用Android支持库23.2将vectorDrawable用作推送通知的图标?setSmallIcon给出错误

我的应用程序在API <v21下,因此我使用Android支持库23.2来管理我的vectorDrawables.

 android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
    }  
 }
Run Code Online (Sandbox Code Playgroud)

所有视图都可以正常执行推送通知的图标:

NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                        .setColor(getResources().getColor(R.color.colorAccent))
                        .setSmallIcon(R.drawable.ic_play_arrow_white_24dp) //ERROR
                        .setContentTitle(getString(R.string.app_name))
                        .setContentText(getString(R.string.playing));
Run Code Online (Sandbox Code Playgroud)

我有错误:

    E/AndroidRuntime: FATAL EXCEPTION: main
android.app.RemoteServiceException: Bad notification posted from package com.ashomok.lullabies: Couldn't create icon: StatusBarIcon(pkg=com.ashomok.lullabiesuser=0 id=0x7f020053 level=0 visible=true num=0 )
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1401)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)

在这种情况下如何使用vectorDrawable?有可能吗?

android android-appcompat android-vectordrawable

4
推荐指数
1
解决办法
1514
查看次数