Using Notifications

Steps to use Notification:

 

Add the following code in the main thread's onCreate() ( or elsewhere )

  

 

Intent intent=new Intent(this,ContactsContract.CommonDataKinds.Note.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);  //延迟执行
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification=new NotificationCompat.Builder(this)
        .setContentTitle( "Notification Title" )
        .setContentText( "Notification text" )
        .setWhen(System.currentTimeMillis ()) //When the notification
 is issued.setSmallIcon ( R.mipmap.ic_launcher )
        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
        .setContentIntent(pi)
        .setDefaults(NotificationCompat.DEFAULT_ALL )
         // .setStyle(new NotificationCompat.BigPictureStyle(). bigPicture (BitmapFactory.decodeResource(getResources(), R.drawable.big_image))) //Set the notification style//.setSound(
         Uri.fromFile (new File(xxxx))) //Send a piece of audio at the same time as the notification
         //.setVibrate(new long[]{0,1000,1000,1000}) //Set the vibration for 1s, stop for 1s, and vibrate for 1s to apply for permission VIBRATE
 . setPriority(NotificationCompat. PRIORITY_MAX )
        .build();
manager.notify( 1 , notification);   //parameter (notification id, instance object of Notification)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326190855&siteId=291194637