Bisher habe ich es folgendermassen versucht:
Die App an sich startet, jedoch wird keine Notification gestartet/gezeigt.Status.java
1package de.Rocky.AppWunsch;
2
3import java.util.Timer;
4
5import android.app.Notification;
6import android.app.NotificationManager;
7import android.app.PendingIntent;
8import android.app.Service;
9import android.content.Context;
10import android.content.Intent;
11import android.os.IBinder;
12
13public class Status extends Service {
14
15 private NotificationManager nManager;
16 private static final int APP_ID = 0;
17 private Timer timer = new Timer();
18
19 public IBinder onBind(Intent intent) {
20 return null;
21 }
22
23 @Override
24 public void onCreate() {
25 super.onCreate();
26 // init the service here
27 _startService();
28
29 }
30
31 @Override
32 public void onStart(Intent intent, int startId) {
33
34 }
35
36
37 @Override
38 public void onDestroy() {
39 super.onDestroy();
40 _shutdownService();
41
42 }
43
44 private void _shutdownService() {
45 if (timer != null) timer.cancel();
46 }
47
48
49 private void _startService() {
50
51 Thread t = new Thread() {
52 public void run() {
53 _Notification();
54 }
55 };
56 t.start();
57
58 }
59
60 private void _Notification() {
61
62 nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
63
64 Notification notification = new Notification(R.drawable.icon,
65 "Notify", System.currentTimeMillis());
66 notification.setLatestEventInfo(this.getApplication(),
67 "AppName","Description of the notification",
68 PendingIntent.getActivity(this.getBaseContext(), 0, null,
69 PendingIntent.FLAG_CANCEL_CURRENT));
70 notification.flags = Notification.FLAG_NO_CLEAR;
71 nManager.notify(APP_ID, notification);
72
73 }
74}
AndroidManifest.xml
1<?xml version="1.0" encoding="utf-8"?>
2<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 package="de.Rocky.AppWunsch"
4 android:versionCode="1"
5 android:versionName="1.0"
6 android:installLocation="auto">
7 <application android:icon="@drawable/icon" android:label="@string/app_name">
8 <activity android:name=".AppWunsch"
9 android:label="@string/app_name"
10 android:configChanges="keyboardHidden|orientation">
11 <intent-filter>
12 <action android:name="android.intent.action.MAIN" />
13 <category android:name="android.intent.category.LAUNCHER" />
14 </intent-filter>
15 </activity>
16
17 <activity android:name="Entry"
18 android:configChanges="keyboardHidden|orientation" />
19
20<service android:name="Status" />
21</application>
22 <uses-sdk android:minSdkVersion="3"
23 android:targetSdkVersion="8" />
24
25 <supports-screens android:smallScreens="true"
26 android:normalScreens="true"
27 android:largeScreens="true"
28 android:anyDensity="true" />
29
30 <uses-permission android:name="android.permission.INTERNET" />
31
32</manifest>
— geändert am 26.11.2010, 17:36:00
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.