1

メソッドを使用しNotificationて背景を表示しています。ServicestartForefround()

  if (notif == null) {

        // Create the pending intent
        Intent intentForeground = new Intent(this, BackgroundLocationService.class)
        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);    
        PendingIntent pendIntent = PendingIntent.getActivity(getApplicationContext(), 0, intentForeground, 0);

        notif = new NotificationCompat.Builder(getApplicationContext())
         .setSmallIcon(R.drawable.ic_launcher)
         .setDefaults(Notification.DEFAULT_ALL)
         .setTicker(getText(R.string.location_service_starting))
         .setOnlyAlertOnce(true)
         .setOngoing(true)
         .setContentIntent(pendIntent)
         .build();
        notif.flags |= Notification.FLAG_NO_CLEAR;
    }
    startForeground(notificationID, notif);

ユーザーに通知が正しく表示され、通知バーを下にスライドすると、ユーザーに通知をタップしてアプリに戻りたいと思います。これどうやってするの?

4

1 に答える 1

1

これを使って

Notification notification = new Notification(R.drawable.logo2, "app is running on the background!", System.currentTimeMillis());

notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

notification.setLatestEventInfo(this, "title", "message!", contentIntent);

this.startForeground(1023, notification);
于 2013-10-08T18:04:03.520 に答える