Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用phonegap生成接收推送通知_Android_Phonegap Plugins_Phonegap Build_Phonegap Pushplugin - Fatal编程技术网

Android 使用phonegap生成接收推送通知

Android 使用phonegap生成接收推送通知,android,phonegap-plugins,phonegap-build,phonegap-pushplugin,Android,Phonegap Plugins,Phonegap Build,Phonegap Pushplugin,我尝试了几天现在得到一个基本的应用程序与推送通知运行 我正在使用PhoneGap构建(桌面应用程序)并在Android设备上进行测试。 我试过各种各样的教程,但似乎都不管用。 运行下面的代码根本不会产生任何反应 这是我当前的代码: config.xml我添加了以下几行: <preference name="android-build-tool" value="gradle" /> <plugin name="phonegap-plugin-push" source="npm"&

我尝试了几天现在得到一个基本的应用程序与推送通知运行

我正在使用PhoneGap构建(桌面应用程序)并在Android设备上进行测试。 我试过各种各样的教程,但似乎都不管用。 运行下面的代码根本不会产生任何反应

这是我当前的代码:

config.xml我添加了以下几行:

<preference name="android-build-tool" value="gradle" />
<plugin name="phonegap-plugin-push" source="npm">
    <param name="SENDER_ID" value="540732047871" />
</plugin>

index.html

<body>  
    <div class="app">
        <h1>PhoneGap</h1>
    </div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
        app.initialize();
    </script>
</body>

音差
app.initialize();
index.js

var app = {
// Application Constructor
initialize: function() {
    this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
    var push = PushNotification.init({
        "android": {
            "senderID": "540732047871"
        },
        "ios": {"alert": "true", "badge": "true", "sound": "true"}, 
        "windows": {} 
    });

    push.on('registration', function(data) {
        console.log("registration event");
        document.getElementById("regId").innerHTML = data.registrationId;
        console.log(JSON.stringify(data));
    });

    push.on('notification', function(data) {
        console.log("notification event");
        console.log(JSON.stringify(data));
        var cards = document.getElementById("cards");
        var card = '<div class="row">' +
              '<div class="col s12 m6">' +
              '  <div class="card darken-1">' +
              '    <div class="card-content black-text">' +
              '      <span class="card-title black-text">' + data.title + '</span>' +
              '      <p>' + data.message + '</p>' +
              '    </div>' +
              '  </div>' +
              ' </div>' +
              '</div>';
        cards.innerHTML += card;

        push.finish(function () {
            console.log('finish successfully called');
        });
    });

    push.on('error', function(e) {
        console.log("push error");
    });
}};
var-app={
//应用程序构造函数
初始化:函数(){
这是bindEvents();
},
//绑定事件侦听器
//
//绑定启动时所需的任何事件。常见事件包括:
//“加载”、“deviceready”、“脱机”和“联机”。
bindEvents:function(){
文件.addEventListener('devicerady',this.ondevicerady,false);
},
//deviceready事件处理程序
//
//“this”的作用域是事件。要调用“receivedEvent”
//函数,我们必须显式调用“app.receivedEvent(…);”
ondevicerady:function(){
var push=PushNotification.init({
“安卓”:{
“senderID”:“540732047871”
},
“ios”:{“警报”:“真实”,“徽章”:“真实”,“声音”:“真实”},
“窗口”:{}
});
推送('注册'),功能(数据){
控制台日志(“注册事件”);
document.getElementById(“regId”).innerHTML=data.registrationId;
log(JSON.stringify(data));
});
push.on('notification',函数(数据){
console.log(“通知事件”);
log(JSON.stringify(data));
var cards=document.getElementById(“卡片”);
var卡=“”+
'' +
'  ' +
'    ' +
''+data.title+''+
“”+data.message+”

”+ ' ' + ' ' + ' ' + ''; cards.innerHTML+=卡片; 推送完成(功能(){ log('finish successfully called'); }); }); 推送('error',函数(e){ 日志(“推送错误”); }); }};
我做错什么了吗?我使用的代码基于“phonegap插件推送”的“github”页面。有什么想法是我在创建项目时遗漏的吗?

@Sven

屏蔽消息
我明天会在博客上写这个,所以我不必一次又一次地重复这个答案

无法将Phonegap桌面应用程序与Phonegap生成一起使用

Phonegap桌面应用程序使用Phonegap CLI,因此如果您想使用Phonegap桌面应用程序,则需要使用Phonegap CLI

如果您想使用Phonegap构建,请忘记您所做的,重新开始制作,将Phonegap桌面应用程序移动到Phonegap构建。要清楚的是,差别很小,但足以让你绊倒

此外,您将无法使用Phonegap开发者应用程序,因为这意味着要使用Phonegap桌面应用程序。您不能使用CLI或与开发人员应用程序一起生成

FWIW:文件就是问题所在。我一直想让Phonegap来解决这个问题。这是你的电话号码

让我知道你想做什么


杰西

哦,好吧,我哪儿也没读过。谢谢你。我将尝试让它与PhoneGap构建相匹配。也许这就解决了问题。我将对我的发现进行评论。@Sven,它写在文档中,但不是很好。