2011-09-28 2 views
0

J'essaie de jouer un son, et de clignoter le rétro-éclairage du téléphone Android en utilisant le gestionnaire de notification. J'ai utilisé le code suivant. Toutes les autorisations requises sont présentes dans le fichier manifeste. Mais je ne suis pas sûr pourquoi cela ne donne aucune notification dans l'émulateur ou dans l'appareil (htc wildfire). Si vous connaissez une solution possible s'il vous plaît faites le moi savoirLa notification ne fonctionne pas (htc wildfire)

XYNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 
     int NOTFICATION_ID = 1331; 
     Notification notifyDetails = new Notification(); 
     notifyDetails.icon = R.drawable.icon12; 
     notifyDetails.tickerText = "Message Received!!!"; 
     notifyDetails.when = System.currentTimeMillis(); 

     notifyDetails.vibrate = new long[] {0,1000,1000,1000,1000,1000,1000,1000}; //vibrate; 

     Intent notifyIntent = new Intent(this, XYReceiverAppActivity.class); 

     PendingIntent pIntent = PendingIntent.getActivity(this, 0,notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK); 

     CharSequence contentTitle = "XYs Notification"; 
     CharSequence contentText = "Get back to XY HOME screen by clicking me"; 


     notifyDetails.setLatestEventInfo(this, contentTitle, contentText, pIntent); 

     Uri xysound = Uri.parse("android.resource://" + getPackageName() +"/"+ "soundxy"); 

     notifyDetails.ledARGB = Color.BLUE; 
     notifyDetails.ledOnMS = 10000; 
     notifyDetails.ledOffMS = 1000; 
     notifyDetails.flags |= Notification.FLAG_SHOW_LIGHTS; 
     notifyDetails.sound = xysound; 



     XYNotificationManager.notify(NOTFICATION_ID, notifyDetails); 

Le dispositif ne vibre pas non plus il n'y a aucune alerte sonore. La lumière LED est la même. comment envoyer la notification?

+0

une icône persistante de la barre d'état. mais rien d'autre ... – drulabs

Répondre

1

Voici un code que j'utilise dans l'un de mes programmes, il a toujours travaillé ...

 int icon = R.drawable.alerte; 
     CharSequence tickerText = getString(R.string.lieuproche); 
     long when = System.currentTimeMillis(); 
     Notification notification = new Notification(icon, tickerText, when); 
     Intent intent = new Intent(getApplicationContext(), 
       ActivityToLaunch.class); 

     notification.setLatestEventInfo(
       MainActivity.this, 
       "title", 
       "action", PendingIntent.getActivity(
         this.getBaseContext(), 0, intent, 
         PendingIntent.FLAG_CANCEL_CURRENT)); 
     notification.flags |= Notification.FLAG_AUTO_CANCEL; 
     notification.defaults |= Notification.DEFAULT_SOUND; 
     notification.defaults |= Notification.DEFAULT_LIGHTS; 
     notificationManager.notify(0, notification); 
+0

Merci pour votre réponse Setsuki. Pouvez-vous s'il vous plaît me dire ce qui est "notificationShowing" ??? – drulabs

+0

Oups, désolé pour celui-là, un morceau de code que j'aurais dû supprimer. C'est juste un booléen de savoir si j'ai déjà une notification, j'en ai besoin pour plus tard, ce n'est pas important. – Setsuki

+0

Merci mon pote ... Permettez-moi de vérifier ce code. – drulabs

Questions connexes