Search in sources :

Example 1 with StartIapActivityResult

use of com.huawei.hms.iap.entity.StartIapActivityResult 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);
        }
    });
}
Also used : IapClient(com.huawei.hms.iap.IapClient) StartIapActivityReq(com.huawei.hms.iap.entity.StartIapActivityReq) StartIapActivityResult(com.huawei.hms.iap.entity.StartIapActivityResult) OnSuccessListener(com.huawei.hmf.tasks.OnSuccessListener) OnFailureListener(com.huawei.hmf.tasks.OnFailureListener) IapApiException(com.huawei.hms.iap.IapApiException)

Example 2 with StartIapActivityResult

use of com.huawei.hms.iap.entity.StartIapActivityResult in project Osmand by osmandapp.

the class InAppPurchaseHelperImpl method manageSubscription.

@Override
public void manageSubscription(@NonNull Context ctx, @Nullable String sku) {
    if (uiActivity != null) {
        StartIapActivityReq req = new StartIapActivityReq();
        if (!Algorithms.isEmpty(sku)) {
            req.setSubscribeProductId(sku);
            req.setType(StartIapActivityReq.TYPE_SUBSCRIBE_EDIT_ACTIVITY);
        } else {
            req.setType(StartIapActivityReq.TYPE_SUBSCRIBE_MANAGER_ACTIVITY);
        }
        Task<StartIapActivityResult> task = getIapClient().startIapActivity(req);
        task.addOnSuccessListener(result -> {
            logDebug("startIapActivity: onSuccess");
            Activity activity = (Activity) uiActivity;
            if (result != null && AndroidUtils.isActivityNotDestroyed(activity)) {
                result.startActivity(activity);
            }
        }).addOnFailureListener(e -> logDebug("startIapActivity: onFailure"));
    }
}
Also used : ProductInfoResult(com.huawei.hms.iap.entity.ProductInfoResult) PurchaseResultInfo(com.huawei.hms.iap.entity.PurchaseResultInfo) Context(android.content.Context) AndroidUtils(net.osmand.AndroidUtils) Arrays(java.util.Arrays) Task(com.huawei.hmf.tasks.Task) InAppPurchaseLiveUpdatesOldSubscription(net.osmand.plus.inapp.InAppPurchasesImpl.InAppPurchaseLiveUpdatesOldSubscription) InAppPurchaseData(com.huawei.hms.iap.entity.InAppPurchaseData) NonNull(androidx.annotation.NonNull) IsEnvReadyResult(com.huawei.hms.iap.entity.IsEnvReadyResult) Intent(android.content.Intent) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Algorithms(net.osmand.util.Algorithms) WeakReference(java.lang.ref.WeakReference) ParseException(java.text.ParseException) InAppSubscription(net.osmand.plus.inapp.InAppPurchases.InAppSubscription) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) OwnedPurchasesResult(com.huawei.hms.iap.entity.OwnedPurchasesResult) IapClient(com.huawei.hms.iap.IapClient) InAppPurchase(net.osmand.plus.inapp.InAppPurchases.InAppPurchase) Set(java.util.Set) TextUtils(android.text.TextUtils) OsmandApplication(net.osmand.plus.OsmandApplication) Iap(com.huawei.hms.iap.Iap) ProductInfo(com.huawei.hms.iap.entity.ProductInfo) OrderStatusCode(com.huawei.hms.iap.entity.OrderStatusCode) List(java.util.List) Nullable(androidx.annotation.Nullable) InAppSubscriptionIntroductoryInfo(net.osmand.plus.inapp.InAppPurchases.InAppSubscriptionIntroductoryInfo) PurchaseInfo(net.osmand.plus.inapp.InAppPurchases.PurchaseInfo) StartIapActivityReq(com.huawei.hms.iap.entity.StartIapActivityReq) PurchaseIntentResult(com.huawei.hms.iap.entity.PurchaseIntentResult) Activity(android.app.Activity) StartIapActivityResult(com.huawei.hms.iap.entity.StartIapActivityResult) StartIapActivityReq(com.huawei.hms.iap.entity.StartIapActivityReq) StartIapActivityResult(com.huawei.hms.iap.entity.StartIapActivityResult) Activity(android.app.Activity)

Aggregations

IapClient (com.huawei.hms.iap.IapClient)2 StartIapActivityReq (com.huawei.hms.iap.entity.StartIapActivityReq)2 StartIapActivityResult (com.huawei.hms.iap.entity.StartIapActivityResult)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Intent (android.content.Intent)1 TextUtils (android.text.TextUtils)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 OnFailureListener (com.huawei.hmf.tasks.OnFailureListener)1 OnSuccessListener (com.huawei.hmf.tasks.OnSuccessListener)1 Task (com.huawei.hmf.tasks.Task)1 Iap (com.huawei.hms.iap.Iap)1 IapApiException (com.huawei.hms.iap.IapApiException)1 InAppPurchaseData (com.huawei.hms.iap.entity.InAppPurchaseData)1 IsEnvReadyResult (com.huawei.hms.iap.entity.IsEnvReadyResult)1 OrderStatusCode (com.huawei.hms.iap.entity.OrderStatusCode)1 OwnedPurchasesResult (com.huawei.hms.iap.entity.OwnedPurchasesResult)1 ProductInfo (com.huawei.hms.iap.entity.ProductInfo)1 ProductInfoResult (com.huawei.hms.iap.entity.ProductInfoResult)1