Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Qualifier and Type | Interface Name and Description |
|---|---|
interface | Defines the product type. |
Qualifier and Type | Method Name and Description |
|---|---|
consumeOwnedPurchase(ConsumeOwnedPurchaseReq consumeOwnedPurchaseReq) Consumes a consumable after it is successfully delivered. | |
createPurchaseIntent(PurchaseIntentReq purchaseIntentReq) Creates orders for products managed by the product management system (PMS), including consumables, non-consumables, and subscriptions. | |
void | Enables pending purchase. |
| Checks whether the currently signed-in HUAWEI ID is located in a country or region where HUAWEI IAP is available. | |
isSandboxActivated(IsSandboxActivatedReq isSandboxActivatedReq) Checks whether the signed-in HUAWEI ID and the app version meet the requirements of sandbox testing. | |
obtainOwnedPurchaseRecord(OwnedPurchasesReq ownedPurchasesReq) Obtains the purchase data of all consumed products or the receipts of all subscriptions. | |
obtainOwnedPurchases(OwnedPurchasesReq ownedPurchasesReq) Queries purchase data of the products that a user has bought. For consumables, this method returns purchase data of those already bought but not consumed. For non-consumables, this method returns purchase data of all the products that have been bought. For subscriptions, this method returns only the currently active subscription relationships. | |
obtainProductInfo(ProductInfoReq productInfoReq) Obtains product details configured in AppGallery Connect. | |
parsePurchaseResultInfoFromIntent(Intent intent) Parses the payment result. | |
startIapActivity(StartIapActivityReq startIapActivityReq) Displays the subscription editing screen or subscription management screen of HUAWEI IAP. |
Method |
|---|
Task<ConsumeOwnedPurchaseResult> consumeOwnedPurchase(ConsumeOwnedPurchaseReq consumeOwnedPurchaseReq) Consumes a consumable after it is successfully delivered. NOTICE
|
Parameters
Name | Description |
|---|---|
consumeOwnedPurchaseReq | ConsumeOwnedPurchaseReq object that contains request information. |
Returns
Type | Description |
|---|---|
Task containing the API request result.
|
Sample code:
// Construct a ConsumeOwnedPurchaseReq object.
ConsumeOwnedPurchaseReq req = new ConsumeOwnedPurchaseReq();
String purchaseToken = "";
try {
// Obtain the value of purchaseToken from inAppPurchaseData. You can obtain inAppPurchaseData from a payment request or by calling the obtainOwnedPurchases API.
InAppPurchaseData inAppPurchaseDataBean = new InAppPurchaseData(inAppPurchaseData);
purchaseToken = inAppPurchaseDataBean.getPurchaseToken();
} catch (JSONException e) {
}
req.setPurchaseToken(purchaseToken);
// Obtain the Activity object that calls the API.
final Activity activity = getActivity();
// Call the consumeOwnedPurchase API.
Task<ConsumeOwnedPurchaseResult> task = Iap.getIapClient(activity).consumeOwnedPurchase(req);
task.addOnSuccessListener(new OnSuccessListener<ConsumeOwnedPurchaseResult>() {
@Override
public void onSuccess(ConsumeOwnedPurchaseResult result) {
// Obtain the result returned upon a successful API call.
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
if (e instanceof IapApiException) {
IapApiException apiException = (IapApiException) e;
Status status = apiException.getStatus();
int returnCode = apiException.getStatusCode();
} else {
// Other external errors.
}
}
});// Construct a ConsumeOwnedPurchaseReq object.
val req = ConsumeOwnedPurchaseReq()
var purchaseToken = ""
try {
// Obtain the value of purchaseToken from inAppPurchaseData. You can obtain inAppPurchaseData from a payment request or by calling the obtainOwnedPurchases API.
val inAppPurchaseDataBean = InAppPurchaseData(inAppPurchaseData)
purchaseToken = inAppPurchaseDataBean.purchaseToken
} catch (e: JSONException) {
}
req.setPurchaseToken(purchaseToken)
// Obtain the Activity object that calls the API.
val activity: Activity = getActivity()
// Call the consumeOwnedPurchase API.
val task = Iap.getIapClient(activity).consumeOwnedPurchase(req)
task.addOnSuccessListener {
// Obtain the result returned upon a successful API call.
}.addOnFailureListener { e ->
if (e is IapApiException) {
val apiException = e as IapApiException
val status: Status = apiException.status
val returnCode = apiException.statusCode
} else {
// Other external errors.
}
}Method |
|---|
Task<PurchaseIntentResult> createPurchaseIntent(PurchaseIntentReq purchaseIntentReq) Creates orders for products managed by the product management system (PMS), including consumables, non-consumables, and subscriptions. After creating a product in AppGallery Connect, you can call this API to open the HUAWEI IAP checkout screen and display the product, price, and payment method. Huawei can adjust product prices by foreign exchange rate changes. To ensure price consistency, your app needs to call the obtainProductInfo API to obtain product details from Huawei instead of your own server. This API only returns the Status object that contains the IAP checkout screen. Showing this screen is implemented by your app. For details about how to show it, please refer to the description of Status in PurchaseIntentResult. After the user completes payment, your app can obtain the payment result using parsePurchaseResultInfoFromIntent from the onActivityResult callback method. NOTICE
|
Parameters
Name | Description |
|---|---|
purchaseIntentReq | PurchaseIntentReq object that contains request information. |
Returns
Type | Description |
|---|---|
Task containing the API request result.
|
Sample code:
// Construct a PurchaseIntentReq object.
PurchaseIntentReq req = new PurchaseIntentReq();
// Only those products already configured in AppGallery Connect can be purchased through the createPurchaseIntent API.
req.setProductId("CProduct1");
// priceType: 0: consumable; 1: non-consumable; 2: subscription
req.setPriceType(0);
req.setDeveloperPayload("test");
// Obtain the Activity object that calls the API.
final Activity activity = getActivity();
// Call the createPurchaseIntent API to create a PMS product order.
Task<PurchaseIntentResult> task = Iap.getIapClient(activity).createPurchaseIntent(req);
task.addOnSuccessListener(new OnSuccessListener<PurchaseIntentResult>() {
@Override
public void onSuccess(PurchaseIntentResult result) {
// Obtain the order creation result.
// The Status object does not support serialization.
Status status = result.getStatus();
if (status.hasResolution()) {
try {
// 6666 is a constant defined by yourself.
// Open the checkout page returned.
status.startResolutionForResult(activity, 6666);
} catch (IntentSender.SendIntentException exp) {
}
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
if (e instanceof IapApiException) {
IapApiException apiException = (IapApiException) e;
// The Status object does not support serialization.
Status status = apiException.getStatus();
int returnCode = apiException.getStatusCode();
} else {
// Other external errors.
}
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 6666) {
if (data == null) {
Log.e("onActivityResult", "data is null");
return;
}
// Call the parsePurchaseResultInfoFromIntent method to parse the payment result.
PurchaseResultInfo purchaseResultInfo = Iap.getIapClient(this).parsePurchaseResultInfoFromIntent(data);
switch(purchaseResultInfo.getReturnCode()) {
case OrderStatusCode.ORDER_STATE_CANCEL:
// The user cancels the purchase.
break;
case OrderStatusCode.ORDER_STATE_FAILED:
case OrderStatusCode.ORDER_PRODUCT_OWNED:
// Check whether the delivery is successful.
break;
case OrderStatusCode.ORDER_STATE_SUCCESS:
// The payment is successful.
String inAppPurchaseData = purchaseResultInfo.getInAppPurchaseData();
String inAppPurchaseDataSignature = purchaseResultInfo.getInAppDataSignature();
// Verify the signature using your app's IAP public key.
// If the verification is successful, check the consistency of the information including productId, price, and currency in InAppPurchaseData between HUAWEI IAP and your app. If relevant information is consistent, deliver the product.
// If the user purchased a consumable, call the consumeOwnedPurchase API to consume it after delivery.
break;
default:
break;
}
}
}// Construct a PurchaseIntentReq object.
val req = PurchaseIntentReq()
// Only those products already configured in AppGallery Connect can be purchased through the createPurchaseIntent API.
req.setProductId("CProduct1")
// priceType: 0: consumable; 1: non-consumable; 2: subscription
req.setPriceType(0)
req.setDeveloperPayload("test")
// Obtain the Activity object that calls the API.
val activity: Activity = getActivity()
// Call the createPurchaseIntent API to create a PMS product order.
val task = Iap.getIapClient(activity).createPurchaseIntent(req)
task.addOnSuccessListener { result ->
// Obtain the order creation result.
// The Status object does not support serialization.
val status: Status = result.status
if (status.hasResolution()) {
try {
// 6666 is a constant defined by yourself.
// Open the checkout page returned.
status.startResolutionForResult(activity, 6666)
} catch (exp: SendIntentException) {
}
}
}.addOnFailureListener { e ->
if (e is IapApiException) {
val apiException = e as IapApiException
// The Status object does not support serialization.
val status: Status = apiException.status
val returnCode = apiException.statusCode
} else {
// Other external errors.
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == 6666) {
if (data == null) {
Log.e("onActivityResult", "data is null")
return
}
// Call the parsePurchaseResultInfoFromIntent method to parse the payment result.
val purchaseResultInfo = Iap.getIapClient(this).parsePurchaseResultInfoFromIntent(data)
when (purchaseResultInfo.returnCode) {
OrderStatusCode.ORDER_STATE_CANCEL -> {
}
OrderStatusCode.ORDER_STATE_FAILED, OrderStatusCode.ORDER_PRODUCT_OWNED -> {
}
OrderStatusCode.ORDER_STATE_SUCCESS -> {
// The payment is successful.
val inAppPurchaseData = purchaseResultInfo.inAppPurchaseData
val inAppPurchaseDataSignature = purchaseResultInfo.inAppDataSignature
}
else -> {
}
}
}
}Method |
|---|
void enablePendingPurchase() Enables pending purchase. To implement pending purchase in your app, call this method before a purchase request is made. The ideal option is to call this method during app initialization. NOTE
|
Sample code:
// Obtain the Activity object that calls the API. Activity activity = getActivity(); Iap.getIapClient(activity).enablePendingPurchase();
// Obtain the Activity object that calls the API. val activity: Activity = getActivity() Iap.getIapClient(activity).enablePendingPurchase()
Method |
|---|
Task<IsEnvReadyResult> isEnvReady() Checks whether the currently signed-in HUAWEI ID is located in a country or region where HUAWEI IAP is available. |
Returns
Type | Description |
|---|---|
Task containing the API request result.
|
Sample code:
// Obtain the Activity object that calls the API.
final Activity activity = getActivity();
Task<IsEnvReadyResult> task = Iap.getIapClient(activity).isEnvReady();
task.addOnSuccessListener(new OnSuccessListener<IsEnvReadyResult>() {
@Override
public void onSuccess(IsEnvReadyResult result) {
// Obtain the result of the API request.
String carrierId = result.getCarrierId();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
if (e instanceof IapApiException) {
IapApiException apiException = (IapApiException) e;
// The Status object does not support serialization.
Status status = apiException.getStatus();
if (status.getStatusCode() == OrderStatusCode.ORDER_HWID_NOT_LOGIN) {
// No HUAWEI ID is signed in.
if (status.hasResolution()) {
try {
// 6666 is a constant defined by yourself.
// Open the sign-in page returned.
status.startResolutionForResult(activity, 6666);
} catch (IntentSender.SendIntentException exp) {
}
}
} else if (status.getStatusCode() == OrderStatusCode.ORDER_ACCOUNT_AREA_NOT_SUPPORTED) {
// The service area of the signed-in HUAWEI ID is not a country or region where IAP is available.
}
} else {
// Other external errors.
}
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 6666) {
if (data != null) {
// Call the parseRespCodeFromIntent method to obtain the result of the API request.
int returnCode = IapClientHelper.parseRespCodeFromIntent(data);
}
}
}// Obtain the Activity object that calls the API.
val activity: Activity = getActivity()
val task = Iap.getIapClient(activity).isEnvReady
task.addOnSuccessListener { result ->
// Obtain the result of the API request.
val carrierId = result.carrierId
}.addOnFailureListener { e ->
if (e is IapApiException) {
val apiException = e as IapApiException
// The Status object does not support serialization.
val status: Status = apiException.status
if (status.getStatusCode() === OrderStatusCode.ORDER_HWID_NOT_LOGIN) {
// No HUAWEI ID is signed in.
if (status.hasResolution()) {
try {
// 6666 is a constant defined by yourself.
// Open the sign-in page returned.
status.startResolutionForResult(activity, 6666)
} catch (exp: SendIntentException) {
}
}
} else if (status.getStatusCode() === OrderStatusCode.ORDER_ACCOUNT_AREA_NOT_SUPPORTED) {
// The service area of the signed-in HUAWEI ID is not a country or region where IAP is available.
}
} else {
// Other external errors.
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == 6666) {
if (data != null) {
// Call the parseRespCodeFromIntent method to obtain the result of the API request.
val returnCode = IapClientHelper.parseRespCodeFromIntent(data)
}
}
}Method |
|---|
Task<IsSandboxActivatedResult> isSandboxActivated(IsSandboxActivatedReq isSandboxActivatedReq) Checks whether the signed-in HUAWEI ID and the app version meet the requirements of sandbox testing. |
Parameters
Name | Description |
|---|---|
isSandboxActivatedReq | IsSandboxActivatedReq object that contains request information. |
Return
Type | Description |
|---|---|
Task containing the API request result.
|
Sample code:
// Obtain the Activity object that calls the API.
final Activity activity = getActivity();
IapClient mClient = Iap.getIapClient(activity);
Task<IsSandboxActivatedResult> task = mClient.isSandboxActivated(new IsSandboxActivatedReq());
task.addOnSuccessListener(new OnSuccessListener<IsSandboxActivatedResult>() {
@Override
public void onSuccess(IsSandboxActivatedResult result) {
Log.i("IAP", "isSandboxActivated success");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Log.e("IAP", "isSandboxActivated fail");
if (e instanceof IapApiException) {
IapApiException apiException = (IapApiException) e;
int returnCode = apiException.getStatusCode();
} else {
// Other external errors.
}
}
});// Obtain the Activity object that calls the API.
val activity: Activity = getActivity()
val mClient = Iap.getIapClient(activity)
val task = mClient.isSandboxActivated(IsSandboxActivatedReq())
task.addOnSuccessListener { result ->
Log.i("IAP", "isSandboxActivated success")
}.addOnFailureListener { e ->
Log.e("IAP", "isSandboxActivated fail")
if (e is IapApiException) {
val apiException = e as IapApiException
val returnCode = apiException.statusCode
} else {
// Other external errors.
}
}Method |
|---|
Task<OwnedPurchasesResult> obtainOwnedPurchaseRecord(OwnedPurchasesReq ownedPurchasesReq) Obtains the purchase data of all consumed products or the receipts of all subscriptions.
NOTE To query the purchase data of non-consumables, you should call obtainOwnedPurchases. |
Parameters
Name | Description |
|---|---|
ownedPurchasesReq | OwnedPurchasesReq object that contains request information. |
Returns
Type | Description |
|---|---|
Task containing the API request result.
|
Sample code:
// Construct an OwnedPurchasesReq object.
OwnedPurchasesReq req = new OwnedPurchasesReq();
// 0: consumable; 2: subscription
req.setPriceType(0);
// Obtain the Activity object that calls the API.
final Activity activity = getActivity();
// Call the obtainOwnedPurchaseRecord API.
Task<OwnedPurchasesResult> task = Iap.getIapClient(activity).obtainOwnedPurchaseRecord(req);
task.addOnSuccessListener(new OnSuccessListener<OwnedPurchasesResult>() {
@Override
public void onSuccess(OwnedPurchasesResult result) {
// Obtain the result returned upon a successful API call.
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
if (e instanceof IapApiException) {
IapApiException apiException = (IapApiException) e;
int returnCode = apiException.getStatusCode();
} else {
// Other external errors.
}
}
});// Construct an OwnedPurchasesReq object.
val req = OwnedPurchasesReq()
// 0: consumable; 2: subscription
req.setPriceType(0)
// Obtain the Activity object that calls the API.
val activity: Activity = getActivity()
// Call the obtainOwnedPurchaseRecord API.
val task = Iap.getIapClient(activity).obtainOwnedPurchaseRecord(req)
task.addOnSuccessListener {
// Obtain the result returned upon a successful API call.
}.addOnFailureListener { e ->
if (e is IapApiException) {
val apiException = e as IapApiException
val returnCode = apiException.statusCode
} else {
// Other external errors.
}
}Method |
|---|
Task<OwnedPurchasesResult> obtainOwnedPurchases(OwnedPurchasesReq ownedPurchasesReq) Queries purchase data of the products that a user has bought, including consumables, non-consumables, and subscriptions. Only one type of products can be queried per API call.
NOTICE If you consume a product before delivery, the following exception may occur: When the consumption API is called, the consumption is successfully executed on the server but the result is not returned to the app due to network exceptions. As a result, the product is not delivered. This exception is difficult to handle, so you should consume the product after a successful delivery.
|
Parameters
Name | Description |
|---|---|
ownedPurchasesReq | OwnedPurchasesReq object that contains request information. |
Returns
Type | Description |
|---|---|
Task containing the API request result.
|
Sample code:
// Construct an OwnedPurchasesReq object.
OwnedPurchasesReq ownedPurchasesReq = new OwnedPurchasesReq();
// priceType: 0: consumable; 1: non-consumable; 2: subscription
ownedPurchasesReq.setPriceType(0);
// Obtain the Activity object that calls the API.
final Activity activity = getActivity();
// Call the obtainOwnedPurchases API to obtain the order information about all consumables that have been purchased but not delivered.
Task<OwnedPurchasesResult> task = Iap.getIapClient(activity).obtainOwnedPurchases(ownedPurchasesReq);
task.addOnSuccessListener(new OnSuccessListener<OwnedPurchasesResult>() {
@Override
public void onSuccess(OwnedPurchasesResult result) {
// Obtain the execution result.
if (result != null && result.getInAppPurchaseDataList() != null) {
for (int i = 0; i < result.getInAppPurchaseDataList().size(); i++) {
String inAppPurchaseData = result.getInAppPurchaseDataList().get(i);
String InAppSignature = result.getInAppSignature().get(i);
// Verify the signature using your app's IAP public key.
// Check the purchase status of each product if the verification is successful. When the payment has been made, deliver the required product. After the delivery is performed, consume the product.
try {
InAppPurchaseData inAppPurchaseDataBean = new InAppPurchaseData(inAppPurchaseData);
int purchaseState = inAppPurchaseDataBean.getPurchaseState();
} catch (JSONException e) {
}
}
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
if (e instanceof IapApiException) {
IapApiException apiException = (IapApiException) e;
Status status = apiException.getStatus();
int returnCode = apiException.getStatusCode();
} else {
// Other external errors.
}
}
});// Construct an OwnedPurchasesReq object.
val ownedPurchasesReq = OwnedPurchasesReq()
// priceType: 0: consumable; 1: non-consumable; 2: subscription
ownedPurchasesReq.setPriceType(0)
// Obtain the Activity object that calls the API.
val activity: Activity = getActivity()
// Call the obtainOwnedPurchases API to obtain the order information about all consumables that have been purchased but not delivered.
val task = Iap.getIapClient(activity).obtainOwnedPurchases(ownedPurchasesReq)
task.addOnSuccessListener { result ->
// Obtain the execution result.
if (result != null && result.getInAppPurchaseDataList() != null) {
for (i in result.getInAppPurchaseDataList().indices) {
val inAppPurchaseData = result.getInAppPurchaseDataList()[i]
val InAppSignature = result.getInAppSignature()[i]
// Verify the signature using your app's IAP public key.
// Check the purchase status of each product if the verification is successful. When the payment has been made, deliver the required product. After the delivery is performed, consume the product.
try {
val inAppPurchaseDataBean = InAppPurchaseData(inAppPurchaseData)
val purchaseState = inAppPurchaseDataBean.purchaseState
} catch (e: JSONException) {
}
}
}
}.addOnFailureListener { e ->
if (e is IapApiException) {
val apiException = e as IapApiException
val status: Status = apiException.status
val returnCode = apiException.statusCode
} else {
// Other external errors.
}
}Method |
|---|
Task<ProductInfoResult> obtainProductInfo(ProductInfoReq productInfoReq) Obtains product details configured in AppGallery Connect. If you use Huawei's PMS to price products, you can use this API to obtain product details from the PMS to ensure that the product information in your app is the same as that displayed on the checkout page of HUAWEI IAP. NOTE It is recommended that your app do not obtain product information from your own server. Otherwise, price information may be inconsistent between your app and the checkout screen of IAP. |
Parameters
Name | Description |
|---|---|
productInfoReq | ProductInfoReq object that contains request information. |
Returns
Type | Description |
|---|---|
Task containing the API request result.
|
Sample code:
List<String> productIdList = new ArrayList<>();
// Only those products already configured in AppGallery Connect can be queried.
productIdList.add("ConsumeProduct1001");
ProductInfoReq req = new ProductInfoReq();
// priceType: 0: consumable; 1: non-consumable; 2: subscription
req.setPriceType(0);
req.setProductIds(productIdList);
// Obtain the Activity object that calls the API.
final Activity activity = getActivity();
// Call the obtainProductInfo API to obtain product details configured in AppGallery Connect.
Task<ProductInfoResult> task = Iap.getIapClient(activity).obtainProductInfo(req);
task.addOnSuccessListener(new OnSuccessListener<ProductInfoResult>() {
@Override
public void onSuccess(ProductInfoResult result) {
// Obtain the product details returned upon a successful API call.
List<ProductInfo> productList = result.getProductInfoList();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
if (e instanceof IapApiException) {
IapApiException apiException = (IapApiException) e;
int returnCode = apiException.getStatusCode();
} else {
// Other external errors.
}
}
});val productIdList: MutableList<String> = ArrayList()
// Only those products already configured in AppGallery Connect can be queried.
productIdList.add("ConsumeProduct1001")
val req = ProductInfoReq()
// priceType: 0: consumable; 1: non-consumable; 2: subscription
req.setPriceType(0)
req.productIds = productIdList
// Obtain the Activity object that calls the API.
val activity: Activity = getActivity()
// Call the obtainProductInfo API to obtain product details configured in AppGallery Connect.
val task = Iap.getIapClient(activity).obtainProductInfo(req)
task.addOnSuccessListener { result ->
// Obtain the product details returned upon a successful API call.
val productList = result.getProductInfoList()
}.addOnFailureListener { e ->
if (e is IapApiException) {
val apiException = e as IapApiException
val returnCode = apiException.statusCode
} else {
// Other external errors.
}
}Method |
|---|
PurchaseResultInfo parsePurchaseResultInfoFromIntent(Intent intent) Parses payment result data and returns a PurchaseResultInfo object in the following scenario: After the createPurchaseIntent API is called and the payment page is displayed successfully, the payment result will be called back using the onActivityResult method of Activity. |
Parameters
Name | Description |
|---|---|
intent | Intent object that contains payment result information. |
Returns
Type | Description |
|---|---|
Object that contains payment result information. |
Sample code:
// The payment result is returned in the onActivityResult method of the Activity object that opens the IAP page.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
PurchaseResultInfo purchaseResultInfo = Iap.getIapClient(this).parsePurchaseResultInfoFromIntent(data);
}// The payment result is returned in the onActivityResult method of the Activity object that opens the IAP page.
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
val purchaseResultInfo = Iap.getIapClient(this).parsePurchaseResultInfoFromIntent(data)
}Method |
|---|
Task<StartIapActivityResult> startIapActivity(StartIapActivityReq startIapActivityReq) Displays the subscription editing screen or subscription management screen of HUAWEI IAP. NOTE This method is added in IAP SDK 4.0.4.300 to replace the subscription management screen redirection method provided in earlier versions. |
Parameters
Name | Description |
|---|---|
startIapActivityReq | StartIapActivityReq object that contains request information. |
Returns
Type | Description |
|---|---|
Task containing the API request result.
|
Sample code:
// Redirect to the subscription management screen.
StartIapActivityReq req = new StartIapActivityReq();
req.setType(StartIapActivityReq.TYPE_SUBSCRIBE_MANAGER_ACTIVITY);
// Obtain the Activity object that calls the API.
final Activity activity = getActivity();
IapClient mClient = Iap.getIapClient(activity);
Task<StartIapActivityResult> task = mClient.startIapActivity(req);
task.addOnSuccessListener(new OnSuccessListener<StartIapActivityResult>() {
@Override
public void onSuccess(StartIapActivityResult result) {
Log.i("startIapActivity", "onSuccess");
if (result != null) {
result.startActivity(activity);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Log.e("startIapActivity", "onFailure");
}
});
// Redirect to the subscription editing screen.
StartIapActivityReq req = new StartIapActivityReq();
req.setSubscribeProductId("XXX");
req.setType(StartIapActivityReq.TYPE_SUBSCRIBE_EDIT_ACTIVITY);
// Obtain the Activity object that calls the API.
final Activity activity = getActivity();
IapClient mClient = Iap.getIapClient(activity);
Task<StartIapActivityResult> task = mClient.startIapActivity(req);
task.addOnSuccessListener(new OnSuccessListener<StartIapActivityResult>() {
@Override
public void onSuccess(StartIapActivityResult result) {
Log.i("startIapActivity", "onSuccess");
if (result != null) {
result.startActivity(activity);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Log.e("startIapActivity", "onFailure");
}
});
// Redirect to the subscription management screen.
val req = StartIapActivityReq()
req.setType(StartIapActivityReq.TYPE_SUBSCRIBE_MANAGER_ACTIVITY)
// Obtain the Activity object that calls the API.
val activity: Activity = getActivity()
val mClient = Iap.getIapClient(activity)
val task = mClient.startIapActivity(req)
task.addOnSuccessListener { result ->
Log.i("startIapActivity", "onSuccess")
result?.startActivity(activity)
}.addOnFailureListener { Log.e("startIapActivity", "onFailure") }
// Redirect to the subscription editing screen.
val req = StartIapActivityReq()
req.setSubscribeProductId("XXX")
req.setType(StartIapActivityReq.TYPE_SUBSCRIBE_EDIT_ACTIVITY)
// Obtain the Activity object that calls the API.
val activity: Activity = getActivity()
val mClient = Iap.getIapClient(activity)
val task = mClient.startIapActivity(req)
task.addOnSuccessListener { result ->
Log.i("startIapActivity", "onSuccess")
result?.startActivity(activity)
}.addOnFailureListener { Log.e("startIapActivity", "onFailure") }