mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-04-13 02:43:10 +08:00
add getRegistragionID
This commit is contained in:
parent
265415f50e
commit
121d63b635
@ -12,14 +12,14 @@
|
||||
<script type="text/javascript">
|
||||
var onDeviceReady = function(){
|
||||
console.log("Device ready!")
|
||||
console.log("iOS is "+window.plugins.jPushPlugin.isPlatformIOS());
|
||||
initiateUI();
|
||||
initiateUI();
|
||||
}
|
||||
var onTagsWithAlias = function(event){
|
||||
try{
|
||||
console.log("onTagsWithAlias");
|
||||
var result="result code:"+event.resultCode+" ";
|
||||
result+="tags:"+event.tags;
|
||||
result+="alias"+event.alias;
|
||||
result+="tags:"+event.tags+" ";
|
||||
result+="alias:"+event.alias+" ";
|
||||
$("#tagAliasResult").html(result);
|
||||
}
|
||||
catch(exception){
|
||||
@ -28,6 +28,8 @@
|
||||
}
|
||||
var onGetRegistradionID = function(data) {
|
||||
try{
|
||||
console.log("index.registrationID:"+data)
|
||||
|
||||
$("#registrationid").html(data);
|
||||
}
|
||||
catch(exception){
|
||||
@ -36,7 +38,8 @@
|
||||
}
|
||||
var initiateUI = function(){
|
||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
||||
window.plugins.jPushPlugin.startLogPageView("mianPage");
|
||||
|
||||
//window.plugins.jPushPlugin.startLogPageView("mianPage");
|
||||
$("#setTagWithAliasButton").click(function(ev) {
|
||||
try{
|
||||
var tag1 = $("#tagText1").attr("value");
|
||||
@ -57,8 +60,9 @@
|
||||
if(tag3 != ""){
|
||||
dd.push(tag3);
|
||||
}
|
||||
}
|
||||
window.plugins.jPushPlugin.setTagsWithAlias(dd,"");
|
||||
}
|
||||
//window.plugins.jPushPlugin.setTagsWithAlias(dd,alias);
|
||||
window.plugins.jPushPlugin.setTags(dd);
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
|
@ -28,8 +28,9 @@ import cn.jpush.android.api.TagAliasCallback;
|
||||
public class JPushPlugin extends CordovaPlugin {
|
||||
private final static List<String> methodList =
|
||||
Arrays.asList(
|
||||
"getRegistrationID",
|
||||
"setTags",
|
||||
"setTagAlias",
|
||||
"setTagsWithAlias",
|
||||
"setAlias",
|
||||
"getNotification",
|
||||
"setBasicPushNotificationBuilder",
|
||||
@ -42,6 +43,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
"isPushStopped",
|
||||
"setLatestNotificationNum",
|
||||
"setPushTime");
|
||||
|
||||
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
|
||||
private static JPushPlugin instance;
|
||||
|
||||
@ -102,14 +104,14 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
JSONArray.class, CallbackContext.class);
|
||||
method.invoke(JPushPlugin.this, data, callbackContext);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
void init(JSONArray data,
|
||||
CallbackContext callbackContext){
|
||||
void init(JSONArray data,CallbackContext callbackContext){
|
||||
JPushInterface.init(this.cordova.getActivity().getApplicationContext());
|
||||
callbackContext.success();
|
||||
}
|
||||
@ -189,17 +191,30 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
callbackContext.success();
|
||||
}
|
||||
|
||||
void getRegistrationID(JSONArray data, CallbackContext callbackContext) {
|
||||
String regID= JPushInterface.getRegistrationID(this.cordova.getActivity().getApplicationContext());
|
||||
callbackContext.success(regID);
|
||||
|
||||
}
|
||||
void setTags(JSONArray data, CallbackContext callbackContext) {
|
||||
HashSet<String> tags = new HashSet<String>();
|
||||
|
||||
HashSet<String> tags=null;
|
||||
try {
|
||||
String tagStr = data.getString(0);
|
||||
String[] tagArr = tagStr.split(",");
|
||||
for (String tag : tagArr) {
|
||||
tags.add(tag);
|
||||
String tagStr;
|
||||
if(data==null){
|
||||
//tags=null;
|
||||
}else if(data.length()==0) {
|
||||
tags= new HashSet<String>();
|
||||
}else{
|
||||
tagStr = data.getString(0);
|
||||
String[] tagArr = tagStr.split(",");
|
||||
for (String tag : tagArr) {
|
||||
tags.add(tag);
|
||||
}
|
||||
}
|
||||
Set<String> validTags = JPushInterface.filterValidTags(tags);
|
||||
//Set<String> validTags = JPushInterface.filterValidTags(tags);
|
||||
JPushInterface.setTags(this.cordova.getActivity()
|
||||
.getApplicationContext(), validTags,mTagWithAliasCallback);
|
||||
.getApplicationContext(), tags,mTagWithAliasCallback);
|
||||
callbackContext.success();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@ -219,7 +234,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
void setTagAlias(JSONArray data, CallbackContext callbackContext) {
|
||||
void setTagsWithAlias(JSONArray data, CallbackContext callbackContext) {
|
||||
HashSet<String> tags = new HashSet<String>();
|
||||
String alias;
|
||||
try {
|
||||
@ -230,7 +245,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
|
||||
JPushInterface.setAliasAndTags(this.cordova.getActivity()
|
||||
.getApplicationContext(), alias, tags);
|
||||
.getApplicationContext(), alias, tags,mTagWithAliasCallback);
|
||||
callbackContext.success();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@ -287,11 +302,13 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
callbackContext.success(obj);
|
||||
}
|
||||
|
||||
void clearAllNotification(JSONArray data,
|
||||
CallbackContext callbackContext){
|
||||
JPushInterface.clearAllNotifications(this.cordova.getActivity());
|
||||
callbackContext.success();
|
||||
}
|
||||
|
||||
void clearNotificationById(JSONArray data,
|
||||
CallbackContext callbackContext){
|
||||
int notificationId=-1;
|
||||
@ -307,6 +324,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
callbackContext.error("error id");
|
||||
}
|
||||
}
|
||||
|
||||
private final TagAliasCallback mTagWithAliasCallback = new TagAliasCallback() {
|
||||
|
||||
@Override
|
||||
|
@ -10,14 +10,14 @@ JPushPlugin.prototype.error_callback = function(msg){
|
||||
console.log("Javascript Callback Error: " + msg)
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.call_native = function(name, args, callback){
|
||||
JPushPlugin.prototype.call_native = function(name, args, callback){
|
||||
console.log("start JPushPlugin.prototype.call_native");
|
||||
ret = cordova.exec(callback,this.error_callback,'JPushPlugin',name,args);
|
||||
console.log("end JPushPlugin.prototype.call_native");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.getRegistrationID = function(callback){
|
||||
this.call_native("getRegistrationID",null,callback);
|
||||
}
|
||||
JPushPlugin.prototype.startLogPageView = function(data){
|
||||
this.call_native( "startLogPageView",[data],null);
|
||||
}
|
||||
@ -27,23 +27,39 @@ JPushPlugin.prototype.stopLogPageView = function(data){
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setTagsWithAlias = function(tags,alias){
|
||||
if(tags==null){
|
||||
this.setAlias(alias);
|
||||
return;
|
||||
}
|
||||
if(alias==null){
|
||||
this.setTags(tags);
|
||||
return;
|
||||
try{
|
||||
if(tags==null){
|
||||
this.setAlias(alias);
|
||||
return;
|
||||
}
|
||||
if(alias==null){
|
||||
this.setTags(tags);
|
||||
return;
|
||||
}
|
||||
var arrayTagWithAlias=[tags];
|
||||
arrayTagWithAlias.unshift(alias);
|
||||
this.call_native( "setTagsWithAlias", arrayTagWithAlias,null);
|
||||
}
|
||||
var arrayTagWithAlias=[tags];
|
||||
arrayTagWithAlias.unshift(alias);
|
||||
this.call_native( "setTagsWithAlias", arrayTagWithAlias,null);
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.getRegistrationID = function(callback){
|
||||
|
||||
try{
|
||||
var data=[];
|
||||
this.call_native("getRegistrationID",[data],callback);
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.setTags = function(data){
|
||||
|
||||
try{
|
||||
this.call_native("setTags",[data],null);
|
||||
this.call_native("setTags",data,null);
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
@ -52,7 +68,7 @@ JPushPlugin.prototype.setTags = function(data){
|
||||
|
||||
JPushPlugin.prototype.setAlias = function(data){
|
||||
try{
|
||||
this.call_native("setAlias", [data],null);
|
||||
this.call_native("setAlias",[data],null);
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
@ -61,6 +77,7 @@ JPushPlugin.prototype.setAlias = function(data){
|
||||
|
||||
JPushPlugin.prototype.pushCallback = function(data){
|
||||
try{
|
||||
console.log(data);
|
||||
var bToObj=JSON.parse(data);
|
||||
var code = bToObj.resultCode;
|
||||
var tags = bToObj.resultTags;
|
||||
|
Loading…
x
Reference in New Issue
Block a user