IAB fixes, improvements

This commit is contained in:
M66B 2016-02-18 09:16:18 +01:00
parent 6a1a3157b6
commit 5ae59064ab
3 changed files with 17 additions and 11 deletions

View File

@ -262,7 +262,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
try {
iab = new IAB(new IAB.Delegate() {
@Override
public void onReady() {
public void onReady(IAB iab) {
try {
iab.updatePurchases();
@ -278,7 +278,6 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
} finally {
iab.unbind();
iab = null;
}
}
}, this);

View File

@ -19,6 +19,7 @@ package eu.faircode.netguard;
Copyright 2015-2016 by Marcel Bokhorst (M66B)
*/
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
@ -124,7 +125,7 @@ public class ActivityPro extends AppCompatActivity {
try {
iab = new IAB(new IAB.Delegate() {
@Override
public void onReady() {
public void onReady(final IAB iab) {
Log.i(TAG, "IAB ready");
try {
iab.updatePurchases();
@ -141,18 +142,22 @@ public class ActivityPro extends AppCompatActivity {
@Override
public void onClick(View view) {
try {
PendingIntent pi = null;
if (view == btnLog)
startIntentSenderForResult(iab.getBuyIntent(SKU_LOG).getIntentSender(), view.getId(), new Intent(), 0, 0, 0);
pi = iab.getBuyIntent(SKU_LOG);
else if (view == btnFilter)
startIntentSenderForResult(iab.getBuyIntent(SKU_FILTER).getIntentSender(), view.getId(), new Intent(), 0, 0, 0);
pi = iab.getBuyIntent(SKU_FILTER);
else if (view == btnNotify)
startIntentSenderForResult(iab.getBuyIntent(SKU_NOTIFY).getIntentSender(), view.getId(), new Intent(), 0, 0, 0);
pi = iab.getBuyIntent(SKU_NOTIFY);
else if (view == btnSpeed)
startIntentSenderForResult(iab.getBuyIntent(SKU_SPEED).getIntentSender(), view.getId(), new Intent(), 0, 0, 0);
pi = iab.getBuyIntent(SKU_SPEED);
else if (view == btnTheme)
startIntentSenderForResult(iab.getBuyIntent(SKU_THEME).getIntentSender(), view.getId(), new Intent(), 0, 0, 0);
pi = iab.getBuyIntent(SKU_THEME);
else if (view == btnAll)
startIntentSenderForResult(iab.getBuyIntent(SKU_PRO1).getIntentSender(), view.getId(), new Intent(), 0, 0, 0);
pi = iab.getBuyIntent(SKU_PRO1);
if (pi != null)
startIntentSenderForResult(pi.getIntentSender(), view.getId(), new Intent(), 0, 0, 0);
} catch (Throwable ex) {
Log.i(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
Util.sendCrashReport(ex, ActivityPro.this);

View File

@ -48,7 +48,7 @@ public class IAB implements ServiceConnection {
private static final int IAB_VERSION = 3;
public interface Delegate {
void onReady();
void onReady(IAB iab);
}
public IAB(Delegate delegate, Context context) {
@ -75,7 +75,7 @@ public class IAB implements ServiceConnection {
public void onServiceConnected(ComponentName name, IBinder binder) {
Log.i(TAG, "Connected");
service = IInAppBillingService.Stub.asInterface(binder);
delegate.onReady();
delegate.onReady(this);
}
@Override
@ -149,6 +149,8 @@ public class IAB implements ServiceConnection {
}
public PendingIntent getBuyIntent(String sku) throws RemoteException {
if (service == null)
return null;
Bundle bundle = service.getBuyIntent(IAB_VERSION, context.getPackageName(), sku, "inapp", "netguard");
Log.i(TAG, "getBuyIntent");
Util.logBundle(bundle);