Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ActivityBuy extends AppCompatActivity {
- IabHelper mHelper;
- public static final int BUY_CODE = 13;
- IInAppBillingService mService;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState); // <== строка 31
- setContentView(R.layout.dialog_buy);
- findViewById(R.id.dialogExit).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- finish();
- }
- });
- findViewById(R.id.dialogBuy).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- try {
- buyFullResolve();
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- finish();
- }
- });
- Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
- serviceIntent.setPackage("com.android.vending");
- bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
- String base64EncodedPublicKey = getString(R.string.licence);
- mHelper = new IabHelper(this, base64EncodedPublicKey);
- mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
- public void onIabSetupFinished(IabResult result) {
- if (!result.isSuccess()) {
- Log.d("ttt", "Problem setting up In-app Billing: " + result);
- } else {
- Log.d("ttt", "Success: " + result);
- mHelper.queryInventoryAsync(mGotInventoryListener);
- }
- }
- });
- }
- IabHelper.QueryInventoryFinishedListener mGotInventoryListener
- = new IabHelper.QueryInventoryFinishedListener() {
- public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
- if (result.isFailure()) {
- StaticToaster.makeToaster(getLayoutInflater(), ActivityBuy.this, getString(R.string.noconnection), true, true);
- } else {
- //
- }
- }
- };
- public void buyFullResolve() throws RemoteException {
- ArrayList<String> skuList = new ArrayList<String>();
- skuList.add(getString(R.string.buyFullID));
- Bundle querySkus = new Bundle();
- querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
- try {
- if (mHelper != null) mHelper.flagEndAsync();
- mHelper.launchPurchaseFlow(this, getString(R.string.buyFullID), BUY_CODE, mPurchaseFinishedListener, getString(R.string.randomKey));
- } catch (IllegalStateException e) {
- StaticToaster.makeToaster(getLayoutInflater(), this, "Покупка не удалась. Попробуйте через несколько секунд.", false, false);
- }
- }
- IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
- = new IabHelper.OnIabPurchaseFinishedListener() {
- public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
- if (result.isFailure()) {
- Log.d("ttt", "Error purchasing: " + result);
- setResult(RESULT_CANCELED);
- } else if (purchase.getSku().equals(getString(R.string.buyFullID))) {
- MyLab.get(ActivityBuy.this).setFullVersion(true);
- StaticToaster.makeToaster(getLayoutInflater(), ActivityBuy.this, getString(R.string.fullSuccess), false, false);
- setResult(RESULT_OK);
- finish();
- }
- }
- };
- ServiceConnection mServiceConn = new ServiceConnection() {
- @Override
- public void onServiceDisconnected(ComponentName name) {
- mService = null;
- }
- @Override
- public void onServiceConnected(ComponentName name,
- IBinder service) {
- mService = IInAppBillingService.Stub.asInterface(service);
- }
- };
- private void queryPurchasedItems() {
- if (mHelper.isSetupDone() && !mHelper.isAsyncInProgress()) {
- mHelper.queryInventoryAsync(mGotInventoryListener);
- }
- }
- <style name="myDialogStyle" parent="Theme.AppCompat.Dialog.Alert">
- <item name="windowActionBar">false</item>
- <item name="windowNoTitle">true</item>
- </style>
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
- <TextView
- style="@style/textStyle"
- android:text="@string/buyFullHeader"
- android:id="@+id/header"/>
- <TextView
- android:id="@+id/dialogHeaderText"
- style="@style/textStyle"
- android:text="@string/buyFullVersion" />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <Button
- android:id="@+id/dialogExit"
- android:text="@string/back"
- style="@style/dialogButton"/>
- <Button
- android:id="@+id/dialogBuy"
- android:text="@string/buy"
- style="@style/dialogButton"/>
- </LinearLayout>
- compileSdkVersion 27
- buildToolsVersion "27.0.3"
- defaultConfig {
- applicationId "id"
- minSdkVersion 14
- targetSdkVersion 27
- versionCode 1
- versionName "1.1"
- }
Add Comment
Please, Sign In to add comment