6
我想知道如何設置通知時間。我想每五分鐘設置一次通知, 所以幫助我做到這一點。每五分鐘顯示一次android通知
public class FirstActivity extends Activity
{
private static final int HELLO_ID = 1;
//public static final int FLAG_AUTO_CANCEL = 0;`enter code here`
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.firstactivity);
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.statusbarnotification);
contentView.setImageViewResource(R.id.image, R.drawable.icon);
contentView.setTextViewText(R.id.text, "Hello, this message is in a custom expanded view");
notification.contentView = contentView;
notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent = new Intent(getApplicationContext(), SecondActivity.class);
//PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
mNotificationManager.notify(HELLO_ID, notification);
}
}
由於是有點什麼,我想,但我對你這個問題。如何在Service Class中設置AlarmManager,以便在它檢查數據庫並有新東西然後顯示通知? (如果你可以在代碼中解釋會更好,不需要數據庫的代碼......只需使用'if'語句在服務類中的AlarmManager) –
當'StartAlarm()'調用?我沒有得到任何通知..代碼不workin克:( – Neo