文档

通知设置相关接口

更新时间:

说明

以下接口调用时,如有回调均为异步执行,且回调不能为空。

设置通知声音

设置推送通知声音文件路径。注意android 8.0以上需要使用NotificationChannel配置声音。

重要
  • 若不调用本接口,默认获取资源ID为R.raw.alicloud_notification_sound的资源文件。

  • 若没有获取到指定声音文件,取设备设置的消息声音。

接口定义

void setNotificationSoundFilePath(String filePath);

参数说明

参数

类型

是否必填

说明

filePath

String

Uri可以解析的字符串

代码示例

        /*
        ASSIGN_NOTIFCE_LARGE_ICON:表示资源文件的名称(不带后缀名),不可以为空,
        DEFAULT_RES_ICON_TYPE:资源文件所在的文件夹:drawable,mipmap...
        PackageName:包名,context.getPackageName()获取
        */
        int assignSoundId = getResources().getIdentifier(ASSIGN_NOTIFCE_SOUND, DEFAULT_RES_SOUND_TYPE, PackageName);
        if (assignSoundId != 0) {
            String defaultSoundPath = DEFAULT_RES_PATH_FREFIX + getPackageName() + "/" + assignSoundId;
            mPushService = PushServiceFactory.getCloudPushService();
            mPushService.setNotificationSoundFilePath(defaultSoundPath);
            Log.i(SETTING_NOTICE, "Set notification sound res id to R." + DEFAULT_RES_SOUND_TYPE + "." + ASSIGN_NOTIFCE_SOUND);
            this.appendConsoleText("Set notification sound res id to R." + DEFAULT_RES_SOUND_TYPE + "." + ASSIGN_NOTIFCE_SOUND);
        } else {
            Log.e(SETTING_NOTICE, "Set notification sound path error, R."
                    + DEFAULT_RES_SOUND_TYPE + "." + ASSIGN_NOTIFCE_SOUND + " not found.");
            this.appendConsoleText("Set notification sound path error, R."
                    + DEFAULT_RES_SOUND_TYPE + "." + ASSIGN_NOTIFCE_SOUND + " not found.");
        }

设置通知栏图标

设置推送通知栏图标资源Bitmap。

重要
  • 若不调用本接口,默认获取ID为R.drawable.alicloud_notification_largeicon的资源文件。

  • 若没有获取到指定图标文件,取App启动图标。

接口定义

void setNotificationLargeIcon(Bitmap icon);

参数说明

参数

类型

是否必填

说明

icon

Bitmap

图标资源Bitmap。

代码示例

  
       int assignLargeIconId = getResources().getIdentifier(ASSIGN_NOTIFCE_LARGE_ICON, DEFAULT_RES_ICON_TYPE, PackageName);
        if (assignLargeIconId != 0) {
            Drawable drawable = getApplicationContext().getResources().getDrawable(assignLargeIconId);
            if (drawable != null) {
                Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
                mPushService = PushServiceFactory.getCloudPushService();
                mPushService.setNotificationLargeIcon(bitmap);
                Log.i(SETTING_NOTICE, "Set notification largeIcon res id to R." + DEFAULT_RES_ICON_TYPE + "." + ASSIGN_NOTIFCE_LARGE_ICON);
                this.appendConsoleText("Set notification largeIcon res id to R." + DEFAULT_RES_ICON_TYPE + "." + ASSIGN_NOTIFCE_LARGE_ICON);
            }
        } else {
            Log.e(SETTING_NOTICE, "Set largeIcon bitmap error, R."
                    + DEFAULT_RES_ICON_TYPE + "." + ASSIGN_NOTIFCE_LARGE_ICON + " not found.");
            this.appendConsoleText("Set largeIcon bitmap error, R."
                    + DEFAULT_RES_ICON_TYPE + "." + ASSIGN_NOTIFCE_LARGE_ICON + " not found.");
        }

设置状态栏图标

设置推送状态栏图标资源id。

重要
  • 若不调用本接口,默认获取R.drawable.alicloud_notification_smallicon的资源文件。

  • 若没有获取到指定资源文件id,取App启动图标。

接口定义

void setNotificationSmallIcon(int iconId);

参数说明

参数

类型

是否必填

说明

iconId

int

图标资源id。

代码示例

        int defaultSmallIconId = getResources().getIdentifier(DEFAULT_NOTICE_LARGE_ICON, DEFAULT_RES_ICON_TYPE, PackageName);
        if (defaultSmallIconId != 0) {
            mPushService = PushServiceFactory.getCloudPushService();
            mPushService.setNotificationSmallIcon(defaultSmallIconId);
            Log.i(SETTING_NOTICE, "Set notification smallIcon res id to R." + DEFAULT_RES_ICON_TYPE + "." + DEFAULT_NOTICE_SMALL_ICON);
            this.appendConsoleText("Set notification smallIcon res id to R." + DEFAULT_RES_ICON_TYPE + "." + DEFAULT_NOTICE_SMALL_ICON);
        } else {
            Log.e(SETTING_NOTICE, "Set notification smallIcon error, R." +
                    DEFAULT_RES_ICON_TYPE + "." + DEFAULT_NOTICE_SMALL_ICON + " not found.");
            this.appendConsoleText("Set notification smallIcon error, R." +
                    DEFAULT_RES_ICON_TYPE + "." + DEFAULT_NOTICE_SMALL_ICON + " not found.");
        }

设置免打扰时段

设置免打扰时间段,过滤所有通知与消息。

重要
  • 免打扰时段仅支持设置一次,多次调用以最后一次调用设置时段为准。

  • SDK版本V2.3.5以下,设置免打扰时间段为00:00-00:00,可取消免打扰功能。

  • 全天免打扰可以设置为“00:00-23:59”。

  • 免打扰时段设置对小米辅助弹窗通知无效。

接口定义

void setDoNotDisturb(int startHour, int startMinute, int endHour, int endMinute, CommonCallback callback);

参数说明

参数

类型

是否必须

说明

startHour

int

免打扰的起始时间(小时),24小时制,取值范围:0-23。

starMinute

int

免打扰起始时间(分钟),取值范围:0-59。

endHour

int

免打扰的结束时间(小时),24小时制,取值范围:0-23。

endMinute

int

免打扰结束时间(分钟),取值范围:0-59。

callback

int

设置免打扰时间段的回调类,设置成功后会回调onSuccess,失败以后会回调onFailed。

代码示例

        
mPushService = PushServiceFactory.getCloudPushService();
       mPushService.setDoNotDisturb(mStartHours, mStartMinutes, mEndHours, mEndMinutes, new CommonCallback() {
            @Override
            public void onSuccess(String s) {
                Log.d(TAG, "设置免打扰成功  " + mStartHours + ":" + mStartMinutes + "~" + mEndHours + ":" + mEndMinutes);
                Toast.makeText(NoDisturbanceActivity.this, "设置免打扰成功", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onFailed(String s, String s1) {
                Log.d(TAG, "设置免打扰失败-- errorcode:" + s + " -- errorMessage:" + s1);
                Toast.makeText(NoDisturbanceActivity.this, "设置免打扰失败", Toast.LENGTH_SHORT).show();
            }
        });

关闭免打扰功能

关闭免打扰功能。

重要
  • 免打扰功能是默认关闭的。

  • 没有对应的开发免打扰功能接口,调用设置免打扰功能时间段功能后自动打开免打扰功能。

  • SDK版本V2.3.5及以上版本支持。

接口定义

void closeDoNotDisturbMode();

代码示例

mPushService = PushServiceFactory.getCloudPushService();
mPushService.closeDoNotDisturbMode();

删除所有通知

删除推送SDK创建的所有通知。厂商通道的通知无法控制删除。

重要
  • 若需要实现精准删除特性通知,可在onNotification回调中获取通知id,自行删除。

  • SDK版本V2.3.7及以上版本支持。

接口定义

void clearNotifications();

代码示例

mPushService = PushServiceFactory.getCloudPushService();
mPushService.clearNotifications();

设置大图标和大图下载失败监控回调

设置大图标和大图下载失败监控回调,感知大图标和大图下载失败的状态和失败原因。

重要
  • SDK版本v3.8.2及以上支持

接口定义

void setLargeIconDownloadListener(OnLargeIconDownloadListener listener);

代码示例

CloudPushService service = PushServiceFactory.getCloudPushService();
service.setLargeIconDownloadListener(new OnLargeIconDownloadListener() {
	@Override
  public void onDownloadLargeIconFailed(String error) {
  }

  @Override
  public void onDownloadBigPictureFailed(String error) {
  }
});

设置通知折叠展示

设置多条通知折叠展示。

重要
  • SDK版本v3.8.2及以上支持

接口定义

void setNotificationShowInGroup(boolean inGroup);

代码示例

CloudPushService service = PushServiceFactory.getCloudPushService();
service.setNotificationShowInGroup(true);
  • 本页导读 (0)
文档反馈