私はAndroid開発にかなり新しく、アプリの請求でGoogleを実装する方法を理解する上で大きな問題を抱えています。私は公式のGoogleドキュメントを読んだり、チュートリアルなどを読んだり、私には分かりやすいものは次のとおりです。それでも私はそれを働かせるのに苦労しています。 http://redappz.com/micro-transactions-tutorial-iap-for-android/Androidでのアプリ請求の実装が混乱していますか?
私がしたことは、すべてのヘルパークラスを単純なドライブからインポートしたことです。署名付きAPKのgoogle devアカウントを持っています。
購入はBボタンを表示するアクティビティA.活動に成功したとき、私は自分のアプリケーションのためにしたいロジックがあります。
public class WorkoutPlan1 extends AppCompatActivity {
private Button WorkoutPlan1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_workoutplan1);
WorkoutPlan1 = (Button) findViewById(R.id.Workout1MoreInfo);
任意のGoogle請求書を含む基本コード。基本的なボタンはGoogleの請求をオフにするだけです。
public class WorkoutPlan1 extends AppCompatActivity {
private Button WorkoutPlan1;
//*************************************************************************************************************************
// Debug tag, for logging
static final String TAG = "test";
// SKUs for our products: the premium upgrade (non-consumable)
static final String SKU_PREMIUM = "android.test.purchased";
// Does the user have the premium upgrade?
boolean mIsPremium = false;
// (arbitrary) request code for the purchase flow
static final int RC_REQUEST = 1;
// The helper object
IabHelper mHelper;
//*************************************************************************************************************************
@Override
protected void onCreate(Bundle savedInstanceState) {
//*************************************************************************************************************************
String base64EncodedPublicKey = "KEY GOES HERE FROM MY GOOGLE DEV";
//It is recommended to add more security than just pasting it in your source code;
mHelper = new IabHelper(this, base64EncodedPublicKey);
Log.d(TAG, "Starting setup.");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
Log.d(TAG, "Setup finished.");
if (!result.isSuccess()) {
// Oh noes, there was a problem.
Log.d(TAG, "Problem setting up In-app Billing: " + result);
}
// Hooray, IAB is fully set up!
// mHelper.queryInventoryAsync(mGotInventoryListener);
}
});
//*************************************************************************************************************************
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_workoutplan1);
WorkoutPlan1 = (Button) findViewById(R.id.Workout1MoreInfo);
}
//*************************************************************************************************************************
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG, "Query inventory finished.");
if (result.isFailure()) {
Log.d(TAG, "Failed to query inventory: " + result);
return;
}
else {
Log.d(TAG, "Query inventory was successful.");
// does the user have the premium upgrade?
mIsPremium = inventory.hasPurchase(SKU_PREMIUM);
// update UI accordingly
WorkoutPlan1.setVisibility(View.VISIBLE);
Log.d(TAG, "User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM"));
}
Log.d(TAG, "Initial inventory query finished; enabling main UI.");
}
};
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
if (result.isFailure()) {
Log.d(TAG, "Error purchasing: " + result);
return;
}
else if (purchase.getSku().equals(SKU_PREMIUM)) {
// give user access to premium content and update the UI
WorkoutPlan1.setVisibility(View.VISIBLE);
}
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
} else {
Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}
私はボタンにonclickリスナーを持っていません。しかし、私はどのように私は支払い/購入の流れを呼び出すか知りません。
この時点で私はちょうど失われた感じとして正しい方向に私を指すようにAT ALLすべてのヘルプはそう、いただければ幸いです。
ありがとうございました
http://stackoverflow.com/questions/8735931/android-in-app-billing-tutorial?rq=1 –