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