Notification의 구현 설정 알림 음악.setSound 2017.06.06
3107 단어 안드로이드 모바일 개발
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.......), 그림 인덱스
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Android는 Bluetooth와 Bluetooth Low Energy를 사용하여 블루투스와 블루투스 4.0, 일행 코드를 구현합니다.구글 중국 API 링크:https://developer.android.google.cn/guide/topics/connectivity/bluetooth.html일반적인 블루투스 사용을 지원합니다.저전력 블루투스 사용...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.