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

--------------------------------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"/>
上一篇:不将文件打开进行编辑(echo)


下一篇:定时任务(crontab)