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...,这时我们找到...
启动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
适用于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: ' + ...
Apache Cordova in Action teaches you how to design, create, and launch hybrid mobile apps people will want to use. With the help of straightforward, real-world examples, you’ll learn to build apps ...
cordova-screenshot cordova截屏插件 document.addEventListener("deviceready", init, false); function init() { document.querySelector("#share").addEventListener("touchend", function() { navigator....
本地通知一个简单的cordova localnotification插件cordova.plugins.localNotify.notify(标题,内容);
上以使用CodePush适用于CodePush的Apache Cordova插件该插件为提供了客户端集成,使您可以轻松地向Cordova应用添加动态更新体验。它是如何工作的? Cordova应用程序由HTML,CSS和JavaScript文件以及任何附带的图像...
phonegap-plugin-localNotifications PhoneGap版本:3.x ... 用Notification notification = new Notification.Builder(context)替换Notification notification = new NotificationCompat.Builder(context) 蜜
cordova-plugin-avos-android-push-notification
流星科尔多瓦推Meteor Cordova 推送包它检测 iOS、Android 的设备令牌
通过Google Cloud消息采样示例进行离子,APACHE CORDOVA和推送通知 脚步: 启动您的 编辑/www/js/configuration.js文件 cordova platform add android cordova plugin add ...
启动cordova-hcp server报错 Could not create tunnel: { Error: ngrok...时,将路径 我个人的是:(C:\Users\lenovo\AppData\Roaming\npm\node_modules)下的cordova-hot-code-push-cli文件下用下载的文件替换就可以了
You'll learn to add in a local push notification in order to test the app. You'll work with Cordova to support native functionalities on both iOS and Android. From there, you'll get to grips with ...
cordova跳转原生Activity
这里展示的是PhoneGap inn Android的Push Notification示例,这里我们也附上了PHP中的服务器代码 脚步 转到 Goggle 开发者控制台并创建一个 App 1.1。 开启 Goggle Cloud 消息 1.2。 单击“凭据”,转到“公钥”,...
适用于Android用户的Pushe Cordova插件1.4.0版 这是适用于Cordova和其他基于Cordova的用户(例如Ionic和PhoneGap)的Pushe android库的插件,使他们能够将Pushe集成到其应用程序中。 如何使用此插件: 首先,在您的...