2016-06-11 3 views
1

알람 관리자를 사용하여 msg를 보내고 있지만 알람이 제대로 작동하지 않습니다. 시간이 18 시간이고 알람을 8 시간 동안 설정하면 그 시간에 msg를 보냅니다. 다음은 코드입니다.알람 관리자가 제대로 작동하지 않습니다

public class Time_Picker extends AppCompatActivity { 
    TimePicker time_picker; 
    String tag="pritesh"; 
    static AlarmManager[] alarmManager=new AlarmManager[5]; 
    static PendingIntent[] pendingIntent = new PendingIntent[5]; 
    EditText message; 
    EditText phone; 
    Intent myIntent; 
    // AlarmManager alarmManager; 
    //PendingIntent pendingIntent; 
    public static String Phone; 
    public static String Message; 
    public int i; 
    array ob=new array(); 
    static ArrayList<PendingIntent> pendingarray=new ArrayList<>(5);  

    public void setAlarm(View view) { 

       //  AlarmManager alarmManager[]=new AlarmManager[5]; 

//   if(prevention.timer==0) { 
       Phone = phone.getText().toString(); 
       Message = message.getText().toString(); 
       phone.setText(""); 
       message.setText(""); 
       //Validating if any field empty 
       if (Phone.length() >= 10 && Message.length() > 0) { 
        Toast.makeText(this.getApplicationContext(), "Your sms will be sent soon", Toast.LENGTH_SHORT).show(); 
        //Getting Calender Reference 
        Calendar cal = Calendar.getInstance(); 
        int currentApiVersion = android.os.Build.VERSION.SDK_INT; 
        if (currentApiVersion > android.os.Build.VERSION_CODES.LOLLIPOP_MR1) { 
         cal.set(Calendar.MINUTE, time_picker.getMinute()); 
         cal.set(Calendar.HOUR_OF_DAY, time_picker.getHour()); 
        } else { 
         //Setting the date and time from the time picker 
         cal.set(Calendar.MINUTE, time_picker.getCurrentMinute()); 
         cal.set(Calendar.HOUR_OF_DAY, time_picker.getCurrentHour()); 
        } 
        int a = (Calendar.getInstance().get(Calendar.SECOND) * 1000); 
        i=array.select; 
        myIntent = new Intent(this, MyReceiver.class); 
        myIntent.putExtra("pos",array.select); 
        //Pending Intent for sending the intent afterwards 
        pendingIntent[array.select] = PendingIntent.getBroadcast(this.getApplicationContext(), array.select, myIntent, 0); 
        alarmManager[array.select] = (AlarmManager) (this.getSystemService(Context.ALARM_SERVICE)); 
        alarmManager[array.select].set(AlarmManager.RTC, cal.getTimeInMillis() - a, pendingIntent[array.select]); 

        pendingarray.add(pendingIntent[array.select]); 
        sms_list.Phone[array.select]=Phone; 
        Intent back = new Intent(this, sms_list.class); 
        back.putExtra("PHONE", Phone); 
        back.putExtra("Flag",2); 
        back.putExtra("MSG", Message); 
        back.putExtra("HOUR", (int) cal.get(Calendar.HOUR_OF_DAY)); 
        back.putExtra("MIN", (int) cal.get(Calendar.MINUTE)); 

        startActivity(back); 

        //int b; 

       } 
       else 
       { 
        Toast.makeText(this.getApplicationContext(), "Please Fill Up All The Details", Toast.LENGTH_SHORT).show(); 
        array.a[array.select]=false; 
        ob.sort(); 
       } 


    } 

}

내가 일을 나던 큰 차이가 시간을 설정 한 경우에도 코드입니다.

12 시계를 사용하여 알람을 설정할 수 있습니까?

답변

0

경고를 이미 지나친 시간으로 설정할 수 없습니다.

alarmManager[array.select].set(AlarmManager.RTC, cal.getTimeInMillis() - a, pendingIntent[array.select]); 

향후 일정을 다음과 같이 시도하십시오.

alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 
    SystemClock.elapsedRealtime() + 
    60 * 1000, alarmIntent); 
+0

확인. 아우, 경과 된 실시간 작업이 IL이 작동하는지 여부를 이해하고 작동하는지 여부를 알려줍니다. – Pritesh

+0

좋습니다. 수 있습니다 받아 들일 수 n을 upvote 그것 ans 다음 – Sush

+0

미안하지만, 내가 15 점이 필요하다고하지만, 나는 대답을 허용했다. – Pritesh

관련 문제