簡體   English   中英

Android推送通知-服務器中未注冊任何設備

[英]Android push notification- No device registred in the server

我想從服務器收到到我的android應用的推送通知。我使用Google Cloud Messaging for Android Library的示例Extras / google / samples /。我已經搜索了3天,但沒有希望:/。

這是我的工作方式:

您將在最后找到源代碼

智能服務器部分:

1-我用塊注釋打開gcm-demo-server \\ WebContent \\ WEB-INF \\ classes \\ api。 我用我的api密鑰更改了它

2在gcm-demo-server目錄的shell窗口中,我運行“ ant war”

3-我將dist \\ gcm-demo.war文件復制到tomcat \\ webapps

4-我在瀏覽器中使用此URL localhost:8080 / gcm-demo打開服務器

II-App部分:

在CommonUtilities.java中,我更改了以下字段:

1-靜態最終字符串SERVER_URL =“ localhost:8080 / gcm-demo / home”;(我的服務器網址)

2-靜態最終字符串SENDER_ID =“ 876836784656”; (我的項目ID)

之后,我打開服務器。 它顯示“未注冊設備”,然后運行應用程序,顯示“服務器上已注冊設備”,但是刷新服務器時顯示“未注冊設備”,但是服務器必須顯示已注冊設備和發送按鈕“推送通知”:cry:PLEAAAZ幫助!!

應用代碼: -源代碼和類在這里

  • 清單:

     <?xml version="1.0" encoding="utf-8"?> 

     <!-- GCM requires Android SDK version 2.2 (API level 8) or above. --> <!-- The targetSdkVersion is optional, but it's always a good practice to target higher versions. --> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16"/> <!-- GCM connects to Google Services. --> <uses-permission android:name="android.permission.INTERNET" /> <!-- GCM requires a Google account. --> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <!-- Keeps the processor from sleeping when a message is received. --> <uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- Creates a custom permission so only this app can receive its messages. NOTE: the permission *must* be called PACKAGE.permission.C2D_MESSAGE, where PACKAGE is the application's package name. --> <permission android:name="com.google.android.gcm.demo.app.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.google.android.gcm.demo.app.permission.C2D_MESSAGE" /> <!-- This app has permission to register and receive data message. --> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- Main activity. --> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".DemoActivity" android:label="@string/app_name" android:screenOrientation="portrait" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- BroadcastReceiver that will receive intents from GCM services and handle them to the custom IntentService. The com.google.android.c2dm.permission.SEND permission is necessary so only GCM services can send data messages for the app. --> <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <!-- Receives the actual messages. --> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <!-- Receives the registration id. --> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.google.android.gcm.demo.app" /> </intent-filter> </receiver> <!-- Application-specific subclass of GCMBaseIntentService that will handle received messages. By default, it must be named .GCMIntentService, unless the application uses a custom BroadcastReceiver that redefines its name. --> <service android:name=".GCMIntentService" /> </application> 

服務器代碼:

-所有課程都在這里

我要感謝大家如何看待這個話題:oops:。

我嘗試該演示時遇到了問題,因為我的tomcat在本地運行,但是仿真器每句話都像一個“虛擬路由器”,所以我無法僅通過Android應用程序使用http://localhost:8080來訪問我的tomcat服務器。 我必須使用運行Tomcat服務器的機器的IP,所以它就像http://[my-machine's ip]:8080/gcm-demo ,其中[my-machine ip]類似於192.168 .1.10

注意:您可以通過在Linux或MacOS上運行ifconfig或在Windows上運行ipconfig來獲取IP。 ip地址是IPv4字段的值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM