use of com.huawei.hms.iap.IapClient in project Osmand by osmandapp.
the class IapRequestHelper method showSubscription.
/**
* link to subscription manager page
* @param activity activity
* @param productId the productId of the subscription product
*/
public static void showSubscription(final Activity activity, String productId) {
StartIapActivityReq req = new StartIapActivityReq();
if (TextUtils.isEmpty(productId)) {
req.setType(StartIapActivityReq.TYPE_SUBSCRIBE_MANAGER_ACTIVITY);
} else {
req.setType(StartIapActivityReq.TYPE_SUBSCRIBE_EDIT_ACTIVITY);
req.setSubscribeProductId(productId);
}
IapClient iapClient = Iap.getIapClient(activity);
Task<StartIapActivityResult> task = iapClient.startIapActivity(req);
task.addOnSuccessListener(new OnSuccessListener<StartIapActivityResult>() {
@Override
public void onSuccess(StartIapActivityResult result) {
if (result != null) {
result.startActivity(activity);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
ExceptionHandle.handle(activity, e);
}
});
}
use of com.huawei.hms.iap.IapClient in project Osmand by osmandapp.
the class InAppPurchaseHelperImpl method isInAppPurchaseSupported.
@Override
public void isInAppPurchaseSupported(@NonNull final Activity activity, @Nullable final InAppPurchaseInitCallback callback) {
if (envReady) {
if (callback != null) {
if (purchaseSupported) {
callback.onSuccess();
} else {
callback.onFail();
}
}
} else {
// Initiating an isEnvReady request when entering the app.
// Check if the account service country supports IAP.
IapClient mClient = Iap.getIapClient(activity);
final WeakReference<Activity> activityRef = new WeakReference<>(activity);
IapRequestHelper.isEnvReady(mClient, new IapApiCallback<IsEnvReadyResult>() {
private void onReady(boolean succeed) {
logDebug("Setup finished.");
envReady = true;
purchaseSupported = succeed;
if (callback != null) {
if (succeed) {
callback.onSuccess();
} else {
callback.onFail();
}
}
}
@Override
public void onSuccess(IsEnvReadyResult result) {
onReady(true);
}
@Override
public void onFail(Exception e) {
onReady(false);
LOG.error("isEnvReady fail, " + e.getMessage(), e);
ExceptionHandle.handle(activityRef.get(), e);
}
});
}
}
Aggregations