Notification의 구현 설정 알림 음악.setSound 2017.06.06

오늘 notification을 연습할 때 설정을 하고 알림을 터치할 때 알림을 설정하는 음악을 생각하면 음악 오디오 파일 자원에 대한 인용(Android 자원 파일의 URI 인용)이 발생합니다.
Notification의 실현은 매우 간단하다. 절차는 다음과 같다.
1. Notification Manager:
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

2. 하나의 통지를 실례화한다.
4
                        Notification notification = new NotificationCompat.Builder(MainActivity.this)
                                .setContentTitle("      ")
                                .setContentText("        ")
                                .setSmallIcon(R.mipmap.ic_launcher_round)
                                .setWhen(System.currentTimeMillis())
//    (Bitmap),setLargeIcon         ,   BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
                                .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
                                //    
                                .setContentIntent(pi)
                                .setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.rae))
                                .setAutoCancel(true)
                                .build();
3, Notification 표시
notificationManager.notify(1,notification);

위의 코드는 우리가 Notification의 알림 설정을 실현했고 Notification을 클릭하는 촉발 시간, 즉 Pending Intent를 실현했다.
또한 setSond 설정 알림 음악을 실현했습니다. 이 곳에서 우리의 자원 인용 문제를 인용합니다.
set Sound의 매개 변수는 Uri로 전송됩니다. 그러면 자원 디렉터리에 있는 오디오를 어떻게 얻을 수 있습니까? 다음과 같습니다.
Apk 의 assets 디렉토리에 직접 액세스하면 AssetManager 클래스를 사용할 수 있지만 res 의 raw 디렉토리에 액세스합니다.
"android.resource://" + getPackageName() + "/" + R.raw.rae))

android.resource://내부 자원을 인용합니다. 뒤에 있는 getPackageName도 저희 프로젝트의 패키지 이름일 수 있습니다. 마지막으로 저희 자원 인덱스만 있으면 됩니다.
마지막으로 우리 비트맵 이야기 하기;Bitmap은 비트맵입니다. 비트맵은 벡터 맵에 상대적이고 비트맵의 참조는 다음과 같습니다.
BitmapFactory.decodeResource(getResource(), R.......), 그림 인덱스

좋은 웹페이지 즐겨찾기