本文整理汇总了Java中com.android.vending.billing.IInAppBillingService类的典型用法代码示例。如果您正苦于以下问题:Java IInAppBillingService类的具体用法?Java IInAppBillingService怎么用?Java IInAppBillingService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IInAppBillingService类属于com.android.vending.billing包,在下文中一共展示了IInAppBillingService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onServiceConnected
import com.android.vending.billing.IInAppBillingService; //导入依赖的package包/类
/**
* For some reason, that method is always called on the main thread
* Regardless of the originating thread executing bindService()
*/
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
ReactiveBilling.log(null, "Service connected (thread %s)", Thread.currentThread().getName());
IInAppBillingService inAppBillingService = IInAppBillingService.Stub.asInterface(service);
billingService = new BillingService(context, inAppBillingService);
if (useSemaphore) {
// once the service is available, release the semaphore
// that is blocking the originating thread
ReactiveBilling.log(null, "Release semaphore (thread %s)", Thread.currentThread().getName());
semaphore.release();
} else {
deliverBillingService(observer);
}
}
示例2: getBuyIntent
import com.android.vending.billing.IInAppBillingService; //导入依赖的package包/类
private Bundle getBuyIntent(IInAppBillingService service, List<String> oldItemIds,
String itemId, String developerPayload) throws BillingException {
try {
// Purchase an item
if (oldItemIds == null || oldItemIds.isEmpty()) {
return service.getBuyIntent(
mApiVersion, mPackageName, itemId, mItemType, developerPayload);
}
// Upgrade/downgrade of subscriptions must be done on api version 5
// See https://developer.android.com/google/play/billing/billing_reference.html#upgrade-getBuyIntentToReplaceSkus
return service.getBuyIntentToReplaceSkus(
BillingApi.VERSION_5.getValue(),
mPackageName,
oldItemIds,
itemId,
mItemType,
developerPayload);
} catch (RemoteException e) {
throw new BillingException(Constants.ERROR_REMOTE_EXCEPTION, e.getMessage());
}
}
示例3: setBinder
import com.android.vending.billing.IInAppBillingService; //导入依赖的package包/类
private void setBinder(android.os.IBinder binder) {
IInAppBillingService service = IInAppBillingService.Stub.asInterface(binder);
Handler handler = mHandler;
mHandler = null;
if (handler == null) {
return;
}
if (service == null) {
BillingException e = new BillingException(
Constants.ERROR_BIND_SERVICE_FAILED_EXCEPTION,
Constants.ERROR_MSG_BIND_SERVICE_FAILED_SERVICE_NULL);
postBinderError(e, handler);
} else {
postBinder(service, handler);
}
}
示例4: isSupported
import com.android.vending.billing.IInAppBillingService; //导入依赖的package包/类
/**
* Check if the device supports InAppBilling
*
* @param service
* @return true if it is supported
*/
protected boolean isSupported(PurchaseType purchaseType, IInAppBillingService service) throws RemoteException {
String type;
if (purchaseType == PurchaseType.SUBSCRIPTION) {
type = Constants.TYPE_SUBSCRIPTION;
} else {
type = Constants.TYPE_IN_APP;
}
int response = service.isBillingSupported(
mContext.getApiVersion(),
mContext.getContext().getPackageName(),
type);
if (response == Constants.BILLING_RESPONSE_RESULT_OK) {
mLogger.d(Logger.TAG, "Subscription is AVAILABLE.");
return true;
}
mLogger.w(Logger.TAG,
String.format(Locale.US, "Subscription is NOT AVAILABLE. Response: %d", response));
return false;
}
示例5: executeInService
import com.android.vending.billing.IInAppBillingService; //导入依赖的package包/类
private void executeInService(final ServiceBinder.Handler serviceHandler, Handler handler) {
handler.post(new Runnable() {
@Override
public void run() {
final ServiceBinder conn = createServiceBinder();
conn.getServiceAsync(new ServiceBinder.Handler() {
@Override
public void onBind(IInAppBillingService service) {
try {
serviceHandler.onBind(service);
} finally {
conn.unbindService();
}
}
@Override
public void onError(BillingException e) {
serviceHandler.onError(e);
}
});
}
});
}
示例6: onServiceConnected
import com.android.vending.billing.IInAppBillingService; //导入依赖的package包/类
@Test
public void onServiceConnected() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
Intent intent = new Intent(Constants.ACTION_BILLING_SERVICE_BIND);
intent.setPackage(Constants.VENDING_PACKAGE);
final ServiceBinder conn = new ServiceBinder(
mDataConverter.newBillingContext(RuntimeEnvironment.application), intent);
conn.getServiceAsync(new ServiceBinder.Handler() {
@Override
public void onBind(IInAppBillingService service) {
assertThat(service).isNotNull();
latch.countDown();
}
@Override
public void onError(BillingException e) {
throw new IllegalStateException(e);
}
});
conn.onServiceConnected(null, mServiceStub.create(new Bundle()).asBinder());
latch.await(15, TimeUnit.SECONDS);
}
示例7: onServiceDisconnected
import com.android.vending.billing.IInAppBillingService; //导入依赖的package包/类
@Test
public void onServiceDisconnected() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
Intent intent = new Intent(Constants.ACTION_BILLING_SERVICE_BIND);
intent.setPackage(Constants.VENDING_PACKAGE);
final ServiceBinder conn = new ServiceBinder(
mDataConverter.newBillingContext(RuntimeEnvironment.application), intent);
conn.getServiceAsync(new ServiceBinder.Handler() {
@Override
public void onBind(IInAppBillingService service) {
assertThat(service).isNotNull();
conn.onServiceDisconnected(null);
latch.countDown();
}
@Override
public void onError(BillingException e) {
throw new IllegalStateException(e);
}
});
conn.onServiceConnected(null, mServiceStub.create(new Bundle()).asBinder());
latch.await(15, TimeUnit.SECONDS);
}
示例8: unbindService
import com.android.vending.billing.IInAppBillingService; //导入依赖的package包/类
@Test
public void unbindService() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
Intent intent = new Intent(Constants.ACTION_BILLING_SERVICE_BIND);
intent.setPackage(Constants.VENDING_PACKAGE);
final ServiceBinder conn = new ServiceBinder(
mDataConverter.newBillingContext(RuntimeEnvironment.application), intent);
conn.getServiceAsync(new ServiceBinder.Handler() {
@Override
public void onBind(IInAppBillingService service) {
conn.unbindService();
latch.countDown();
}
@Override
public void onError(BillingException e) {
throw new IllegalStateException(e);
}
});
conn.onServiceConnected(null, mServiceStub.create(new Bundle()).asBinder());
latch.await(15, TimeUnit.SECONDS);
}
示例9: callGetServiceAsyncTwice
import com.android.vending.billing.IInAppBillingService; //导入依赖的package包/类
@Test
public void callGetServiceAsyncTwice() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
Intent intent = new Intent(Constants.ACTION_BILLING_SERVICE_BIND);
intent.setPackage(Constants.VENDING_PACKAGE);
final ServiceBinder conn = new ServiceBinder(
mDataConverter.newBillingContext(RuntimeEnvironment.application), intent);
ServiceBinder.Handler handler = new ServiceBinder.Handler() {
@Override
public void onBind(IInAppBillingService service) {
conn.unbindService();
latch.countDown();
}
@Override
public void onError(BillingException e) {
throw new IllegalStateException(e);
}
};
conn.getServiceAsync(handler);
conn.getServiceAsync(handler);
conn.onServiceConnected(null, mServiceStub.create(new Bundle()).asBinder());
latch.await(15, TimeUnit.SECONDS);
}
示例10: bindService
import com.android.vending.billing.IInAppBillingService; //导入依赖的package包/类
@Test
public void bindService() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
Intent intent = new Intent(Constants.ACTION_BILLING_SERVICE_BIND);
intent.setPackage(Constants.VENDING_PACKAGE);
final ServiceBinder conn = new ServiceBinder(
mDataConverter.newBillingContext(RuntimeEnvironment.application), intent);
ServiceBinder.Handler handler = new ServiceBinder.Handler() {
@Override
public void onBind(IInAppBillingService service) {
assertThat(service).isNotNull();
latch.countDown();
}
@Override
public void onError(BillingException e) {
throw new IllegalStateException(e);
}
};
conn.getServiceAsync(handler);
latch.await(15, TimeUnit.SECONDS);
}
示例11: connectService
import com.android.vending.billing.IInAppBillingService; //导入依赖的package包/类
private Single<Ignore> connectService() {
return Single.create(new SingleOnSubscribe<Ignore>() {
@Override public void subscribe(final SingleEmitter<Ignore> emitter) throws Exception {
if (serviceConnection == null) {
serviceConnection = new ServiceConnection() {
@Override public void onServiceDisconnected(ComponentName name) {
rxBillingServiceLogger.log(getTargetClassName(), "Service disconnected");
appBillingService = null;
emitter.onError(
new RxBillingServiceException(RxBillingServiceError.SERVICE_DISCONNECTED));
}
@Override public void onServiceConnected(ComponentName name, final IBinder service) {
rxBillingServiceLogger.log(getTargetClassName(), "Service connected");
appBillingService = IInAppBillingService.Stub.asInterface(service);
emitter.onSuccess(Ignore.Get);
}
};
bindService();
} else {
emitter.onSuccess(Ignore.Get);
}
}
});
}
示例12: loadInstance
import com.android.vending.billing.IInAppBillingService; //导入依赖的package包/类
private void loadInstance(final Context activityContext) {
if (activityContext != null && this.activityContext == null)
this.activityContext = activityContext;
mServiceConn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
// Service connected : we can now check if the user has purchased smth for example
launchPurchase(productToBuy);
unbind();
}
};
Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
intent.setPackage("com.android.vending");
isBound = this.activityContext.bindService(intent, mServiceConn, Context.BIND_AUTO_CREATE);
}
示例13: BillingManager
import com.android.vending.billing.IInAppBillingService; //导入依赖的package包/类
/**
* Creates a new {@link BillingManager} for your Activity.
* @param activity The activity that initiates purchase requests.
*/
public BillingManager(final Activity activity) {
this.activity = activity;
this.connection = new ServiceConnection() {
@Override
public void onServiceConnected(final ComponentName name, final IBinder service) {
BillingManager.this.service = IInAppBillingService.Stub.asInterface(service);
BillingManager.this.connected = true;
if (BillingManager.this.onConnectListener != null) {
BillingManager.this.onConnectListener.onConnect();
}
}
@Override
public void onServiceDisconnected(final ComponentName name) {
BillingManager.this.service = null;
BillingManager.this.connected = false;
if (BillingManager.this.onDisconnectListener != null) {
BillingManager.this.onDisconnectListener.onDisconnect();
}
}
};
}
示例14: consumeAllPurchases
import com.android.vending.billing.IInAppBillingService; //导入依赖的package包/类
public static void consumeAllPurchases(Activity activity, SupportAppDevelopmentDialogFragment dialog, IInAppBillingService mService) {
try {
Bundle ownedItems = mService.getPurchases(3, activity.getPackageName(), IabHelper.ITEM_TYPE_INAPP, null);
int response = ownedItems.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
for (String purchaseData : purchaseDataList) {
JSONObject jo = new JSONObject(purchaseData);
mService.consumePurchase(3, activity.getPackageName(), jo.getString("purchaseToken"));
}
}
} catch (Exception e) {
ActivityTracker.sendEvent(activity, ActivityTracker.CAT_BE, "message_err_billing_check_error", e.getMessage(), 0L);
Log.e(TAG, "InApp billing - exception " + e.getMessage());
}
}
示例15: consumeDisposablePurchases
import com.android.vending.billing.IInAppBillingService; //导入依赖的package包/类
public static void consumeDisposablePurchases(Activity activity, IInAppBillingService mService) {
try {
Bundle ownedItems = mService.getPurchases(3, activity.getPackageName(), IabHelper.ITEM_TYPE_INAPP, null);
int response = ownedItems.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
for (String purchaseData : purchaseDataList) {
JSONObject jo = new JSONObject(purchaseData);
if (INAPP_CODE_DONATION_3.equals(jo.getString("productId")))
mService.consumePurchase(3, activity.getPackageName(), jo.getString("purchaseToken"));
}
}
} catch (Exception e) {
ActivityTracker.sendEvent(activity, ActivityTracker.CAT_BE, "message_err_billing_check_error", e.getMessage(), 0L);
Log.e(TAG, "InApp billing - exception " + e.getMessage());
}
}