Android(安卓)O使用通知遇到的坑
今天在Android 8.0上使用通知的时候,遇到一个问题,只要一发出通知,就弹出系统界面已停止运行的弹框。如下图所示
代码如下:
NotificationChannel chan1 = new NotificationChannel(PRIMARY_CHANNEL, "cd", NotificationManager.IMPORTANCE_DEFAULT);chan1.setLightColor(Color.GREEN);chan1.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);notificationManager.createNotificationChannel(chan1);builder = new Notification.Builder(getApplicationContext(), PRIMARY_CHANNEL) .setContentTitle("ds") .setContentText("fa") .setSmallIcon(R.mipmap.ic_launcher) .setAutoCancel(true);notificationManager.notify(NOTI_ID, builder.build());
Log显示如下:
I/DynamiteModule: Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:19
I/DynamiteModule: Selected remote version of com.google.android.gms.maps_dynamite, version >= 19
I/Google Maps Android API: Google Play services client version: 11400000
I/Google Maps Android API: Google Play services package version: 11745036
I/zygote64: Do full code cache collection, code=124KB, data=85KB
I/zygote64: After code cache collection, code=122KB, data=70KB
I/zygote64: Do partial code cache collection, code=124KB, data=73KB
I/zygote64: After code cache collection, code=124KB, data=73KB
I/zygote64: Increasing code cache capacity to 512KB
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/Choreographer: Skipped 77 frames! The application may be doing too much work on its main thread.
W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found.
I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4
I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 4
W/zygote64: Verification of void j.
刚开始根据log在google上搜了半天,没半点眉目,之后很无奈的一行一行的注释掉代码排除问题所在。结果发现
builder = new Notification.Builder(getApplicationContext(), PRIMARY_CHANNEL) .setContentTitle("ds") .setContentText("fa") .setSmallIcon(R.mipmap.ic_launcher) .setAutoCancel(true);把上面红色部分注释掉,正常,取消注释就崩掉,那么这就是问题所在了。把图片复制到drawable-xx文件夹下,
setSmallIcon(R.mipmap.ic_launcher)改为 setSmallIcon(R.drawable.ic_launcher)就正常了。虽然问题解决了,但是依然很困惑。drawable和
mipmap在使用上应该是一样的,只是mipmap在性能上做了优化。希望有知道的能解释一下
更多相关文章
- Android(安卓)EditText OnTouchListener事件重复
- ListView下拉加载一(分页)
- android 指纹识别 之 BiometricPrompt的简单使用教程
- android native ndk崩溃定位
- Android双击返回键退出程序代码
- Android-NDK开发之基础--Android(安卓)JNI实例代码(四)-- JNI中
- android 特效之一 电视机关闭特效
- Android屏蔽通知栏的下拉
- Android(安卓)Intent.createChooser()