Guest User

Untitled

a guest
Apr 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. package com.brians.launcherapp;
  2.  
  3. import android.app.AlarmManager;
  4. import android.app.PendingIntent;
  5. import android.app.Service;
  6. import android.content.Context;
  7. import android.content.Intent;
  8. import android.os.Handler;
  9. import android.os.IBinder;
  10. import android.os.Message;
  11.  
  12. public class LauncherService extends Service {
  13.  
  14. Context mContext;
  15. public int level = -1;
  16. static boolean start;
  17.  
  18. private Handler mHandler = new Handler() {
  19. public void handleMessage(Message msg) {
  20. String message = (String) msg.obj;
  21. DialogActivity.showDialog(LauncherService.this, message);
  22. setAlarmAt(LauncherService.this);
  23. stopSelf();
  24. }
  25. };
  26.  
  27. @Override
  28. public int onStartCommand(Intent intent, int flags, int startId) {
  29. start = true;
  30. System.out.println("Launcher service launched..");
  31. new GetInfo(this, mHandler).start();
  32.  
  33. return START_NOT_STICKY;
  34. }
  35.  
  36. public static void setAlarmAt(Context context) {
  37. //testing version alarm 5 minutes
  38. int alarmPeriod = (1000*60*5);
  39. Intent alarmIntent = new Intent(context, AlarmReceiver.class);
  40. PendingIntent sender = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);
  41. AlarmManager am = (AlarmManager) context.getSystemService(ALARM_SERVICE);
  42. am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + alarmPeriod, alarmPeriod, sender);
  43. }
  44.  
  45. @Override
  46. public IBinder onBind(Intent intent) {
  47. return null;
  48. }
  49.  
  50.  
  51. }
Add Comment
Please, Sign In to add comment