From cd340aba0c003c35e67b3f00e895c3fa498c9c49 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 15 Aug 2012 06:53:13 -0700 Subject: [PATCH] post notification on receipt of url for new app that'll result it it's being downloaded. --- .../android/XWords4/res/values/strings.xml | 2 ++ .../src/org/eehouse/android/xw4/NetUtils.java | 22 +++++++++++++------ .../src/org/eehouse/android/xw4/Utils.java | 8 ++++++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 735d3fc51..7152b496b 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -1999,5 +1999,7 @@ Check for updates New Wordlist available %s has been updated + New app available + Click to download diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetUtils.java index 18a73bdd0..ca6ed962a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetUtils.java @@ -20,22 +20,22 @@ package org.eehouse.android.xw4; -import javax.net.SocketFactory; -import java.net.InetAddress; -import java.net.Socket; import android.content.Context; - import android.content.Intent; +import android.content.pm.PackageManager; +import android.net.Uri; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; +import java.net.Socket; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; -import android.content.pm.PackageManager; +import javax.net.SocketFactory; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -349,8 +349,16 @@ public class NetUtils { nvp.add( new BasicNameValuePair( "version", String.format( "%d", versionCode ) ) ); - String result = runPost( post, nvp ); - DbgUtils.logf( "checkVersions: received: \"%s\"", result ); + String url = runPost( post, nvp ); + if ( null != url ) { + Intent intent = + new Intent( Intent.ACTION_VIEW, Uri.parse(url) ); + String title = Utils.format( context, R.string.new_app_availf, + packageName ); + String body = context.getString( R.string.new_app_avail ); + Utils.postNotification( context, intent, title, body, + url.hashCode() ); + } } catch ( PackageManager.NameNotFoundException nnfe ) { DbgUtils.logf( "checkVersions: %s", nnfe.toString() ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java index e3e70910d..72db41eec 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java @@ -144,6 +144,13 @@ public class Utils { public static void postNotification( Context context, Intent intent, int titleID, String body, int id ) + { + String title = context.getString( titleID ); + postNotification( context, intent, title, body, id ); + } + + public static void postNotification( Context context, Intent intent, + String title, String body, int id ) { /* s_nextCode: per this link http://stackoverflow.com/questions/10561419/scheduling-more-than-one-pendingintent-to-same-activity-using-alarmmanager @@ -155,7 +162,6 @@ public class Utils { PendingIntent.getActivity( context, ++s_nextCode, intent, PendingIntent.FLAG_ONE_SHOT ); - String title = context.getString( titleID ); Notification notification = new Notification( R.drawable.icon48x48, title, System.currentTimeMillis() );