【问题标题】:Android: When notification is clicked how to come back to same app?Android:点击通知时如何返回到同一个应用程序?
【发布时间】:2013-07-20 06:54:00
【问题描述】:

我知道标题不是解释性的,但让我向您解释一下。我正在做一个 Shoutcast 流媒体广播项目。当应用程序开始流式传输时,通知栏上会出现一个通知,其中包含电台名称和当前歌曲 ID。到目前为止,一切似乎都很正常,但是当用户触摸通知时(当流继续时)它会再次打开应用程序并开始播放另一个流。我希望我已经很好地解释了这个问题,这里是代码:

编辑:

 Hey again, I have just figured out how to make it that way and here is the sample code.


    String ns = Context.NOTIFICATION_SERVICE;
    mNotificationManager = (NotificationManager) getSystemService(ns);

    icon = R.drawable.rbnot;
    CharSequence tickerText = "Radyo Bilkent";
    long when = System.currentTimeMillis();

    notification = new Notification(icon, tickerText, when);
    notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;   
    Intent notificationIntent = new Intent(this, myMain.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    Context context = getApplicationContext();
    CharSequence contentTitle = "Radyo Bilkent";
    CharSequence contentText = currPlayView.getText();

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    mNotificationManager.notify(HELLO_ID, notification);

【问题讨论】:

    标签: android radio shoutcast


    【解决方案1】:

    查看代码。它对我有帮助。

        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(icon, message, when);
         Intent notificationIntent = new Intent(context, HomeActivity.class);
    
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    
        PendingIntent intent = PendingIntent.getActivity(context, 0,
                notificationIntent, 0);
    
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-10
      • 1970-01-01
      • 2019-09-07
      • 1970-01-01
      • 2015-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多