2014-09-04 4 views
-1

내 응용 프로그램 데이터베이스의 날짜를 저장하고 현재 날짜로이 날짜를 확인할 수있는 하나의 안드로이드 응용 프로그램을 개발 중입니다. 일치하는 경우 자동으로 사람에게 SMS를 보냅니다. 이 일을하는 법을 알지 못합니다. 제발 help. 데이터베이스에서 하나의 테이블 사람 이름, 모바일 아니, 날짜, message.help 같은 일부 엔티티가 존재합니다!자동으로 SMS를 기반으로 날짜를 보내십시오

+0

당신이 사용할 수있는 [알람 관리기 (http://developer.android.com/reference/android/app/AlarmManager.html) – Bishan

+0

네하지만 난 사람의 이름과 자신의 생년월일을 저장하려면 데이터베이스에 다음 저장된 날짜와 현재 날짜를 확인하는 방법 –

+0

u는 몇 가지 힌트 또는 완전한 소스 코드를 원한다면 하나의 알람 관리자를 만들 필요가 있습니다. tht는 데이터베이스를 점검 할 것입니다. 날짜가 wil과 일치하면 sms를 보냅니다. – Jeetendra

답변

0

이렇게하려면 PendingIntent 및 AlarmManager를 사용할 수 있습니다. 그것을 한번보세요.

첫 번째 alarmManager 초기화 및 PendingIntent.

intentsOpen = new Intent(this, AlarmReceiver.class); 
    intentsOpen.setAction("com.sandeep.alarm.ACTION"); 
    pendingIntent = PendingIntent.getBroadcast(this,111, intentsOpen, 0); 
    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 

SMS를 보내려는 날짜와 시간을 설정하십시오.

//set what you want only. I am giving all 
       Calendar calendar = Calendar.getInstance(); 
       calendar.set(Calendar.MONTH, month); 
       calendar.set(Calendar.YEAR, year); 
       calendar.set(Calendar.DAY_OF_MONTH, day); 
       calendar.set(Calendar.HOUR_OF_DAY, hours); 
       calendar.set(Calendar.MINUTE, minutes); 
// set action 
       intentsOpen.setAction("com.sandeep.sendsms.ACTION"); 
       pendingIntent = PendingIntent.getBroadcast(this,112, intentsOpen, 0); 
       if((calendar.getTimeInMillis() > System.currentTimeMillis())){ 
// Always use this if condition so your receiver will not trigger when you start app. if triggerAtMillis is older than the currentMillis, the alarm will be fired no matter when you set it 
// to send sms on repetitive basis 
       alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24*60*60*1000, pendingIntent); 
// 24*60*60*1000 is a duration means how much day you want to repeat. 

// to send sms once only 
    alarmManager.set(AlarmManager.RTC_WAKEUP, calendar1.getTimeInMillis(), pendingIntent) 
    } 

여기는 알람 수신기 클래스입니다.

public class AlarmReceiver extends BroadcastReceiver { 
private final String SEND_SMS = "com.sandeep.sendsms.ACTION"; 


@Override 
public void onReceive(Context context, Intent intent) { 

    String action = intent.getAction(); 
    if (SEND_SMS .equals(action)) { 
     // HERE you can code to send sms. 

    } 

} 

}

관련 문제