--- android/TrainInfo/src/dk/thoerup/traininfo/WelcomeScreen.java 2014/03/03 17:32:14 2122 +++ android/TrainInfo/src/dk/thoerup/traininfo/WelcomeScreen.java 2014/03/05 12:11:16 2123 @@ -9,7 +9,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; -import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; @@ -22,6 +21,8 @@ import android.widget.Button; import android.widget.Toast; +import com.example.android.trivialdrivesample.util.IabHelper; +import com.example.android.trivialdrivesample.util.IabResult; import com.nullwire.trace.ExceptionHandler; import dk.thoerup.androidutils.CheckUpdates; @@ -43,6 +44,8 @@ ListFavorites } + IabHelper mHelper; + Handler handler = new Handler(); SharedPreferences prefs; @@ -124,16 +127,57 @@ } } + + + try { + initBilling(); + } catch (Exception e) { + //Do nothing - just don't crash if billing failed to initialize + } + + + } + + private void initBilling() { + String base64EncodedPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAln3XRJzM8Eo/SSMBLzSOj9pLedftZrWONRLO9KC/BU1Bv0EK3PQhza1S6apS69fa300ZitKSB91WDkf88eW4VJq8txmq8W1J2x/WJCFRQnFaPP0pDgERo9EdEULH2ybsOape/7+ypqNaDWxuqBh4fQfAd+Qpgdz8E7y5ZNbIKqJnRn2gyEfpzytiNQKNATI+XxJfyrS7urg/u/hXYw1R7VBNoAO7KU3b4D205WtXBn2u+Zexjd5disVGmZ5jd0BiuVOyPIWK5e9tA/VnKl/6XDfB9utCtXcAWFVUoVE6+8HWwo9ugFauuwYmbl6pTZydPKjyh9WxVR5MS2TPue/wEwIDAQAB"; + + // compute your public key and store it in base64EncodedPublicKey + mHelper = new IabHelper(this, base64EncodedPublicKey); + mHelper.enableDebugLogging(true); + + mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { + public void onIabSetupFinished(IabResult result) { + + Log.d("TrainInfo", "onIabSetupFinished"); + + if (!result.isSuccess()) { + // Oh noes, there was a problem. + Log.d("TrainInfo", "Problem setting up In-app Billing: " + result); + } + // Hooray, IAB is fully set up! + } + }); + } - + @Override protected void onDestroy() { super.onDestroy(); if (stationLoader != null) { stationLoader.cancel(true); + stationLoader = null; } + if (mHelper != null) { + try { + mHelper.dispose(); + } catch (Exception e) { + //Do Nothing + } + mHelper = null; + } + ProviderFactory.purgeOldEntries(); //exiting application, do some cleanup }