use

3 minutes to quickly use JPush Android Demo

Project introduction JPush:

api 'cn. Jiguang. SDK: jpush: we'
api 'cn. Jiguang. SDK: jcore: 2.1.2'

Copy the code
8.0 Customizing notification bar adaptation
Create notification Channels

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); String id = (id = 1)"111111"; // The name of the notification channel that the user can see. CharSequence name ="notification channel"; // The user can see the description of the notification channel String Description ="notification description"; int importance = NotificationManager.IMPORTANCE_HIGH; NotificationChannel mChannel = new NotificationChannel(id, name, importance); // Configure the notification channel property McHannel.setdescription (description); McHannel. enableLights(If the Android device supports it)true); mChannel.setLightColor(Color.RED); McHannel.setsound (uri.parse ())"android.resource://" + context.getPackageName() + "/raw/msg_sound"),null); // Set the vibration when notifications appear (if android devices support them) McHannel.enablevibration (true); mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); / / finally create the circular channels in the notificationmanager mNotificationManager. CreateNotificationChannel (mChannel); }Copy the code
Stomp pit: set setSound() to the corresponding channel invalid

Key: the channel after creating immutable, can only delete deleteNotificationChannel (String channelId), recreate createNotificationChannel.

McHannel.setsound (uri.parse ())"android.resource://" + context.getPackageName() + "/raw/msg_sound"),null);

Copy the code
 /**
     * Sets the sound that should be played for notifications posted to this channel and its
     * audio attributes. Notification channels with an {@link #getImportance() importance} of at
     * least {@link NotificationManager#IMPORTANCE_DEFAULT} should have a sound.
     *
     * Only modifiable before the channel is submitted to
     * {@link NotificationManager#createNotificationChannel(NotificationChannel)}.Set the sound and audio properties of notification notifications sent to this channel to play. The channel can only be modified before it is committed */ public voidsetSound(Uri sound, AudioAttributes audioAttributes) {
        this.mSound = sound;
        this.mAudioAttributes = audioAttributes;
    }

Copy the code
Aurora message notification callback

	@Override
    public void onReceive(Context context, Intent intent) {
        try {
            Bundle bundle = intent.getExtras();
            Logger.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));

            if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
                String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
                Logger.d(TAG, "[MyReceiver] Registration Id:" + regId);
                //send the Registration Id to your server...

            } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
                Logger.d(TAG, [MyReceiver] receives a custom message pushed down: + bundle.getString(JPushInterface.EXTRA_MESSAGE));
                processCustomMessage(context, bundle);

            } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
                Logger.d(TAG, "[MyReceiver] receives notifications pushed down");
                int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
                Logger.d(TAG, "[MyReceiver] ID that received the notification push down:" + notifactionId);

            } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
                Logger.d(TAG, "[MyReceiver] user clicks on notification"); Intent I = New Intent(context, testActivity.class); i.putExtras(bundle); //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); context.startActivity(i); }else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
                Logger.d(TAG, [MyReceiver] user receives RICH PUSH CALLBACK:+ bundle.getString(JPushInterface.EXTRA_EXTRA)); // In this case, use the JPushInterface.EXTRA_EXTRA content to process the code, such as open a new Activity, open a web page, etc.. }else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
                boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
                Logger.w(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);
            } else {
                Logger.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
            }
        } catch (Exception e) {

        }

    }

Copy the code

Breakpoint debugging:

  • 1. Push notifications down in the entry branch:else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {... }It has been posted to the notification bar before, prompting the system’s default tone and vibration and so on.
  • 2. Custom message, aurora push does not do any processing, parsing and writing their own logic. Enter the branch:else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {... }

Android development push notifications, how to use their own prompt tone?

JPush custom message -Android

Custom prompt tone implementation mode

Notification messages do not support custom sound resources. Push a custom message and display the received custom message on the client. 239 At the same time, implement a custom sound.

Attach:

  • Project Address:

JPushExample project making

  • Project screenshots