2014-07-14 4 views
8

Ricevo correttamente la notifica push GCM. Ora voglio aggiungere un file audio personalizzato invece del suono predefinito. Ho provato con Uri da fileAndroid GCM PushNotification - Aggiungi aggiungi file audio personalizzato nell'app

: ///res/raw/pop.mp3

in

Notification.DEFAULT_SOUND;

ma non successo. Si prega di condividere se si dispone di una soluzione migliore.

mio GCMIntentService.java codice metodo è al di sotto -

/** 
* Issues a notification to inform the user that server has sent a message. 
*/ 
private static void generateNotification(Context context, String message) { 

    System.out.println("Called generateNotification>>>>>>>>>>>>>"+message); 
    NotificationManager notificationManager = (NotificationManager) context 
      .getSystemService(Context.NOTIFICATION_SERVICE); 
    // Notification notification = new Notification(icon, message, when); 

    String title = context.getString(R.string.app_name); 

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
      context) 
      .setSmallIcon(R.drawable.app_icon) 
      .setContentTitle(title) 

      .setStyle(
        new NotificationCompat.BigTextStyle().bigText(message)) 
      .setContentText(message); 

    Intent notificationIntent = new Intent(context, 
      SplashActivity.class); 
    PendingIntent intent = PendingIntent.getActivity(context, 0, 
      notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); 

    mBuilder.setContentIntent(intent); 

    Notification notification = mBuilder.build(); 
    notification.flags |= Notification.FLAG_AUTO_CANCEL; 

    notification.defaults |= Notification.DEFAULT_SOUND; 
    notification.defaults |= Notification.DEFAULT_VIBRATE; 


    notificationManager.notify(0, notification); 



} 

risposta

15

Per aggiungere personalizzato suono aggiungere questo

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.pop); 

cioè Nel modifica del codice

notification.defaults |= Notification.DEFAULT_SOUND; 
notification.defaults |= Notification.DEFAULT_VIBRATE; 

a

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" +R.raw.pop); 
notification.defaults |= Notification.DEFAULT_VIBRATE;