学习安卓中遇到的问题记录

1 获取string.xml文件里的值(已解决)

String itemName=(String)MainActivity.this.getResources().getText(R.string.item_name);

如果直接引用R.string.item_name,返回的结果是一个长整数

2 用数据线连真机时,如果app不能安装在手机上一个方法是在gradle.properties(Project Properties)文件的最后一行添加代码android.injected.testOnly=false

在这里插入图片描述

3 Android8.0及以上 收不到通知Notification(未解决)

下面代码是IntentService类的子类的onHandleIntent方法中实现的

// 自定义通知ID
int NOTIFICATION_ID = 1;
String channelID = "channel_1";
String channelName = "channel_name_1";
String question = "What is the secret of comedy?";
String answer = "Timing!";
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                    .setSmallIcon(android.R.drawable.sym_def_app_icon)
                    .setContentTitle(question)
                    .setChannelId(channelID)
                    .setContentText(answer)
                    .setPriority(NotificationCompat.PRIORITY_HIGH)
                    .setVibrate(new long[] {0, 1000})
                    .setAutoCancel(true);

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// 此处必须兼容android O设备,否则系统版本在O以上可能不展示通知栏
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
	NotificationChannel channel = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_HIGH);
    notificationManager.createNotificationChannel(channel);
            }
            notificationManager.notify(NOTIFICATION_ID, builder.build());

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
这个判断的代码实现,并没有起到实际效果,真机调试的时候仍然显示不出通知栏

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值