Vote count:
0
I want to add an option to remove ads from my app. So I have written some code. I have created one imageview named "remove ads". I do not know what is the procedure for IAP. Can anyone tell me if it has any modification or is it right? and now what is the next step?
public static final String PRO_SKU = "removeads";
private final String BASE_64_PUBLIC_KEY = "KEY";
private Inventory mInventory;
IabHelper mHelper;
public static boolean isPro;
private InterstitialAd interstitial;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);}
/*interstitial = new InterstitialAd(getActivity(),
"AD UNIT");
AdRequest adRequest = new AdRequest();
interstitial.loadAd(adRequest);
mHelper = new IabHelper(getActivity().getApplicationContext(),
BASE_64_PUBLIC_KEY);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener()
{
@Override
public void onIabSetupFinished(IabResult result)
{
if (result.isSuccess())
{
loadInventory();
Log.d("IAP", "IAP Setup Succesful yeah!");
} else
{
Log.d("IAP", "IAP Setup Failed");
}
}
});
;
interstitial.setAdListener(new AdListener()
{
@Override
public void onReceiveAd(Ad arg0)
{
if (!isPro)
interstitial.show();
}
@Override
public void onPresentScreen(Ad arg0) {
// TODO Auto-generated method stub
}
@Override
public void onLeaveApplication(Ad arg0) {
// TODO Auto-generated method stub
}
@Override
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
// TODO Auto-generated method stub
}
@Override
public void onDismissScreen(Ad arg0) {
// TODO Auto-generated method stub
}
});
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_quality, container,
false);
ImageView purchaseAds = (ImageView) rootView.findViewById(R.id.promo);
purchaseAds.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
purchasePro(PRO_SKU);
}
});
private void loadInventory() {
mHelper.queryInventoryAsync(true,
new IabHelper.QueryInventoryFinishedListener() {
@Override
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isSuccess()) {
mInventory = inventory;
Log.d("IAP inventory loader", "inventory loaded");
if (inventory.hasPurchase(PRO_SKU)) {
isPro = true;
Log.d("IAP inventory checker", "purchased");
} else {
Log.d("IAP inventory checker", "not purchased");
isPro = false;
}
} else {
Log.d("IAP inventory loader","inventory not loaded");
}
}
});
}
private void purchasePro(String sku) {
mHelper.launchPurchaseFlow(getActivity(), sku, 1000,
new IabHelper.OnIabPurchaseFinishedListener() {
@Override
public void onIabPurchaseFinished(IabResult result,
Purchase info) {
if (result.isSuccess()) {
isPro = true;
Log.d("IAP purchase person", "purchased!");
} else {
Toast.makeText(
getActivity().getApplicationContext(),
"Error in your purchase",
Toast.LENGTH_SHORT).show();
Log.d("IAP purchase person", "not purchased!");
}
}
}, null);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (!mHelper.handleActivityResult(1000, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
}
}
}
asked 18 secs ago
Aucun commentaire:
Enregistrer un commentaire