Suppressing notification from package com.example.mynotification by user request.

在学Android多媒体Notification时,怎么修改代码,手机端就是不弹通知,翻看Log发现如标题错误,经在网上查资料,发现是手机设置问题,打开手机设置,通知与状态栏,通知管理,找到对应的应用,允许该应用谈通知即可。
代码如下:

    private void createNotification() {
        Intent intent = new Intent(this, NotifictionActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel("1", "name", NotificationManager.IMPORTANCE_HIGH);
            mNotificationManager.createNotificationChannel(channel);
            Notification notification = new NotificationCompat.Builder(this, "1")
                    .setContentTitle("我的通知")
                    .setContentText("我通知的内容")
                    .setWhen(System.currentTimeMillis())
                    .setContentIntent(pendingIntent)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_background))
                    .setSmallIcon(R.drawable.ic_launcher_background)
                    .setAutoCancel(true)
                    .build();
            mNotificationManager.notify(1, notification);
        } else {
            Notification notification = new Notification.Builder(this)
                    .setContentTitle("我的通知")
                    .setContentText("我通知的内容")
                    .setWhen(System.currentTimeMillis())
                    .setContentIntent(pendingIntent)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_background))
                    .setSmallIcon(R.drawable.ic_launcher_background)
                    .setAutoCancel(true).build();
            mNotificationManager.notify(1, notification);
        }
    }

参考链接:link

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值