In the second part of the article about my New Year's toy, I will tell you about in-game purchases inside. I do not like advertising in applications at all, on this issue of embedding advertising in my application, for me it disappeared immediately. My experience of laying out paid games in Gooogle Play says that the number of people who want to download this game drops dramatically, this option of selling the game has also disappeared. And since I don’t want to make a fortune from a game, but I do it more for my own pleasure, I decided that let users decide whether to pay something or not.
apply plugin: 'com.android.application' android { compileSdkVersion 26 defaultConfig { applicationId "ru.crazyprojects.android.newyeartree" minSdkVersion 14 targetSdkVersion 26 versionCode 8 versionName '1.8' testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } productFlavors { } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:0.5' androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2' compile 'com.anjlab.android.iab.v3:library:1.0.44' } import com.anjlab.android.iab.v3.BillingProcessor; import com.anjlab.android.iab.v3.TransactionDetails; public class NewYearTree extends AppCompatActivity implements BillingProcessor.IBillingHandler { ... } public class NewYearTree extends AppCompatActivity implements BillingProcessor.IBillingHandler { BillingProcessor bp; ........... @Override public void onBillingInitialized() { /* * , */ } @Override public void onProductPurchased(String productId, TransactionDetails details) { /* * */ } @Override public void onBillingError(int errorCode, Throwable error) { /* * - */ } @Override public void onPurchaseHistoryRestored() { /* * . * , , */ } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // , , if (!bp.handleActivityResult(requestCode, resultCode, data)) { super.onActivityResult(requestCode, resultCode, data); } } } protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ........ if(!BillingProcessor.isIabServiceAvailable(this)) { Toast.makeText(this, "In-app billing service is unavailable.", Toast.LENGTH_LONG).show(); } bp = new BillingProcessor(this, " Google Play", this); // . bp.initialize(); } @Override public void onBillingInitialized() { Log.d("LOG", "On Billing Initialaized"); // } @Override public void onProductPurchased(String productId, TransactionDetails details) { Toast.makeText(this, "Thanks for Your donate. "+productId, Toast.LENGTH_LONG).show(); // bp.consumePurchase(productId); // , . } @Override public void onBillingError(int errorCode, Throwable error) { Log.d("LOG", "On Billing Error"+Integer.toString(errorCode)); // } @Override public void onPurchaseHistoryRestored() { // , . // , } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { //Toast.makeText(this, "On Activity Result", Toast.LENGTH_LONG).show(); Log.d("LOG", "On Activity Result"); if (!bp.handleActivityResult(requestCode, resultCode, data)) { super.onActivityResult(requestCode, resultCode, data); } } // , public void donate(String ProductID) { bp.purchase(this, ProductID); // } bp = new BillingProcessor(this, "MIIBIjANBgkqhkiG9w0BAQEFAAOCA......................................................................................", this); bp.purchase(this, "one_dollar_donate"); Source: https://habr.com/ru/post/344566/
All Articles