Mc Flurry Posted May 9, 2011 Share Posted May 9, 2011 [solution] Créer un Intent qui qui lance mon application. De la même manière que lorsque qu'on appuie sur la touche home et que l'on reclic sur une application non fermée, on la retrouve en état. Intent intent = new Intent("android.intent.action.MAIN"); intent.setComponent(ComponentName .unflattenFromString("com.mon.package/com.mon.package.activity")); intent.addCategory("android.intent.category.LAUNCHER"); PendingIntent pendingIntent = PendingIntent.getActivity( getApplicationContext(), 0, intent, 0); [/solution] Bonjour, J'ai besoin d'un coup de main au sujet des notifications, je pense que ce problème sera vite résolu car je viens d'apprendre l'histoire des flags pour les notifications et ce doit etre ça la solution. Alors voila, mon application a une structure en TabWidget et possède un service local qui met à jour des données. Lorsqu'une donnée sensible est détectée, l'activity qui gère la mise à jour graphique déclenche une notification. Le problème c'est qu'au clic de cette notification, j'ouvre une deuxième instance de mon appli et non celle qui était déjà lancée. Je me suis aperçut de ça parce que j'ai un bouton qui permet de lancer ou arrêter le service avec en fonction de son état le mot "activé" ou "désactivé" est affiché et donc au clic de cette notif, le mot "désactivé" est affiché ce qui correspond bien à l'état du service car si je clic sur le bouton d'arrêt, un warning s'affiche dans le DDMS. Pouvez vous m'aidez à récupérer la première instance de mon application plutôt que la seconde ? Voila le code de création de notification : public static final int ID_NOTIFICATION = 1991; private void createNotify() { NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.icon, "Information importante !", System.currentTimeMillis()); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, getParent().getIntent(), 0); String titreNotification = "Important : "; String texteNotification = "Cliquez ici pour afficher les informations."; notification.setLatestEventInfo(this, titreNotification, texteNotification, pendingIntent); // Ici les chiffres correspondent à 0sec de pause, 0.2sec de vibration, // 0.1sec de pause, 0.2sec de vibration, 0.1sec de pause, 0.2sec de // vibration notification.vibrate = new long[] { 0, 200, 100, 200, 100, 200 }; notificationManager.notify(ID_NOTIFICATION, notification); } Link to comment Share on other sites More sharing options...
Mc Flurry Posted May 10, 2011 Author Share Posted May 10, 2011 Comme personne n'a d'idée, je réoriente ma question espérant que quelqu'un ait déjà fait ça ! :emo_im_angel: Plutôt que d'envoyer l'utilisateur sur l'application je cherche à afficher un Toast sur l'écran actif, c'est à dire la où se trouve l'utilisateur(dans un jeu, la page paramètre, une autre application, ...). Comme référence il y a Handcent sms qui après une réponse rapide affiche un Taost "réponse rapide envoyée". Je ne demande pas un bout de code tout fait, je cherche plus a être orienté sur la bonne piste, utiliser les bons composants, lire les bons articles, ... Merci d'avance ! Link to comment Share on other sites More sharing options...
BapNesS Posted May 10, 2011 Share Posted May 10, 2011 J'ai utilisé une notification pour une de mes applications. Ce que j'ai fait c'est mettre mon activity principale en singleTop ou singleFirst (je ne sais plus exactement) dans le manifest. C'est pas une solution optimum, j'ai remarqué quelques bugs. Link to comment Share on other sites More sharing options...
Mc Flurry Posted May 10, 2011 Author Share Posted May 10, 2011 Ok, merci, je vais regarder du coté du manifest. Quel genre de bugs tu as rencontré? Link to comment Share on other sites More sharing options...
Mc Flurry Posted May 11, 2011 Author Share Posted May 11, 2011 J'ai essayé ta solution, ça n'a pas marché. J'ai trouvé plusieurs solutions plausibles, j'aimerai savoir laquelle est la plus propre : soit passer un Intent spécifique lors de la création de mon PendingIntent, soit faire un intent-filter dans le manifest, soit utiliser des SharedPreference. Merci. Link to comment Share on other sites More sharing options...
GuiGui35 Posted January 24, 2012 Share Posted January 24, 2012 Salut Mc Flurry, J'ai le même soucis que toi. J'ai essayé ce que tu a noté en solution mais quand je clique sur ma notification rien ne se passe as tu une idée ? //Reference au manager String svcName = Context.NOTIFICATION_SERVICE; notificationManager=(NotificationManager)getSystemService(svcName); //Création de la notification int icon = R.drawable.icon; String tickerText = "Course en cours"; long when = System.currentTimeMillis(); courseEnCours = new Notification(icon,tickerText,when); //Definition du message de notification Context context = getApplicationContext(); CharSequence contentTitle = "FollowMi"; CharSequence contentText = "Temps : "+chrono.getTime(); Intent notificationIntent = new Intent(); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.setComponent(ComponentName.unflattenFromString("fr.eseo.followmi.activity/fr.eseo.followmi.activity.RunningActivity")); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); courseEnCours.setLatestEventInfo(context, contentTitle, contentText, pendingIntent); //Arret de la notification notificationManager.cancel(NOTIFICATION_ID); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.