12zTEmszfVSevVq5TnQoaM5KpHG5jo6ccU


SUBMITTED BY: Guest

DATE: Nov. 23, 2013, 6:09 p.m.

FORMAT: Text only

SIZE: 1.9 kB

HITS: 1342

  1. public class CallMonitorService extends Service {
  2. @Override
  3. public int onStartCommand(Intent intent, int flags, int startId) {
  4. Notification notification = new Notification(icon, "service", System.currentTimeMillis());
  5. Intent notificationIntent = new Intent(this, Main.class);
  6. notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
  7. PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
  8. notification.setLatestEventInfo(this, "title", "text", pendingIntent);
  9. notification.flags |= Notification.FLAG_NO_CLEAR;
  10. startForeground(1337, notification);
  11. new ListenThread().start();
  12. }
  13. }
  14. class ListenThread extends Thread {
  15. public void run() {
  16. Looper.prepare();
  17. Handler handler = new Handler() {
  18. public void handleMessage(Message msg) {
  19. BufferedReader in = null;
  20. Socket socket = new Socket();
  21. socket.setKeepAlive(true);
  22. socket.connect(new InetSocketAddress(InetAddress.getByName("http://fritz.box"), 1012), 30*1000);
  23. in = new BufferedReader(new InputStreamReader(socket.getInputStream()), 8 * 1024);
  24. String line = null;
  25. while ((line = in.readLine()) != null) {
  26. Log.d("TAG", line);
  27. }
  28. }
  29. };
  30. handler.sendEmptyMessage(0);
  31. Looper.loop();
  32. }
  33. }

comments powered by Disqus