是否有反正在發送基於位置的推送通知android設備與使用第三方推送通知服務,如解析?我想發送推送通知給我的用戶,而不必煩惱收到與特定用戶無關的通知,因爲他們不在特定區域。另外,我可以根據時間間隔獲取用戶位置,但如果可能的話,我寧願以不同的方式進行操作。基於位置的推送通知對於Android
回答
是的,這是完全可能的,只要我正確地解釋你在問什麼。
要完成此操作,您需要將GCM推送通知發送給所有用戶(除非您有辦法,服務器端將其中的一些過濾掉)。然後在您的應用程序中,不是隻創建一個通知並將其傳遞給通知管理器,您應該首先使用LocationManager(或更新的LocationServices API)確定用戶是否位於適當的位置,然後放棄GCM如果不是,則通知。
你需要照顧的幾件事情,爲了做到這一點:
您的AndroidManifest.xml將需要幾個權限更改,無論是對GCM變化,併爲Location訪問:
<!-- Needed for processing notifications --> <permission android:name="com.myappname.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.myappname.permission.C2D_MESSAGE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- Needed for Location --> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
您還需要建立一個通知接收器在清單的
<application>
部分:<receiver android:name="com.myappname.NotificationReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.myappname" /> </intent-filter> <intent-filter> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.myappname" /> </intent-filter> </receiver>
此外,你需要寫你NotificationReceiver Java類,並覆蓋
onReceive
功能:public class NotificationReceiver extends BroadcastReceiver { public void onReceive(final Context context, final Intent intent) { if ("com.google.android.c2dm.intent.REGISTRATION".equals(intent.getAction())) { handleRegistration(context, intent); // you'll have to write this function } else if ("com.google.android.c2dm.intent.RECEIVE".equals(intent.getAction())) { // the handle message function will need to check the user's current location using the location API you choose, and then create the proper Notification if necessary. handleMessage(context, intent); } }
謝謝!你知道一個可以解釋每一步的教程嗎?我是Android新手,我覺得這很有幫助 – user3471066
這些是Google的GCM文檔:http://developer.android.com/google/gcm/gs.html。請注意,您必須擁有某種後端解決方案才能真正告知Google發送通知。 這些是確定用戶位置的文檔: http://developer.android.com/guide/topics/location/strategies.html 給他們一個通讀,嘗試一下,如果你完全卡住了你可以在這裏再問一次。 如果這回答你的問題,別忘了標記我的答案爲可接受的答案,並歡迎來到Stack Overflow。 –
我已經添加了更多的答案。這不是一個簡單的編碼任務,但肯定是可行的。 –
- 1. 基於位置的推送通知FCM
- 2. 適用於Android的位置感知推送通知
- 3. 基於地理位置的推送通知
- 4. 用戶如何跟蹤基於位置的推送通知?
- 5. 基於.NET的推送通知服務
- 6. 基於PHP的網站推送通知
- 7. 基於Sinch FCM的推送通知
- 8. 基於Firebase更新的推送通知
- 9. Android - 每日Firebase雲消息推送通知和基於位置的地址
- 10. 基於帳戶註冊推送通知
- 11. 基於Azure中觸發發送推送通知到Android
- 12. Appcelerator Titanium推送通知適用於Android?
- 13. 關於推送通知
- 14. 基於位置的本地通知
- 15. 設置推送通知android
- 16. 應用程序未運行時基於位置的推送通知?
- 17. 如何在iOS上使用基於地理位置的推送通知?
- 18. 如何發送基於數據庫字段的推送通知
- 19. IOS/Android推送通知 - 基本問題
- 20. Android - 推送通知
- 21. 推送通知 - Android
- 22. 推送通知android
- 23. Android推送通知
- 24. 用於推送通知的Authenicate Webservice
- 25. 用於聊天的APN推送通知
- 26. 用於推送通知的Creating.pem文件?
- 27. 基於距離的ios中特定點的推送通知
- 28. 地理位置推送通知
- 29. HTML地理位置推送通知
- 30. 解析推送通知與位置IOS
看區域範圍設定。它可能會給你一個解決方案。例如根據入口/出口到地理圍欄的位置,讓您的申請註冊/取消註冊通知...? –