其他分享
首页 > 其他分享> > 安卓通知栏,需手动打开悬浮权限

安卓通知栏,需手动打开悬浮权限

作者:互联网

--------------------------------MainActivity-----------------------------

public class MainActivity extends AppCompatActivity {
    @RequiresApi(api = Build.VERSION_CODES.O)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
           init();
    }

    @RequiresApi(api = Build.VERSION_CODES.O)
    public void init() {
        String channelId = "测试渠道";
        Notification notification = new Notification.Builder(this, channelId)
                .setContentTitle("付朝杰说:")
                .setContentText("我是你爹")
                .setWhen(System.currentTimeMillis())
                .setSmallIcon(R.drawable.tooltip_frame_dark)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.abc_btn_radio_material))   //设置大图标
                .build();
        NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        NotificationChannel channel = new NotificationChannel(channelId, "测试渠道名称", NotificationManager.IMPORTANCE_DEFAULT);
        notificationManager.createNotificationChannel(channel);
        notificationManager.notify(23, notification);
    }
}

--------------------可有可无==========

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

标签:notificationManager,CODES,NotificationManager,悬浮,Notification,安卓,channelId,MainA
来源: https://blog.csdn.net/m0_46126969/article/details/118884509