기본 소리 알림을 사용 하시겠습니까?
Notification.Builder 를 사용하여 알림 을 작성합니다. 이제 기본 소리 알림을 다음과 함께 사용하고 싶습니다.
builder.setSound(Uri sound)
그러나 기본 알림의 Uri는 어디에 있습니까?
RingtoneManager 를 사용하여 다음과 같이 기본 알림 Uri를 얻습니다.
Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
builder.setSound(uri);
builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
잘 작동합니다
하는 두 가지 사용 옵션 Default Notification Sound
은 다음 과 가변.
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
또는 RingtoneManager 클래스 사용 :
mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
이 모든 방법이 작동합니다.
mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
사용할 수 있습니다.
Uri uri = Uri.parse(PreferenceManager.getDefaultSharedPreferences(this).
getString("pref_tone", "content://settings/system/notification_sound"));
mBuilder.setSound(uri);
시스템 기본 알림
Uri uri = RingtoneManager.getDefaultUri (RingtoneManager.TYPE_NOTIFICATION);
맞춤 알림
Uri customSoundUri = Uri.parse ( "android.resource : //"+ getPackageName () + "/"+ R.raw.twirl);
알림 음의 출처 ( "twirl"로 이름을 바꾸고 res-> raw 폴더에 배치)
https://notificationsounds.com/message-tones/twirl-470
알림 빌더 :
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notificaion_icon)
.setContentTitle("Title here")
.setContentText("Body here")
.setSound(defaultSoundUri)
.setAutoCancel(true);
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(id, mBuilder.build());
누군가가 여전히 필요하다면, 이것은 소리와 진동으로 절대 작동합니다.
Context context = getApplicationContext();
long[] vibrate = new long[] { 1000, 1000, 1000, 1000, 1000 };
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context,
0, notificationIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
Resources res = context.getResources();
Notification.Builder builder = new Notification.Builder(context);
builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.notif)
.setTicker("lastWarning")
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setVibrate(vibrate)
//.setContentTitle(res.getString(R.string.notifytitle))
.setContentTitle("Notification")
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
//.setContentText(res.getString(R.string.notifytext))
.setContentText("Notification text");
// Notification notification = builder.getNotification(); // until API 16
Notification notification = builder.build();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFY_ID, notification);
예를 들어 진동 변경을 선택하여 새 긴으로 진동 [] {0,0,0,0,0}; 다른 경우에는 소리로 할 수 있습니다.
참고 URL : https://stackoverflow.com/questions/11271991/uri-to-default-sound-notification
'IT' 카테고리의 다른 글
django 앱에 파비콘을 표시해야합니까? (0) | 2020.07.11 |
---|---|
Android ListView 헤더 (0) | 2020.07.11 |
임시 SSH 터널을 설정하기위한 Bash 펼쳐보기 (0) | 2020.07.11 |
“return list.sort ()”가 목록이 아닌 None을 반환하는 이유는 무엇입니까? (0) | 2020.07.11 |
전체 오류 메시지를 표시하도록 web.config 파일을 설정하는 방법 (0) | 2020.07.11 |