Сообщение
AlexVinn » 03 май 2014, 14:56
Устанавливаю notif.number = 10 - иконку показывает, 10-ку не хочет. Что может быть не так ?
MyService.java
[syntax=java5]package com.example.p0991_servicenotification;
import java.util.concurrent.TimeUnit;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class MyService extends Service {
NotificationManager nm;
@Override
public void onCreate() {
super.onCreate();
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
public int onStartCommand(Intent intent, int flags, int startId) {
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
sendNotif();
return super.onStartCommand(intent, flags, startId);
}
void sendNotif() {
// 1-я часть
Notification notif = new Notification(R.drawable.ic_launcher,
"Text in status bar", System.currentTimeMillis());
// 3-я часть
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(MainActivity.FILE_NAME, "somefile");
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
// 2-я часть
notif.setLatestEventInfo(this, "Notification's title",
"Notification's text", pIntent);
// ставим флаг, чтобы уведомление пропало после нажатия
notif.flags |= Notification.FLAG_AUTO_CANCEL;
notif.number = 10;
// отправляем
nm.notify(1, notif);
}
public IBinder onBind(Intent arg0) {
return null;
}
}
[/syntax]
Тут должна быть подпись.