2014-09-25 3 views
2

특정 시간에 매일 알림을 표시해야합니다 (예 : 4.25PM). AlarmManagerNotification을 사용하고 있습니다. 응용 프로그램의 방문 페이지에 경보를 설정했습니다. 또한 BroadcastReceiver을 구현했습니다.AlarmManager를 사용하여 특정 시간에 알림 표시

Calendar calendar = Calendar.getInstance(); 
calendar.set(Calendar.HOUR_OF_DAY, 16); 
calendar.set(Calendar.MINUTE, 25); 
calendar.set(Calendar.SECOND, 0); 

Intent notificationmassage = new Intent(getApplicationContext(),Notificationmassage.class); 

//This is alarm manager 
PendingIntent pi = PendingIntent.getService(this, 0 , notificationmassage, PendingIntent.FLAG_UPDATE_CURRENT); 
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); 
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 
     AlarmManager.INTERVAL_DAY, pi); 

이 방송 수신기

public class Notificationmassage extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent arg1) { 
     showNotification(context); 
    } 

    private void showNotification(Context context) { 
     Log.i("notification", "visible"); 

     PendingIntent contentIntent = PendingIntent.getActivity(context, 0, 
       new Intent(context, Notificationmassage.class), 0); 

     NotificationCompat.Builder mBuilder = 
      new NotificationCompat.Builder(context) 
       .setSmallIcon(R.drawable.ic_launcher) 
       .setContentTitle("xyz") 
       .setContentText("It will contain dummy content"); 
     mBuilder.setContentIntent(contentIntent); 
     mBuilder.setDefaults(Notification.DEFAULT_SOUND); 
     mBuilder.setAutoCancel(true); 
     NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
     mNotificationManager.notify(1, mBuilder.build()); 
    } 
} 

이 방법에 문제가 있습니다 무엇입니까 :

코드 알람을 설정하는 방법?

+1

안녕을 보여주십시오. Whats the question ... 죄송합니다. 아래로 스크롤되었습니다. 문제를 일으킬 수있는 유일한 사실은 그 사람이 응용 프로그램을 열지 않으면 어떻게되는지입니다. – Pintac

+0

안녕하세요, 특정 시간에 Android 앱을 던져 알림을 보내야합니다. 위 코드를 완료했지만 작동하지 않습니다. –

+1

안녕하세요. 정의가 작동하지 않습니다. 방송에 들어 가지 않거나 알림을 표시하지 않습니까? – Pintac

답변

4

이전에 이렇게하지 않은 경우 Manifest.xml에 수신자를 추가하십시오. 이미 그렇게한다면 응용 프로그램 섹션

<application> 
     .... 

     <receiver android:name="org.yourapp.Notificationmassage"></receiver> 

    </application> 

에서

<receiver android:name="org.yourapp.Notificationmassage"></receiver> 

는 질문을 편집하고 Manifest.xml

+0

감사합니다 ... Everyone ... –

관련 문제