Пример #1
0
  private void registerPongListener() {
    pingID = null;

    if (pongListener != null) extXMPPConnection.removePacketListener(pongListener);

    pongListener =
        new PacketListener() {

          @Override
          public void processPacket(Packet packet) {
            if (packet == null) return;

            gotServerPong(packet.getPacketID());
          }
        };

    extXMPPConnection.addPacketListener(pongListener, new PacketTypeFilter(IQ.class));
    pingAlarmPendIntent =
        PendingIntent.getBroadcast(
            service.getApplicationContext(), 0, intentPingAlarm, PendingIntent.FLAG_UPDATE_CURRENT);
    timeoutAlarmPendIntent =
        PendingIntent.getBroadcast(
            service.getApplicationContext(),
            0,
            intentTimeoutAlarm,
            PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.setInexactRepeating(
        AlarmManager.RTC_WAKEUP,
        System.currentTimeMillis() + AlarmManager.INTERVAL_FIFTEEN_MINUTES,
        AlarmManager.INTERVAL_FIFTEEN_MINUTES,
        pingAlarmPendIntent);
  }
    private static ArrayList<String> extractTextFromNotification(Service service, RemoteViews view) {
    	LayoutInflater inflater = (LayoutInflater) service.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	    ArrayList<String> result = new ArrayList<String>();
	    if (view == null) {
	    	Log.d(TAG, "View is empty");
	    	return null;
	    }
		try {
			int layoutid = view.getLayoutId();
			ViewGroup localView = (ViewGroup) inflater.inflate(layoutid, null);
		    view.reapply(service.getApplicationContext(), localView);
		    ArrayList<View> outViews = new ArrayList<View>();
		    extractViewType(outViews, TextView.class, localView);
		    for (View  ttv: outViews) {
		    	TextView tv = (TextView) ttv;
		    	String txt = tv.getText().toString();
		    	if (!TextUtils.isEmpty(txt) && tv.getId() != TIMESTAMPID) {
		    		result.add(txt);
		    	}
			}
		} catch (Exception e) {
			Log.d(TAG, "FAILED to load notification " + e.toString());
			Log.wtf(TAG, e);
			return null;
			//notification might have dissapeared by now
		}
		Log.d(TAG, "Return result" + result);
	    return result;
    }
Пример #3
0
  @Override
  public void stopDiscovery(IAgentUPnPListener listener) {
    if (_upnpService != null) {
      _upnpService.getRegistry().removeListener(this);
      _upnpService = null;
    }
    _parentService.getApplicationContext().unbindService(_serviceConnection);

    _listeners.clear();
  }
Пример #4
0
  @Override
  public void startDiscovery(IAgentUPnPListener listener) {
    if (_upnpService == null) {
      _parentService
          .getApplicationContext()
          .bindService(
              new Intent(_parentService, AndroidUpnpServiceImpl.class),
              _serviceConnection,
              Context.BIND_AUTO_CREATE);
    }

    _listeners.add(listener);
  }
Пример #5
0
 private static void startOnForeground(Service service, boolean playSound) {
   service.startForeground(
       STICKY_NOTIFICATION_ID,
       buildNotification(service.getApplicationContext(), playSound, null));
 }