public static Invocation fromClass(String name) throws InvocationException { if (name == null) { throw new IllegalArgumentException("Class name is null"); } Class<?> cls = RuntimeUtils.classForName(name); if (cls == null) { throw new InvocationException("Unable to find class '%s'", name); } return fromClass(cls); }
private static Intent makeRestartActivityTaskGuarded(ComponentName cn) throws InvocationException { try { return Intent.makeRestartActivityTask(cn); } catch (NoSuchMethodError e) { //return IntentCompat.makeRestartActivityTask(cn); Invocation invocation = Invocation.fromClass(IntentCompat.class); return (Intent) invocation.invokeMethod("makeRestartActivityTask", new Class<?>[]{ComponentName.class}, new Object[]{cn}); } }
@SuppressWarnings("unchecked") public static @Nullable Map<String, ApptentiveApptimizeTestInfo> getTestInfo() { try { Invocation apptimize = Invocation.fromClass(CLASS_APPTIMIZE); Map<String, Object> testInfoDict = apptimize.invokeMethod(METHOD_GET_TEST_INFO, Map.class); if (testInfoDict == null) {
private static @Nullable AdvertisingIdClientInfo resolveAdvertisingIdClientInfo(Context context) { try { Invocation advertisingIdClient = Invocation.fromClass(CLASS_ADVERTISING_ID_CLIENT); Object infoObject = advertisingIdClient.invokeMethod(METHOD_GET_ADVERTISING_ID_INFO, new Class<?>[] { Context.class }, new Object[] { context }); if (infoObject == null) { ApptentiveLog.w("Unable to resolve advertising ID: '%s' did not return a valid value", METHOD_GET_ADVERTISING_ID_INFO); return null; } Invocation info = Invocation.fromObject(infoObject); String id = info.invokeStringMethod(METHOD_GET_ID); boolean limitAdTrackingEnabled = info.invokeBooleanMethod(METHOD_IS_LIMIT_AD_TRACKING_ENABLED); return new AdvertisingIdClientInfo(id, limitAdTrackingEnabled); } catch (Exception e) { Throwable cause = e.getCause(); if (cause != null) { if (StringUtils.equal(cause.getClass().getSimpleName(), "GooglePlayServicesNotAvailableException")) { ApptentiveLog.e(e, "Unable to resolve advertising ID: Google Play is not installed on this device"); return null; } if (StringUtils.equal(cause.getClass().getSimpleName(), "GooglePlayServicesRepairableException")) { ApptentiveLog.e(e, "Unable to resolve advertising ID: error connecting to Google Play Services"); return null; } } ApptentiveLog.e(e, "Unable to resolve advertising ID"); logException(e); return null; } }