나는 안드로이드 프로그래밍의 초보자입니다. 그 시간에 알림을 표시 할 수 있는지 알고 싶습니다. 시간 형식 문자열 (2014-1-10 1:30:33)? 앱이 실행 중일 때마다 (2014-1-1 1:30:33) 주어지고 2014-1-10 1:30:33에 표시됩니다. \알림 android?
public void Notification(String s)
{
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.notification_icon;
CharSequence tickerText = "Ready for Play time."; // ticker-text
long when = System.currentTimeMillis();
Context context = getApplicationContext();
CharSequence contentTitle = "Play Time";
CharSequence contentText = "Your match is at "+s;
Intent notificationIntent = new Intent(this,ScheldueNotification .class);
//PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this.getApplicationContext(),0, notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, pendingNotificationIntent);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
// and this
mNotificationManager.notify(MY_NOTIFICATION_ID, notification);
Intent myIntent = new Intent(MainActivity.this, myReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent,0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");
/*java.util.Date date;
try {
date = formatter.parse(getCurrentTime());
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
try {
alarmManager.set(AlarmManager.RTC,(sdf.parse(getCurrentTime())).getTime(), pendingIntent);
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
notification.defaults |= Notification.DEFAULT_SOUND;
notification.vibrate = new long[] { 0, 100, 200, 300 };
notification.flags |= Notification.FLAG_AUTO_CANCEL;
//alert();
}
편집 : 여기 내 코드에 있습니다. 잘 작동하지 않습니다.
좀 더 구체적으로 시도해 보시기 바랍니다. – SoulRayder
내 코드를 편집했습니다. – Halo