차근차근
안드로이드 푸시 알람 설정 본문
참조 : http://kwongyo.tistory.com/5?category=880252
MainActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("onCreate ===========>", "onCreate");
new AlamHATT(getApplicationContext()).Alarm();
}
public class AlamHATT {
private Context context;
public AlamHATT(Context context){
this.context = context;
}
public void Alarm(){
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(MainActivity.this,BroadcastD.class);
PendingIntent sender = PendingIntent.getBroadcast(MainActivity.this,0,intent,0);
Calendar calendar = Calendar.getInstance();
//10시 한번만 실행
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE), 10, 00);
calendar.set(Calendar.SECOND, 0);
Log.d("TIME : ",""+calendar.getTime());
am.setExact(AlarmManager.RTC,calendar.getTimeInMillis(),sender);
}
}
BroadcastD
public class BroadcastD extends BroadcastReceiver {
String INTENT_ACTION = Intent.ACTION_BOOT_COMPLETED;
@Override
public void onReceive(Context context, Intent intent) {
Log.d("Recive","Recive");
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent pendingIntent = PendingIntent.getActivity(context,0,new Intent(context,MainActivity.class),PendingIntent.FLAG_UPDATE_CURRENT);
Notification.Builder builder = new Notification.Builder(context);
builder.setSmallIcon(R.mipmap.ic_launcher).setTicker("HETT").setWhen(System.currentTimeMillis())
.setNumber(1).setContentTitle("푸쉬 제목").setContentText("푸쉬내용")
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE).setContentIntent(pendingIntent).setAutoCancel(true);
notificationManager.notify(1, builder.build());
}
}
AndroidManifest.xml
application안에 추가
<receiver android:name=".BroadcastD"></receiver>
'개발' 카테고리의 다른 글
스프링 FCM 푸시 보내기 (0) | 2018.02.01 |
---|---|
자바스크립트 하루종일 팝업 (0) | 2018.01.25 |
안드로이드 웹뷰 쿠키 문제 (0) | 2018.01.24 |
a태그 강제 클릭 (0) | 2018.01.24 |
mysql Left OUTER 조인 하는법 (0) | 2018.01.19 |