i Anfänger sind in android.i erstellen Sie einen Dienst eine Benachrichtigung zu zeigen, wenn onCreat auf mainActivityWie eine Benachrichtigung zeigen, selbst App nicht läuft
genannt hierpublic class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent a = new Intent(this,myService.class);
startService(a);
}
}
meine Dienstklasse ist
public class myService extends Service{
private NotificationManager mManager;
@Override
public void onCreate() {
mManager = (NotificationManager) this.getApplicationContext().getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE);
Intent intent1 = new Intent(this.getApplicationContext(),MainActivity.class);
Notification notification = new Notification(R.drawable.ic_launcher,"This is a test message!", System.currentTimeMillis());
intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP| Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this.getApplicationContext(),0, intent1,PendingIntent.FLAG_UPDATE_CURRENT);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(this.getApplicationContext(), "AlarmManagerDemo", "This is a test message!", pendingNotificationIntent);
mManager.notify(0, notification);
}
aber ich möchte, wenn meine app nicht läuft kann ich diesen service zb zeigen wenn meine telefonzeit ist größer als 9 ich zeige diese benachrichtigung nur einmal an einem tag.eine ideen? Vielen Dank im Voraus