Last active
January 6, 2017 05:11
-
-
Save tcw165/c579e53a70a02da5aab486f28bb79021 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IapDelegateActivity extends AppCompatActivity { | |
/** | |
* The IAP task is successful. | |
*/ | |
public static final String ACTION_IAP_OK = "my.intent.action.IAP_OK"; | |
/** | |
* The IAP task is failed. | |
*/ | |
public static final String ACTION_IAP_CANCELED = "my.intent.action.IAP_CANCELED"; | |
public static final String PARAMS_SKU = "PARAMS_SKU"; | |
public static final String PARAMS_SKU_PRICE = "PARAMS_SKU_PRICE"; | |
String mSku; | |
float mSkuPrice; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
final Intent intent = getIntent(); | |
mSku = intent.getStringExtra(PARAMS_SKU); | |
mSkuPrice = intent.getFloatExtra(PARAMS_SKU_PRICE, 0f); | |
} | |
@Override | |
protected void onStart() { | |
super.onStart(); | |
// TODO: Handle the IAP task. | |
} | |
@Override | |
protected void onStop() { | |
super.onStop(); | |
// TODO: Interrupt the IAP task if necessary. | |
} | |
@Override | |
protected void onSaveInstanceState(Bundle outState) { | |
super.onSaveInstanceState(outState); | |
// TODO: Save the SKU and SKU price in case the "Don't Keep Activity" | |
// TODO: is enabled. | |
} | |
@Override | |
protected void onRestoreInstanceState(Bundle savedState) { | |
super.onRestoreInstanceState(savedState); | |
// TODO: Restore the SKU and SKU price. | |
} | |
@Override | |
protected void onActivityResult(int requestCode, | |
int resultCode, | |
Intent data) { | |
if (resultCode == RESULT_OK) { | |
// Notify the subscribers. | |
sendBroadcast( | |
new Intent(ACTION_IAP_OK) | |
.putExtra(PARAMS_SKU, mSku) | |
.putExtra(PARAMS_SKU_PRICE, mSkuPrice)); | |
} else { | |
// Notify the subscribers. | |
sendBroadcast( | |
new Intent(ACTION_IAP_CANCELED) | |
.putExtra(PARAMS_SKU, mSku) | |
.putExtra(PARAMS_SKU_PRICE, mSkuPrice)); | |
} | |
setResult(resultCode); | |
finish(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment