Notification sound to modify the default ringtone

Recently, there was a demand: the user requested to change the notification tone of the mobile phone to the default mobile phone ringtone. After a long time, the change was finally made, and a record was made.

code show as below:

 /**
     * 启动通知
     */
    public void showNotification(CharSequence title, CharSequence content, Class<?> jumpActivity) {
        mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        // 标题
        CharSequence contentTitle = title;
        // 内容
        CharSequence contentText = content;
        Intent intentDetail = new Intent(context, jumpActivity);
        /**
         * android api15以后用以下方法代替
         */
        Notification.Builder builder1 = new Notification.Builder(context);
        builder1.setSmallIcon(R.mipmap.ic_launcher); //设置图标
        builder1.setTicker("显示第二个通知");
        builder1.setContentTitle(contentTitle); //设置标题
        builder1.setContentText(contentText); //消息内容
        builder1.setWhen(System.currentTimeMillis()); //发送时间
        builder1.setAutoCancel(true);//打开程序后图标消失
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intentDetail, PendingIntent.FLAG_UPDATE_CURRENT);
        builder1.setContentIntent(pendingIntent);
        Notification notification1 = builder1.getNotification();
        Uri uri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE) ;
        notification1.sound=uri;
        mNotificationManager.notify(124, notification1); // 通过通知管理器发送通知
    }

 

Guess you like

Origin blog.csdn.net/u010256329/article/details/88414311