Ich habe ein einfache Test App erstellt mit drei Buttons und möchte, wenn man auf den Button klickt, wird der Kaufvorgang eingeleitet. Wenn der Kaufvorgang fertig ist, wird das "Produkt" gutgeschrieben. Ich habe dafür ein Youtub Video angeschaut und für meine Verhältnisse umgeschrieben, da er was anderes machen wollte.
Ich habe 2 Probleme und hoffe, ihr könnt mir helfen.
Problem 1:
- Wenn ich auf dem Button klicke wird das Produkt gutgeschrieben und erst dann geht der Kaufvorgang los. Wie mache ich es, das erst der KAufvorgang kommt und wenn alles stimmt, das "Produkt" gutgeschrieben wird? Es bringt ja nicht, wenn man "umsonst" Produkte bekommt.
Problem 2:
- Ich bin Test Nutzer im Interner Test, aber wenn ich das Produkt kaufen möchte, für den Test, bekomme ich keine Test Card zum bezahlen. Wiso bekomme ich als Tester keine Test Card? Ich kann ja nicht mehrere hundert Euros ausgeben, nur fürs testen.
Ich hoffe, dass mir hier sehr gut geholfen wird. Dann können andere, die das selbe Problem haben, wissen, wie es geht.
Ich werde den Code als Open Source für die Community anbieten...
PS.: Ich mache das zum erstenmal so richtig....
Ich danke schon mal im Vorfeld!
Hier die Codes:
[CODE lang="java" title="MainActivity.class"]package com.............;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import com.anjlab.android.iab.v3.BillingProcessor;
import com.anjlab.android.iab.v3.TransactionDetails;
public class MainActivity extends AppCompatActivity implements BillingProcessor.IBillingHandler {
private BillingProcessor bp;
private TextView coinText;
private Button btn1, btn2, btn3;
private int coins = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences prefsnetzeinstellung = getSharedPreferences("Coins", MODE_PRIVATE);
coins = prefsnetzeinstellung.getInt("coins", coins);
coinText = findViewById(R.id.textView);
coinText.setText(coins + " Coins");
btn1 = findViewById(R.id.button);
btn2 = findViewById(R.id.button2);
btn3 = findViewById(R.id.button3);
bp = new BillingProcessor(this, getResources().getString(R.string.play_console_license), this);
bp.initialize();
}
@Override
public void onBillingInitialized() {
btn1.setOnClickListener(v ->{
if(bp.isOneTimePurchaseSupported()){
bp.purchase(this, "button1");
coins += 2;
SharedPreferences prefs = getSharedPreferences("Coins", MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("coins" , coins);
editor.apply();
coinText.setText(coins + " Coins");
}else{
}
});
btn2.setOnClickListener(v ->{
if(bp.isOneTimePurchaseSupported()){
bp.purchase(this, "button2");
coins += 5;
SharedPreferences prefs = getSharedPreferences("Coins", MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("coins" , coins);
editor.apply();
coinText.setText(coins + " Coins");
}else{
}
});
btn3.setOnClickListener(v ->{
if(bp.isOneTimePurchaseSupported()){
bp.purchase(this, "button3");
coins += 8;
SharedPreferences prefs = getSharedPreferences("Coins", MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("coins" , coins);
editor.apply();
coinText.setText(coins + " Coins");
}else{
}
});
}
@Override
public void onProductPurchased(String productId, TransactionDetails details) {
}
@Override
public void onPurchaseHistoryRestored() {
}
@Override
public void onBillingError(int errorCode, Throwable error) {
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (!bp.handleActivityResult(requestCode,resultCode, data)){
super.onActivityResult(requestCode, resultCode, data);
}
}
@Override
public void onDestroy() {
if (bp != null){
bp.release();
}
super.onDestroy();
}
}[/CODE]
[CODE lang="java" title="build.gradle(app)"]plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "........."
minSdkVersion 21
targetSdkVersion 30
versionCode 4
versionName "4.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.anjlab.android.iab.v3:library:1.0.44'
def billing_version = "4.0.0"
implementation "com.android.billingclient:billing:$billing_version"
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}[/CODE]
Ich habe 2 Probleme und hoffe, ihr könnt mir helfen.
Problem 1:
- Wenn ich auf dem Button klicke wird das Produkt gutgeschrieben und erst dann geht der Kaufvorgang los. Wie mache ich es, das erst der KAufvorgang kommt und wenn alles stimmt, das "Produkt" gutgeschrieben wird? Es bringt ja nicht, wenn man "umsonst" Produkte bekommt.
Problem 2:
- Ich bin Test Nutzer im Interner Test, aber wenn ich das Produkt kaufen möchte, für den Test, bekomme ich keine Test Card zum bezahlen. Wiso bekomme ich als Tester keine Test Card? Ich kann ja nicht mehrere hundert Euros ausgeben, nur fürs testen.
Ich hoffe, dass mir hier sehr gut geholfen wird. Dann können andere, die das selbe Problem haben, wissen, wie es geht.
Ich werde den Code als Open Source für die Community anbieten...
PS.: Ich mache das zum erstenmal so richtig....
Ich danke schon mal im Vorfeld!
Hier die Codes:
[CODE lang="java" title="MainActivity.class"]package com.............;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import com.anjlab.android.iab.v3.BillingProcessor;
import com.anjlab.android.iab.v3.TransactionDetails;
public class MainActivity extends AppCompatActivity implements BillingProcessor.IBillingHandler {
private BillingProcessor bp;
private TextView coinText;
private Button btn1, btn2, btn3;
private int coins = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences prefsnetzeinstellung = getSharedPreferences("Coins", MODE_PRIVATE);
coins = prefsnetzeinstellung.getInt("coins", coins);
coinText = findViewById(R.id.textView);
coinText.setText(coins + " Coins");
btn1 = findViewById(R.id.button);
btn2 = findViewById(R.id.button2);
btn3 = findViewById(R.id.button3);
bp = new BillingProcessor(this, getResources().getString(R.string.play_console_license), this);
bp.initialize();
}
@Override
public void onBillingInitialized() {
btn1.setOnClickListener(v ->{
if(bp.isOneTimePurchaseSupported()){
bp.purchase(this, "button1");
coins += 2;
SharedPreferences prefs = getSharedPreferences("Coins", MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("coins" , coins);
editor.apply();
coinText.setText(coins + " Coins");
}else{
}
});
btn2.setOnClickListener(v ->{
if(bp.isOneTimePurchaseSupported()){
bp.purchase(this, "button2");
coins += 5;
SharedPreferences prefs = getSharedPreferences("Coins", MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("coins" , coins);
editor.apply();
coinText.setText(coins + " Coins");
}else{
}
});
btn3.setOnClickListener(v ->{
if(bp.isOneTimePurchaseSupported()){
bp.purchase(this, "button3");
coins += 8;
SharedPreferences prefs = getSharedPreferences("Coins", MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("coins" , coins);
editor.apply();
coinText.setText(coins + " Coins");
}else{
}
});
}
@Override
public void onProductPurchased(String productId, TransactionDetails details) {
}
@Override
public void onPurchaseHistoryRestored() {
}
@Override
public void onBillingError(int errorCode, Throwable error) {
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (!bp.handleActivityResult(requestCode,resultCode, data)){
super.onActivityResult(requestCode, resultCode, data);
}
}
@Override
public void onDestroy() {
if (bp != null){
bp.release();
}
super.onDestroy();
}
}[/CODE]
[CODE lang="java" title="build.gradle(app)"]plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "........."
minSdkVersion 21
targetSdkVersion 30
versionCode 4
versionName "4.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.anjlab.android.iab.v3:library:1.0.44'
def billing_version = "4.0.0"
implementation "com.android.billingclient:billing:$billing_version"
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}[/CODE]