1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
private void initCloudChannel(Context applicationContext) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); String id = "1"; CharSequence name = "测试渠道名"; String description = "测试渠道描述"; int importance = NotificationManager.IMPORTANCE_HIGH; NotificationChannel mChannel = new NotificationChannel(id, name, importance); mChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); mChannel.setDescription(description); mChannel.enableLights(true); mChannel.setLightColor(Color.RED); mChannel.setSound(Uri.parse("android.resource://" + BaseUtil.getPackageInfo(BaseUtil.getApp()).packageName + "/" + R.raw.hint_four), null); mChannel.enableVibration(true); mChannel.setVibrationPattern(new long[]{100, 200 , 300, 400, 500, 400, 300, 200, 400}); if (mNotificationManager != null) { mNotificationManager.createNotificationChannel(mChannel); } } PushServiceFactory.init(applicationContext); CloudPushService pushService = PushServiceFactory.getCloudPushService(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { pushService.setNotificationSoundFilePath(Uri.parse("android.resource://" + BaseUtil.getPackageInfo(BaseUtil.getApp()).packageName + "/" + R.raw.hint_four).toString()); } pushService.register(applicationContext, new CommonCallback() { @Override public void onSuccess(String response) { Log.d(TAG, "init cloudchannel success"); pushService.turnOnPushChannel(null); } @Override public void onFailed(String errorCode, String errorMessage) { Log.d(TAG, "init cloudchannel failed -- errorcode:" + errorCode + " -- errorMessage:" + errorMessage); } }); }
|