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;
    }
예제 #2
0
  /**
   * Marks the service as a foreground service. This uses reflection to figure out whether the new
   * APIs for marking a service as a foreground service are available. If not, it falls back to the
   * old {@link #setForeground(boolean)} call.
   *
   * @param service the service to put in foreground mode
   * @param notificationId id of the notification to show
   * @param notification the notification to show
   */
  public static void setForeground(
      Service service, Integer notificationId, Notification notification) {
    final Class<?>[] startForegroundSignature = new Class[] {int.class, Notification.class};
    Method startForeground = null;
    try {
      startForeground = service.getClass().getMethod("startForeground", startForegroundSignature);

      try {
        startForeground.invoke(service, new Object[] {notificationId, notification});
      } catch (IllegalArgumentException e) {
        // Should not happen!
        Log.e("Could not set TriggerService to foreground mode.", e);
      } catch (IllegalAccessException e) {
        // Should not happen!
        Log.e("Could not set TriggerService to foreground mode.", e);
      } catch (InvocationTargetException e) {
        // Should not happen!
        Log.e("Could not set TriggerService to foreground mode.", e);
      }

    } catch (NoSuchMethodException e) {
      // Fall back on old API.
      service.setForeground(true);

      NotificationManager manager =
          (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE);
      manager.notify(notificationId, notification);
    }
  }
예제 #3
0
 public ThreeGLogger(String logFileName, int interval, Service s) {
   super(logFileName, interval);
   m_service = s;
   m_ss = -1;
   m_myListener = new MyPhoneStateListener();
   m_telManager = (TelephonyManager) m_service.getSystemService(Context.TELEPHONY_SERVICE);
   m_telManager.listen(m_myListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
 }
예제 #4
0
 public SmackableImp(YaximConfiguration config, ContentResolver contentResolver, Service service) {
   this.mConfig = config;
   this.mContentResolver = contentResolver;
   this.mService = service;
   this.mAlarmManager = (AlarmManager) mService.getSystemService(Context.ALARM_SERVICE);
 }