मैं अपने बालों को खींच रहा हूं! पिछले हफ्ते में एक बिंदु पर, मैंने यह काम किया था।एंड्रॉइड आईएबी - सफल खरीद के बाद गतिविधि नष्ट हो गई
मेरे पास एक एंड्रॉइड ऐप है जिसे मैं इन-एपी बिलिंग जोड़ने की कोशिश कर रहा हूं। मैंने नमूना TrivialDrive का पालन किया, और मेरे कोड कुछ बार काम किया। अब यह नहीं है।
मैं एक साधारण ट्रिविया गेम बना रहा हूं जिसमें कई मुफ्त प्रश्न हैं, और अधिक प्रश्न प्राप्त करने के लिए अपग्रेड करने का विकल्प है। जब उपयोगकर्ता मुफ्त प्रश्नों की सूची पूरी करता है, तो उन्हें "गेम ओवर" स्क्रीन पर ले जाया जाता है जहां वे अपने उत्तरों मिटा सकते हैं और फिर से शुरू कर सकते हैं या अपग्रेड कर सकते हैं।
जब मैं "अपग्रेड" बटन पर क्लिक करता हूं, तो मैं एक सफल खरीद कर सकता हूं, लेकिन जैसे ही Google "भुगतान सफल" संवाद दूर हो जाता है, मेरी गतिविधि नष्ट हो जाती है और मुझे अपनी मुख्य गतिविधि में वापस भेज दिया जाता है।
जब मैं वापस जाने और फिर से अपनी खरीद करने की कोशिश करता हूं, तो मेरा कोड त्रुटि को पकड़ता है ("आप पहले से ही इस आइटम के स्वामी हैं") और इसे उचित तरीके से संभालते हैं। मेरा कोड उपयोगकर्ता को बताता है कि उनके पास पहले से ही अपग्रेड है, और उन्हें खेलने के लिए एक बटन क्लिक करने की अनुमति देता है। तो ऐसा लगता है कि OnIabPurchaseFinishedListener इस बिंदु पर गोलीबारी कर रहा है।
मैंने नवीनतम फाइलों के साथ Google सहायक कोड अपडेट किया है।
उत्तर की तलाश करने के लिए कहां से कोई मदद या सुझाव बहुत सराहना की है।
धन्यवाद।
यह मेरा गतिविधि के लिए प्रासंगिक कोड है:
public class GameOverActivity extends BaseActivity
{
private IabHelper mHelper;
private String m_base64EncodedPublicKey;
private static String THE_UPGRADE_SKU = "upgrade52";
public static int BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED = 7;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_over);
setTitle("Game Over");
Button butPlay = (Button) findViewById(R.id.buttonPlay);
butPlay.setVisibility(View.INVISIBLE);
PrepareIAB();
}
@Override
protected void onResume()
{
super.onResume();
CURRENT_ACTIVITY = ACTIVITY_GAME_OVER;
SetMainText();
}
@Override
protected void onDestroy()
{
super.onDestroy();
try
{
if (mHelper != null)
{
mHelper.dispose();
mHelper = null;
}
}
catch (Exception e)
{
}
}
private void PrepareIAB()
{
m_base64EncodedPublicKey = "MyKey";
// compute your public key and store it in base64EncodedPublicKey
mHelper = new IabHelper(this, m_base64EncodedPublicKey);
mHelper.enableDebugLogging(true, TAG);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener()
{
public void onIabSetupFinished(IabResult result)
{
if (!result.isSuccess())
{
ShowMessage("There was an error connecting to the Google Play Store.");
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
try
{
// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data))
{
// not handled, so handle it ourselves (here's where you'd
// perform any handling of activity results not related to in-app
// billing...
super.onActivityResult(requestCode, resultCode, data);
}
else
{
// Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}
catch (Exception e)
{
super.onActivityResult(requestCode, resultCode, data);
}
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener =
new IabHelper.OnIabPurchaseFinishedListener()
{
public void onIabPurchaseFinished(IabResult result, Purchase purchase)
{
try
{
if (result.isFailure())
{
if (result.mResponse==7)
{
UpgradeComplete();
ShowMessage("Thank you for upgrading.\r\n\r\nThis version has 400 more questions.");
}
else
{
ShowMessage("Error purchasing: " + String.valueOf(result.mResponse));
UpgradeError();
return;
}
}
else if (purchase.getSku().equals(THE_UPGRADE_SKU))
{
UpgradeComplete();
ShowMessage("Thank you for upgrading.\r\n\r\nThis version has 400 more questions.");
}
else
{
ShowMessage("Something else happened. ");
}
}
catch (Exception e)
{
Log.e(TAG, e.getLocalizedMessage());
}
}
};
private void HideUpgrade()
{
try
{
Button btnUpgrade = (Button) findViewById(R.id.buttonUpgrade);
if (btnUpgrade != null)
{
btnUpgrade.setVisibility(View.INVISIBLE);
}
TextView txtMessage = (TextView) findViewById(R.id.txtUpgradeFromGameOver);
if (txtMessage!=null)
{
txtMessage.setVisibility(View.INVISIBLE);
}
}
catch (Exception e)
{
}
}
public void onQuitButtonClick(View view)
{
finish();
}
public void onResetDBButtonClick(View view)
{
ConfirmResetDatabase();
}
private void ConfirmResetDatabase()
{
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
switch (which)
{
case DialogInterface.BUTTON_POSITIVE:
ResetDatabase();
Intent gameActivity = new Intent(getApplicationContext(), GameActivity.class);
gameActivity.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
// startActivityForResult(gameActivity, ACTIVITY_GAME);
startActivity(gameActivity);
break;
case DialogInterface.BUTTON_NEGATIVE:
// No button clicked
break;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Do you want to erase your score and start over?").setPositiveButton("Yes", dialogClickListener).setNegativeButton("No", dialogClickListener).show();
}
public void onUpgradeButtonClick(View view)
{
try
{
if (mHelper != null)
{
mHelper.launchPurchaseFlow(this, THE_UPGRADE_SKU, 10001, mPurchaseFinishedListener, m_TriviaAppInstance.AppInstallID());
}
else
{
ShowMessage("Unable to connect to Google Play Store.");
}
}
catch (Exception e)
{
ShowMessage("Unable to connect to Google Play Store.");
SendErrorMessage(e.getLocalizedMessage());
}
}
private void UpgradeComplete()
{
try
{
HideUpgrade();
Button butPlay = (Button) findViewById(R.id.buttonPlay);
if (butPlay!=null)
{
butPlay.setVisibility(View.VISIBLE);
}
TextView txtReset = (TextView) findViewById(R.id.txtGameOverRestDB);
if (txtReset!=null)
{
txtReset.setVisibility(View.INVISIBLE);
}
Button btnReset = (Button)findViewById(R.id.buttonResetDB);
if (btnReset!=null)
{
btnReset.setVisibility(View.INVISIBLE);
}
m_TriviaAppInstance.SetUpgradedStatus(true);
}
catch (Exception e)
{
}
//
}
private void UpgradeError()
{
try
{
Button butUpgrade;
butUpgrade = (Button) findViewById(R.id.buttonUpgrade);
butUpgrade.setVisibility(View.INVISIBLE);
TextView txtMessage = (TextView) findViewById(R.id.txtUpgradeScreen);
txtMessage.setText(R.string.upgradeScreenTextError);
}
catch (Exception e)
{
}
}
public void onPlayButtonClick(View view)
{
Intent myIntent = new Intent(view.getContext(), GameActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivityForResult(myIntent, ACTIVITY_GAME);
}
public void SetMainText()
{
TextView txt = (TextView) findViewById(R.id.txtScoreGlobal);
txt.setText(Integer.toString(m_TriviaAppInstance.getGlobal()) + "%");
SetPlayerScore(1);
if (m_TriviaAppInstance.getUpgradedStatus() == true)
{
HideUpgrade();
}
}
}
अपडेट: मेरे कोड सही कुछ करना ही होगा मेरा परीक्षण खरीद मेरे गूगल व्यापारी खाते में दिख रहे हैं लेकिन कुछ अभी भी काम नहीं कर रहा है क्योंकि सफल खरीद करने के लिए संकेत नहीं जा रहा है।। । उपयोगकर्ता (मुझे) –
onIabPurchaseFinished घटना FYI एक सफल खरीद के बाद सब पर फायरिंग नहीं है लेकिन, उपयोगकर्ता पहले आइटम का मालिक अगर यह आग करता –
:।। मुझे लगता है कि मैं इस राशि पता चला - किसी और के लिए जो इसे पार कर सकता है। गतिविधि है कि मैं Google Play स्टोर लॉन्च करने के लिए उपयोग कर रहा था एक "FLAG_ACTIVITY_NO_HISTORY" के साथ बुलाया गया था। मैंने ऐसा इसलिए किया क्योंकि मैं नहीं चाहता था कि उपयोगकर्ता इस "गेम ओवर" गतिविधि पर वापस जाने के लिए क्लिक कर सके। लेकिन, इस के साथ "अनुप्रयोग में बिलिंग" दु: ख का कारण बनता है। तो, सुनिश्चित करें कि आप "FLAG_ACTIVITY_NO_HISTORY" सेट वाली गतिविधि से "ऐप बिलिंग में" लॉन्च करने का प्रयास नहीं करते हैं। शांति –