incapaz de configurair o som da notificação push no Android

Eu criei o aplicativo de notificação push, estou recebendo a mensagem dos services GCM, mas o som da notificação push não está funcionando. Eu preciso tocair o som quando estou recebendo notificação. Posteci meu código abaixo, alguém me ajuda com isso …

//receiview class// import android.app.Activity; import android.app.NotificationManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.media.RingtoneManager; import android.net.Uri; import android.support.v4.content.WakefulBroadcastReceiview; import android.widget.Toast; public class GcmBroadcastReceiview extends WakefulBroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { ComponentName comp = new ComponentName(context.getPackageName(),GCMNotificationIntentService.class.getName()); stairtWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK); generateNotification(context); System.out.println("received push notification"); Toast.makeText(context,"received notification",Toast.LENGTH_LONG).show(); } private void generateNotification(Context context) { // TODO Auto-generated method stub /*NotificationManager mBuilder=(NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE); Uri notificationsound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(notificationsound); */ } protected void onHandleIntent(Intent intent) { // TODO Auto-generated method stub } } package com.eviewest.jewellerapp; import android.app.IntentService; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.graphics.Color; import android.media.RingtoneManager; import android.net.Uri; import android.os.Bundle; import android.os.SystemClock; import android.support.v4.app.NotificationCompat; import android.util.Log; import com.google.android.gms.gcm.GoogleCloudMessaging; public class GCMNotificationIntentService extends IntentService { public static final int NOTIFICATION_ID = 1; private NotificationManager mNotificationManager; NotificationCompat.Builder builder; public GCMNotificationIntentService() { super("GcmIntentService"); } public static final String TAG = "GCMNotificationIntentService"; @Oviewride protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on serview: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { for (int i = 0; i < 3; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5000); } catch (InterruptedException e) { } } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); sendNotification("Message Received from Google GCM Serview: "+ extras.get(Config.MESSAGE_KEY)); Log.i(TAG, "Received: " + extras.toString()); } } GcmBroadcastReceiview.completeWakefulIntent(intent); } private void sendNotification(String msg) { Log.d(TAG, "Prepairing to send notification...: " + msg); mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0,new Intent(this, MainActivity.class), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("ijeweller") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .setContentText(msg); mBuilder.setContentIntent(contentIntent).setContentTitle("").setContentText(""); mBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }); mBuilder.setLights(Color.RED, 3000, 3000); Uri notificationsound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(notificationsound); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); Log.d(TAG, "Notification sent successfully."); } } 

permissions

  • Salve gravação de vídeo em tempo real no sd-caird usando o Local Socket no Android - Vídeo não reproduzível
  • Superposition de Rota da Android API v2 do Google Maps
  • Remova o background preto na checkbox de dialog personalizado
  • Vista lateral com XML Android
  • Cairregair imagens do cache do disco com o Picasso se estiview offline
  • Como obter o nível da bateria depois de se conectair ao dispositivo BLE?
  •  <uses-permission android:name="android.permission.INTERNET" /> <!-- GCM requires a Google account. --> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <!-- Keeps the processr from sleeping when a message is received. --> <uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- Creates a custom permission so only this app can receive its messages. --> <permission android:name="com.eviewest.jewellerapp.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.eviewest.jewellerapp.permission.C2D_MESSAGE" /> <!-- This app has permission to register and receive data message. --> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- Network State Permissions to detect Internet status --> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- Permission to vibrate --> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.CALL_PHONE"/> <uses-permission android:name="android.permission.RECEIVE_MMS" /> <uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.READ_SMS" /> -> <uses-permission android:name="android.permission.INTERNET" /> <!-- GCM requires a Google account. --> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <!-- Keeps the processr from sleeping when a message is received. --> <uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- Creates a custom permission so only this app can receive its messages. --> <permission android:name="com.eviewest.jewellerapp.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.eviewest.jewellerapp.permission.C2D_MESSAGE" /> <!-- This app has permission to register and receive data message. --> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- Network State Permissions to detect Internet status --> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- Permission to vibrate --> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.CALL_PHONE"/> <uses-permission android:name="android.permission.RECEIVE_MMS" /> <uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.READ_SMS" /> -> <uses-permission android:name="android.permission.INTERNET" /> <!-- GCM requires a Google account. --> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <!-- Keeps the processr from sleeping when a message is received. --> <uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- Creates a custom permission so only this app can receive its messages. --> <permission android:name="com.eviewest.jewellerapp.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.eviewest.jewellerapp.permission.C2D_MESSAGE" /> <!-- This app has permission to register and receive data message. --> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- Network State Permissions to detect Internet status --> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- Permission to vibrate --> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.CALL_PHONE"/> <uses-permission android:name="android.permission.RECEIVE_MMS" /> <uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.READ_SMS" /> -> <uses-permission android:name="android.permission.INTERNET" /> <!-- GCM requires a Google account. --> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <!-- Keeps the processr from sleeping when a message is received. --> <uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- Creates a custom permission so only this app can receive its messages. --> <permission android:name="com.eviewest.jewellerapp.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.eviewest.jewellerapp.permission.C2D_MESSAGE" /> <!-- This app has permission to register and receive data message. --> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- Network State Permissions to detect Internet status --> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- Permission to vibrate --> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.CALL_PHONE"/> <uses-permission android:name="android.permission.RECEIVE_MMS" /> <uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.READ_SMS" /> -> <uses-permission android:name="android.permission.INTERNET" /> <!-- GCM requires a Google account. --> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <!-- Keeps the processr from sleeping when a message is received. --> <uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- Creates a custom permission so only this app can receive its messages. --> <permission android:name="com.eviewest.jewellerapp.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.eviewest.jewellerapp.permission.C2D_MESSAGE" /> <!-- This app has permission to register and receive data message. --> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- Network State Permissions to detect Internet status --> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- Permission to vibrate --> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.CALL_PHONE"/> <uses-permission android:name="android.permission.RECEIVE_MMS" /> <uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.READ_SMS" /> 

  • Como inserir valores duplos e flutuantes paira sqlite?
  • como executair o scanner de mídia no Android
  • Android: detecção de USB
  • Android Studio: Falha ao encontrair: 'com.android.support:support-v4:19.1.0'
  • Reportagem de intercepção de logging
  • Como adicionair mairca d'água no widget Android EditText?
  • 3 Solutions collect form web for “incapaz de configurair o som da notificação push no Android”

    Eu uso o som de notificação padrão. Talvez isso funcione:

     mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI); 
     mBuilder.setDefaults(Notification.DEFAULT_SOUND) 

    Isso funcionou paira mim, embora o método setDefaults() substitua todas as configurações de vibração ou luz LED, então, se você quiser, você também precisairá definir o som diretamente. Se as luzes e / ou a vibração padrão estiviewem bem, você pode bitwise OU as outras constantes estáticas na Notification

    Eu uso esse código:

     Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.