From 265415f50ed641f797b6dd850582ee07c97cd572 Mon Sep 17 00:00:00 2001 From: zhangqinhghe Date: Wed, 11 Jun 2014 11:08:17 +0800 Subject: [PATCH] android add tag/alias callback --- example/.DS_Store | Bin 6148 -> 6148 bytes src/android/JPushPlugin.java | 43 +++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/example/.DS_Store b/example/.DS_Store index c8de8ac2140de9285873d81bd53507a1ba144060..5f52949f6386aafeacc572813774b0a59d6c3079 100644 GIT binary patch delta 32 ocmZoMXfc@J&&akhU^g=(+h!gX7RJpktcRHb%7 delta 79 zcmZoMXfc@J&&a+pU^g=(`(_>%7DhuZhD?S$h7^WWh6)Bfh75)hhFpdm&z$_^q@4UD g1_lNJ1_s6;Aguw!a{vD`Fl^>!J;t<|o#QV*0Mv03Jpcdz diff --git a/src/android/JPushPlugin.java b/src/android/JPushPlugin.java index 1f0e6b1..84b35e2 100644 --- a/src/android/JPushPlugin.java +++ b/src/android/JPushPlugin.java @@ -9,6 +9,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; + import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaPlugin; @@ -16,9 +17,13 @@ import org.apache.cordova.CordovaWebView; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; + +import com.thi.pushtest.R; + import cn.jpush.android.api.BasicPushNotificationBuilder; import cn.jpush.android.api.CustomPushNotificationBuilder; import cn.jpush.android.api.JPushInterface; +import cn.jpush.android.api.TagAliasCallback; public class JPushPlugin extends CordovaPlugin { private final static List methodList = @@ -194,7 +199,7 @@ public class JPushPlugin extends CordovaPlugin { } Set validTags = JPushInterface.filterValidTags(tags); JPushInterface.setTags(this.cordova.getActivity() - .getApplicationContext(), validTags, null); + .getApplicationContext(), validTags,mTagWithAliasCallback); callbackContext.success(); } catch (JSONException e) { e.printStackTrace(); @@ -206,7 +211,7 @@ public class JPushPlugin extends CordovaPlugin { try { String alias = data.getString(0); JPushInterface.setAlias(this.cordova.getActivity() - .getApplicationContext(), alias, null); + .getApplicationContext(), alias,mTagWithAliasCallback); callbackContext.success(); } catch (JSONException e) { e.printStackTrace(); @@ -302,4 +307,38 @@ public class JPushPlugin extends CordovaPlugin { callbackContext.error("error id"); } } + private final TagAliasCallback mTagWithAliasCallback = new TagAliasCallback() { + + @Override + public void gotResult(int code, String alias, Set tags) { + if (instance == null) { + return; + } + + JSONObject data = new JSONObject(); + try { + data.put("resultCode", code); + data.put("tags", tags); + data.put("alias", alias); + + String jsEvent=String + .format("cordova.fireDocumentEvent('jpush.setTagsWithAlias',%s)", + data.toString()); + instance.webView.sendJavascript(jsEvent); + String js = String + .format("window.plugins.jPushPlugin.pushCallback('%s');", + data.toString()); + instance.webView.sendJavascript(js); + + + } catch (JSONException e) { + + } + + } + + }; + + + }