0%
使用通知
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button sendNotice = findViewById(R.id.send_notice); Intent intent = new Intent(this, NotificationActivity.class); PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0); sendNotice.setOnClickListener(v ->{ NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Notification notification = new NotificationCompat.Builder(this).setContentTitle("Content Title") .setContentText("Content Text") .setWhen(System.currentTimeMillis()) .setSmallIcon(R.mipmap.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setContentIntent(pi) .setAutoCancel(true) .build(); manager.notify(1, notification); }); }
|
进阶
1 2 3 4
| .setSound(Uri.fromFile(new File("/system/media/audio/notifications/Antimony.ogg"))) .setVibrate(new long[]{0, 500, 500, 500}) .setLights(Color.GREEN, 1000, 1000)
|