1,cordova create foldername packagename Appname
eg: cordova create pushservice com.version.pushservice PushServiceDemo
2,cordova platform add android
3,cordova plugin add cordova-plugin-device
4,cordova plugin add cordova-plugin-file
5,cordova plugin add cordova-plugin-media
6 cordova plugin add https://github.com/phonegap-build/PushPlugin.git
7.create a project on https://console.developers.google.com,and enable api (gcm)
8.generate api key and Autth client ID
9. copy javascrip code from pushplugin in folder example to demo ,and edit it.
pushNotification.register(successHandler, errorHandler, {"senderID":"565080771215","ecb":"onNotification"});
"565080771215" is a front part of client ID
10.if you want to custom notification audio,please add some patch in file platforms\android\src\com\plugin\gcm\GCMIntentService.java
import android.content.res.Resources;
import android.net.Uri;
String soundName = extras.getString("sound");
if (soundName != null) {
Resources r = getResources();
int resourceId = r.getIdentifier(soundName, "raw", context.getPackageName());
Uri soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + resourceId);
//defaults &= ~Notification.DEFAULT_SOUND;
//mBuilder.setDefaults(defaults);
mBuilder.setSound(soundUri);
}
11,send message to gcm
lib:httpclient4.5
public class PushDemo {
public static String REQUEST_URL = "https://android.googleapis.com/gcm/send";
private static String GCM_ID = "APA91bF21aYAZmM6Uc0ckX0YDlTnO5e4_1zkgx1D2TWvX3gE8UwfqZn7qzPDG6abRb2o7YnXwT-WU4KFV-gpRyHULufVNKjxtZ5OJRA-Pzwmv15XVM03pMj0ZPP6dg";
public static void main(String[] args) {
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("registration_id", GCM_ID));
formparams.add(new BasicNameValuePair("data.message", "testing"));
formparams.add(new BasicNameValuePair("data.msgcnt", "1"));
formparams.add(new BasicNameValuePair("data.sound", "beep"));
HttpClient httpclient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(REQUEST_URL);
HttpResponse response;
httpPost.setHeader("Authorization",
"key=AIzaSyC6pHODuXeUMO6_iEgin0e8");
httpPost.setHeader("Content-Type",
"application/x-www-form-urlencoded;charset=UTF-8");
try {
httpPost.setEntity(new UrlEncodedFormEntity(formparams, "utf-8"));
httpclient.execute(httpPost);
//Get the response
response = httpclient.execute(httpPost);
int responseCode = response.getStatusLine().getStatusCode();
String responseText = Integer.toString(responseCode);
System.out.println("HTTP POST : " + responseText);
/*Checking response */
if(response!=null){
InputStream in = response.getEntity().getContent(); //Get the data in the entity
System.out.println("HTTP POST : " + in.toString());
}
//Print result
System.out.println(response.toString());
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
相关推荐
热更新时,我们执行命令 npm install -g cordova-hot-code-push-cli安装插件,但运行cordova-hcp server会报错,如:Could not create tunnel: { Error: ngrok is not yet ready to start tunnels...,这时我们找到...
它利用了 Google 的 Firebase Cloud Messaging (FCM) 对于 Android 设备和 Apple 的 Push Notification Service (APNs) 对于 iOS 设备的服务,使得开发者能够轻松地向 Meteor Cordova 应用的用户发送推送消息。...
启动cordova-hcp server报错 Could not create tunnel: { Error: ngrok is not yet ready to start tunnels 时,将路径 下的cordova-hot-code-push-cli文件下用下载的文件替换就可以了
AeroGear PushPlugin科尔多瓦 ...cordova plugin add https://github.com/aerogear/aerogear-cordova-push.git#:/tests 添加此插件: cordova plugin add http://git-wip-us.apache.org/repos/asf/cordova
启动cordova-hcp server报错 Could not create tunnel: { Error: ngrok...时,将路径 我个人的是:(C:\Users\lenovo\AppData\Roaming\npm\node_modules)下的cordova-hot-code-push-cli文件下用下载的文件替换就可以了
适用于Android,iOS,WP8,Windows8,BlackBerry 10和Amazon Fire OS的Cordova推送通知插件 描述 此插件可与一起使用,并允许您的应用程序在Amazon Fire OS,Android,iOS,Windows Phone和Windows8设备上接收推送...
离子推送通知应用安装克隆仓库git clone https://github.com/jaffyadhav/ionic-push-notification.git 下载依赖项ionic state restore 注意:您的cordova版本必须> = 5.2.0才能正常工作创建登录至ionic.io ionic ...
If you’re familiar with an older version of Cordova, this book will show you in detail how to use all of the new stuff that’s in Cordova 3 plus stuff that has been around for a while (like the ...
用开源时间@ 构建安装$ npm install com.nrswolf.cordova.push-notifications-status用法PushNotificationsStatus . isPushNotificationsEnabled ( function ( response ) { console . log ( 'Success: ' + ...
上以使用CodePush适用于CodePush的Apache Cordova插件该插件为提供了客户端集成,使您可以轻松地向Cordova应用添加动态更新体验。它是如何工作的? Cordova应用程序由HTML,CSS和JavaScript文件以及任何附带的图像...
标题中的“localNotification”指的是Cordova插件LocalNotification,它是一个用于在移动设备上实现本地通知功能的工具。Cordova是一种流行的开源框架,允许开发者使用Web技术(如HTML、CSS和JavaScript)构建原生的...
cordova-screenshot cordova截屏插件 document.addEventListener("deviceready", init, false); function init() { document.querySelector("#share").addEventListener("touchend", function() { navigator....
console.log('Badge count changed to ' + count); }); ``` 5. 平台差异:需要注意的是,不同的操作系统可能对角标的支持和处理方式有所不同。例如,iOS通常在应用图标右上角显示角标,而Android可能在通知抽屉...
cordova.plugins.notification.badge.get(function(count) { console.log("当前徽章数值:" + count); }); ``` - **增加徽章数值:** ```javascript cordova.plugins.notification.badge.increase(); // 增加...
在这个“cordova_to_native”示例中,我们看到的是一个Cordova插件的实现,该插件用于启动一个原生的Android活动,即百度SDK导航应用。百度SDK是一个强大的地图和导航工具,提供API供开发者在自己的应用中集成导航...
4. **设置服务器配置**:在服务器端,你需要集成一个Push Notification服务提供商,如Firebase Cloud Messaging (FCM,前身是Google Cloud Messaging, GCM) 或者第三方服务商如Parse。这些服务通常提供API接口,允许...
phonegap-plugin-localNotifications PhoneGap版本:3.x ... 用Notification notification = new Notification.Builder(context)替换Notification notification = new NotificationCompat.Builder(context) 蜜
cordova-plugin-avos-android-push-notification
通过Google Cloud消息采样示例进行离子,APACHE CORDOVA和推送通知 脚步: 启动您的 编辑/www/js/configuration.js文件 cordova platform add android cordova plugin add ...