• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

155
Views
No se puede enviar una notificación con un sonido personalizado desde las funciones de la nube

Estoy tratando de configurar un sonido personalizado para mi notificación desde la mensajería en la nube de Firebase, pero no puedo entender por qué no funciona. Creo que estoy configurando correctamente las propiedades del canal de notificación. Pero soy principiante en las funciones de la nube y en las notificaciones de Android.

Mi código de notificación:

 AudioAttributes attributes = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .build(); Uri sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getApplicationContext().getPackageName() + "/" + R.raw.notification_sound); final String CHANNEL_ID = "MAIN"; NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "Main", NotificationManager.IMPORTANCE_HIGH); getSystemService(NotificationManager.class).createNotificationChannel(channel); channel.enableVibration(true); channel.setImportance(NotificationManager.IMPORTANCE_HIGH); channel.setSound(sound, attributes); Notification.Builder notification = new Notification.Builder(this, CHANNEL_ID) .setContentTitle(notificationTitle) .setContentText(notificationBody) .setSmallIcon(R.drawable.app_logo) .setAutoCancel(false); notification.setContentIntent(pendingIntent); NotificationManagerCompat.from(this).notify(1, notification.build());

Mi código de funciones en la nube:

 //import firebase functions modules const functions = require('firebase-functions'); //import admin module const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); const db = admin.firestore(); exports.notifications = functions.firestore.document("notifications/{userId}").onCreate((snap, context) => { const values = snap.data(); //db.collection("notifications").add({name: "notification " + values.token}); const token = values.token; const tokens = [token]; // c4FREruMT42IZpuSBF47X_:APA91bGJvT1ny46JeE5rp9R6M5usSWwUAlIGi88xWknPm4Uh73ybUrOvcaCiHbN3MUfKOzJCKEmvc_qoqpueQyE_7igeG_hVdem2wvX53cPI0X6GPEiQOjyhAIeS8QlgZNNaJstsHl42 // Create a notification const payload = { notification: { channel_id: "Main", sound: "notification_sound.wav", priority: "high", title: values.title, body: values.message, } }; //Create an options object that contains the time to live for the notification and the priority const options = { priority: "high", timeToLive: 60 * 60 * 24 }; //return admin.messaging().sendToTopic("pushNotifications", payload, options); return admin.messaging().sendToDevice(tokens, payload, options); });
almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error