그래서 저는 Android 앱을 개발 중이며 Firebase에서 오는 알림을받습니다. 이를 받기 위해서는 문제가 없지만 문제는 앱이 열려 있고 메인 화면에있는 동안 사용자의 장치에 표시되는 방식 만 사용자 지정할 수 있다는 것입니다. 따라서 앱이 닫히면 알림에 아이콘, 소리, 진동이 없습니다.
NotificationCompat 클래스에서 내가 원하는 것을 이미 변경했지만 이러한 구성은 앱이 닫혀있는 동안에는 적용되지 않는다는 것을 이해해야합니다. 아래 코드를 참조하십시오.
그래서 제가 이해할 수 있었으면 좋겠고 거기있는 누군가가 무슨 일이 일어나고 있는지 말할 수 있다면 정말 감사 할 것입니다.
알림을받는 클래스
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
notifyuer(remoteMessage.getFrom(), remoteMessage.getNotification().getBody());
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
}
public void notifyuer(String from, String notification){
MyNotificationManager myNotificationManager = new MyNotificationManager(getApplicationContext());
myNotificationManager.showNotificacao(from,notification, new Intent(getApplicationContext(),MainActivity.class));
}
사용자 정의 알림 클래스
public class MyNotificationManager {
private Context context;
public MyNotificationManager(Context context){
this.context = context;
}
public void showNotificacao(String from, String notification, Intent intent){
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 /* Request code */, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
//long[] vibrar = {150,400,150,800};
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
Notification mNotification = notificationBuilder
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.logocinza64)
.setContentTitle("S.I.C.C.")
.setContentText(notification)
.setAutoCancel(true)
.setVibrate(new long[]{ 100, 250, 100, 500, 800})
.build();
mNotification.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
try{
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone toque = RingtoneManager.getRingtone(context,defaultSoundUri);
toque.play();
}catch (Exception e){
}
notificationManager.notify(0 /* ID of notification */, mNotification);
}
}
알림을 맞춤 설정하려면 firebase 콘솔을 사용하면 안됩니다.
자세한 내용은 여기를 참조하십시오.
이미지에 대한 아래 코드도 추가해야합니다.
Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);
notificationBuilder.setLargeIcon(largeIcon)
두 번째는 알림 사운드에 관한 것입니다. 사용자 정의 사운드를 원한다면 다음을 사용하십시오.
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notifysnd);
notificationBuilder.setSound(uri);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다