Thanks JP!

If you're worried about the cache, don't use the browser.
Instead, use DefaultHttpClient/HttpURLConnection to download your HTML
file from your web-site (be sure to set the DefaultHttpClient/
HttpURLConnection not to use any cache). Then show the data from this
downloaded HTML file in a WebView.


On Apr 22, 10:24 pm, JP <[email protected]> wrote:
> On Apr 22, 9:48 am, "[email protected]" <[email protected]> wrote:
>
> > I am looking for any information on the Android Kill switch ?
>
> Well, AFAIK there is no Android Kill switch. Some home cooking is in
> order. Here's my recipe. The beauty here - you can spice it up as much
> as you like.
> As a prerequisite, you need to have a web site to anchor the "kill
> switch". Below a code snippet that you can use and (must) modify (use
> proper domain names). I've pulled this together from a few classes so
> it might not work out of the box. DIY spirit required (;->).
>
> <------------------------------------- snip
> --------------------------------------->
> Context appContext = this.getApplicationContext();
>
> // Read app version
> String versionName = "";
> try {
>         PackageManager pM = appContext.getPackageManager();
>         PackageInfo pI =  pM.getPackageInfo("com.yourdomain.yourapp", 0);
>         versionName = pI.versionName;} catch (Exception e) {
>
>         Log.v("Exception", "Exception version check: " + e.getMessage());
>
> }
>
> // Read network state (requires network state permission in
> AndroidManifest.xml):
> //      <uses-permission
> android:name="android.permission.ACCESS_NETWORK_STATE" />
> NetworkInfo.State networkState = NetworkInfo.State.DISCONNECTED;
> ConnectivityManager systemService = (ConnectivityManager)
> appContext.getSystemService(Context.CONNECTIVITY_SERVICE);
> if (systemService != null && systemService.getActiveNetworkInfo() !=
> null)
>         networkState = systemService.getActiveNetworkInfo().getState();
>
> // If network is available, reach out and see if "kill switch" page is
> posted
> try {
>         if (networkState == NetworkInfo.State.CONNECTED) {
>                 URL url = new URL("http://www.yourwebsite.com/"; + versionName 
> +
> ".html");
>                 URLConnection connection = 
> (URLConnection)url.openConnection();
>                 connection.setDefaultUseCaches(false);
>                 connection.setUseCaches(false);
>                 connection.connect();
>                 InputStream is = connection.getInputStream();
>                 if (is.read() != null) {
>                         // "Kill switch" triggered, open Android browser with
> "kill switch" file
>                         Intent myIntent = new Intent(Intent.ACTION_VIEW,
> Uri.parse("http://www.yourwebsite.com/"; + version + ".html"));
>                         myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
>                         startActivity(myIntent);
>                         this.finish(); // Comment this out and this will 
> "only" be a nag
> screen
>                 }
>         }} catch (Exception e) {
>
>         Log.v("Check", "Check version authorization exception: " +
> e.getMessage());
>
> }
>
> <------------------------------------- snip
> --------------------------------------->
>
> The network state analysis can probably be omitted. I need the network
> state for other app functionality, so I've included it in the
> implementation.
> The "kill switch" can be tied to any condition you can determine
> within your running app. I've used the app's version, so let's run
> with this example.
> Assuming the app version is "1.0": When you post a file 1.0.html 
> onhttp://www.yourwebsite.com/, the "kill switch" will be triggered, and
> your app opens the Android browser with the content of 1.0.html before
> finishing. This happens without user interaction. Posting the "kill
> switch" page is not to be taken lightly. Even after you unpost it, it
> remains in Android's HTTP cache for a while, and the "kill switch"
> condition will be triggered regardless you unposting 1.0.html. I could
> not figure that part out completely, so I assume throwing the "kill
> switch" an irreversible operation.
> If the "kill switch" file has not been posted, the code above will
> throw an exception, and just log a "Check version authorization
> exception". The user will not notice anything. I recommend you execute
> this in a Thread separate from you main UI cycle in order to avoid
> getting hit by any delays reaching out to yourwebsite.com.
> In rare cases I found that the exception is not thrown, even though
> the "kill switch" page has never been posted - I consider this a bug
> in Android. I couldn't narrow this down, except for the impression
> this might have to do with switching networks between 3G/Edge and
> Wifi. When this happens, the browsers opens with a 404. Again, this is
> rare.
>
> Going back to the kill switch page (1.0.html). You have to be very
> articulate and nice in explaining why this page pops up.
> This is important, because on this page, you will steer the user to
> download the properly distributed .apk file. Now you've turned the
> tables on the unauthorized distribution of your app, because you've
> leveraged the pirates' efforts to fill their illegit channel with
> content to actually promote your app. Earlier this week, a developer
> reported a mod of an .apk file that featured a translation of the
> app's resources. I'd say, if that ever happens, extract that content,
> and use it to localize your app. Now you've paid back double. How do
> you like that.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to