Guest User

Untitled

a guest
Dec 10th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. public class Serviceclass extends Service {
  2. Databaseclass dbobj;
  3. String messagee;
  4. String phonenumber;
  5. String currenttime;
  6. String comparetime;
  7. String comparedate;
  8. String currentdate;
  9. @Override
  10. public void onCreate() {
  11. super.onCreate();
  12. dbobj= new Databaseclass(getApplicationContext());
  13. Cursor cursor = dbobj.getalldata();
  14. cursor.moveToFirst();
  15. final Calendar c = Calendar.getInstance();
  16. int mYear = c.get(Calendar.YEAR);
  17. int mMonth = c.get(Calendar.MONTH);
  18. int mDay = c.get(Calendar.DAY_OF_MONTH);
  19. int time = c.get(Calendar.HOUR_OF_DAY);
  20. int mMinute = c.get(Calendar.MINUTE);
  21. currentdate = mDay+"-"+(mMonth + 1)+"-"+mYear+"";
  22. comparedate = cursor.getString(4);
  23. currenttime = time + ":" + mMinute;
  24. comparetime = cursor.getString(3);
  25. phonenumber=cursor.getString(2);
  26. messagee=cursor.getString(1);}
  27. @Override
  28. public IBinder onBind(Intent intent) {
  29. return null; } @Override
  30. public void onDestroy() {
  31. super.onDestroy(); }
  32. @Override
  33. public int onStartCommand(Intent intent, int flags, int startId) {
  34. Log.i("***time(Datetosend)", comparedate);
  35. Log.i("***time2(currentdate)", currentdate);
  36. Log.i("***time3(currenttime)", currenttime);
  37. Log.i("***time4(timetosend)", comparetime);
  38. Log.i("***time4(numbertosend)", phonenumber); if(currentdate.equals(comparedate) && currenttime.equals(comparetime)) {
  39. SmsManager sms = SmsManager.getDefault();
  40. List<String> messages = sms.divideMessage(messagee);
  41. for (String msg : messages) {
  42. PendingIntent sentIntent = PendingIntent.getBroadcast(this, 0, new Intent("SMS_SENT"), 0);
  43. PendingIntent deliveredIntent = PendingIntent.getBroadcast(this, 0, new Intent("SMS_DELIVERED"), 0);
  44. sms.sendTextMessage(phonenumber, null, msg, sentIntent, deliveredIntent);
  45. Toast.makeText(getApplicationContext(), "Text send", Toast.LENGTH_SHORT).show();
  46. Log.i("***time2(currentdate)", currentdate);
  47. }}
  48. return START_STICKY;
  49. }}
Add Comment
Please, Sign In to add comment