0
SMS 스케줄러 앱을 개발 중입니다. 여기서 사용자는 시간, 숫자 및 msg를 설정할 수 있습니다. 내 코드는 스케줄링해야 할 메시지가 하나뿐이라면 잘 작동합니다. 그러나 만약 내가 여러 개의 스케줄을 갖고 싶다면, 새로운 것으로 바꿀 수는 없다.SMS 스케줄러에서 여러 개의 알람을 허용하지 않습니다.
내가 사용하고있는 기술은 읽은 다른 게시물에서 제안한대로 다른 요청 코드로 보류중인 인 텐트 배열을 만드는 것이지만 새 일정이 이전 일정으로 바뀝니다. 내 방송 수신기
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zax_sms_scheduler);
Button dateSet=(Button) findViewById(R.id.dateSetBtn);
Button timeSet=(Button) findViewById(R.id.timeSetBtn);
dateSet.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
DatePickerDialog.OnDateSetListener d=new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthodyear, int dayofmonth) {
// TODO Auto-generated method stub
mMonth=monthodyear;
mYear=year;
mDay=dayofmonth;
Toast.makeText(getBaseContext(), "Date Set is :"+mDay+"/"+(mMonth+1)+"/"+mYear, Toast.LENGTH_SHORT).show();
}
};
// TODO Auto-generated method stub
new DatePickerDialog(ZaxSmsScheduler.this,d,Calendar.YEAR,Calendar.MONTH,Calendar.DAY_OF_MONTH).show();
}
});
timeSet.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
TimePickerDialog.OnTimeSetListener t=new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view2, int hour, int min) {
// TODO Auto-generated method stub
mHour=hour;
mMin=min;
if(mHour>=12)
mHour=mHour-12;
Log.d("MYAPP", "hh:"+mHour+"\nmm:"+mMin);
Toast.makeText(getBaseContext(), "Time Set is:"+mHour+":"+mMin+":00", Toast.LENGTH_SHORT).show();
}
};
Calendar cal=Calendar.getInstance();
new TimePickerDialog(ZaxSmsScheduler.this,t,cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),true).show();
}
});
Button saveAndClearBtn=(Button) findViewById(R.id.saveBtn);
saveAndClearBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Calendar myCal=Calendar.getInstance();
long timeToTrigger;
/*myCal.set(Calendar.DAY_OF_MONTH, mDay);
myCal.set(Calendar.MONTH,mMonth);
myCal.set(Calendar.YEAR, mYear);*/
myCal.set(Calendar.HOUR, mHour);
myCal.set(Calendar.MINUTE, mMin);
myCal.set(Calendar.SECOND, 0);
long setTime=myCal.getTimeInMillis();
if(setTime>System.currentTimeMillis())
{
timeToTrigger=setTime-System.currentTimeMillis();
EditText edt1=(EditText) findViewById(R.id.editText1);
EditText edt2=(EditText) findViewById(R.id.editText2);
msg=edt2.getText().toString();
telno=edt1.getText().toString();
SQLiteDatabase db=openOrCreateDatabase("MYDB", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS mySmsScheduler(SlNo VARCHAR,Number VARCHAR,Msg VARCHAR);");
String s="INSERT INTO mySmsScheduler VALUES ('"+count+"','"+telno+"','"+msg+"');";
db.execSQL(s);
Log.d("MYREC", "Insertion of data successfull");
db.close();
edt1.setText("");
edt2.setText("");
Intent intent = new Intent();
intent.setClass(ZaxSmsScheduler.this, MyBroadcastReceiver.class);
Bundle b = new Bundle();
b.putString("index", Integer.toString(count));
intent.putExtras(b);
PendingIntent pendingIntent = PendingIntent.getBroadcast(ZaxSmsScheduler.this, (int)Math.random(), intent, 0);
intentArray.add(pendingIntent);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
+ timeToTrigger, intentArray.get(count));
count++;
Toast.makeText(getBaseContext(), "Sms Scheduled after:"+(timeToTrigger/1000)+" sec.", Toast.LENGTH_SHORT).show();
Log.d("MYAPP", "Set Time:"+(setTime/1000)+"Sec. \n"+"Cur time:"+System.currentTimeMillis()/1000);
Log.d("MYAPP", "Time to trigger:"+(timeToTrigger/1000)+"sec.");
}
else
{
Toast.makeText(getBaseContext(), "Please Enter a valid time", Toast.LENGTH_SHORT).show();
Calendar calendar =Calendar.getInstance();
int h=calendar.get(Calendar.HOUR);
int m=calendar.get(Calendar.MINUTE);
Log.d("MYAPP", "cur HH:"+h+"\ncur MM:"+m);
}
}
});
}
코드는 다음과 같습니다 :
@Override
public void onReceive(Context arg0, Intent intent) {
// TODO Auto-generated method stub
int myCount;
String cnt=intent.getStringExtra("index");
if(cnt==null)
Log.d("MYAPP","Data not received");
Log.d("MYAPP", "Count:"+cnt);
myCount=Integer.parseInt(cnt);
Log.d("MYAPP","Broadcast receiver called...");
SQLiteDatabase db=arg0.openOrCreateDatabase("MYDB",Context.MODE_PRIVATE, null);
Cursor c=db.rawQuery("SELECT Number, Msg FROM mySmsScheduler WHERE SlNo=="+myCount, null);
Log.d("MYAPP", "Cursor reference obtained...");
if(c!=null)
{
c.moveToFirst();
}
else
Log.d("MYAPP", "cursor is null");
/* c.moveToFirst();*/
String num=c.getString(c.getColumnIndex("Number"));
String myMsg=c.getString(c.getColumnIndex("Msg"));
Log.d("MYAPP", "number:"+num+"\nMsg:"+myMsg);
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage(num, null, myMsg, null, null);
Log.d("MYAPP", "Message Sent");
Toast.makeText(arg0, "Msg sent successfully", Toast.LENGTH_LONG).show();
String table="mySmsScheduler";
String whereClause = "SlNo = ?";
String[] whereArgs = new String[] { Integer.toString(ZaxSmsScheduler.count) };
db.delete(table, whereClause, whereArgs);
db.close();
Log.d("MYAPP", "Entry deleted..");
//sm.sendTextMessage(ZaxSmsScheduler.telno, null, ZaxSmsScheduler.msg, null, null);
}
내 매니페스트에 필요한 권한을 설정하고 내 방송 수신기를 등록
다음은 내 코드입니다. 나는 당신이 똑같은 문제를 해결할 수있는 귀중한 제안을 해주길 바랍니다.
미리 감사드립니다. 에서 setalarm에 대해 여러 경보
@Override
public void onReceive(Context c, Intent i) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
Bundle bundle = i.getExtras();
String title = bundle.getString("title");
String text = bundle.getString("text");
String billno = bundle.getString("billno");
int id = bundle.getInt("id");
Toast.makeText(c, text, Toast.LENGTH_LONG).show();
final int NOTIF_ID = id;
// final int NOTIF_ID = 1;
NotificationManager notofManager = (NotificationManager) c
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(c, AyyappaGoldActivity.class);
//notificationIntent.putExtra("billno", billno);
PendingIntent contentIntent = PendingIntent.getActivity(c, 0,
notificationIntent, 0);
Notification notification = new Notification(icon, title, when);
notification.setLatestEventInfo(c, title, text, contentIntent);
//notification.flags = Notification.FLAG_INSISTENT;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notofManager.notify(NOTIF_ID, notification);
}
}
코드에 대한