Alexander R.
- Forum-Beiträge: 1.148
03.06.2011, 14:39:47 via Website
03.06.2011 14:39:47 via Website
Hallo,
über folgenden Code erstelle ich eine Statusbar-Notification:
Nun starte ich diese als Service in meiner Hauptanwenung:
Wie kann ich es nun realisieren, dass wenn ich die App starte, nur die Notification angezeigt wird (in der Statusbar) und nicht noch zusätzlich das MainWindow?
über folgenden Code erstelle ich eine Statusbar-Notification:
1String ns = Context.NOTIFICATION_SERVICE;
2NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
3
4int icon = R.drawable.notification_icon;
5CharSequence tickerText = "Hello";
6long when = System.currentTimeMillis();
7Notification notification = new Notification(icon, tickerText, when);
8
9Context context = getApplicationContext();
10CharSequence contentTitle = "My notification";
11CharSequence contentText = "Hello World!";
12Intent notificationIntent = new Intent(this, Test.class);
13PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
14notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
15
16notification.flags = Notification.FLAG_NO_CLEAR;
17
18private static final int HELLO_ID = 1;
19mNotificationManager.notify(HELLO_ID, notification);
2NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
3
4int icon = R.drawable.notification_icon;
5CharSequence tickerText = "Hello";
6long when = System.currentTimeMillis();
7Notification notification = new Notification(icon, tickerText, when);
8
9Context context = getApplicationContext();
10CharSequence contentTitle = "My notification";
11CharSequence contentText = "Hello World!";
12Intent notificationIntent = new Intent(this, Test.class);
13PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
14notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
15
16notification.flags = Notification.FLAG_NO_CLEAR;
17
18private static final int HELLO_ID = 1;
19mNotificationManager.notify(HELLO_ID, notification);
Nun starte ich diese als Service in meiner Hauptanwenung:
1startService(new Intent(this, Statusbar.class);
Wie kann ich es nun realisieren, dass wenn ich die App starte, nur die Notification angezeigt wird (in der Statusbar) und nicht noch zusätzlich das MainWindow?
Gruß Alexander
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.