閱讀Docs在Parse.com
我找不到默認通知推送消息的方法。我想獲得消息(一個JSON
),做一些工作,然後(如有必要)準備一個自定義通知。 這可能嗎?我不明白爲什麼它不應該,但文件並不清楚。解析推送通知沒有通知
回答
你在兩個賬戶上都是對的 - 文檔可以使用更多的細節,這是可能的。
首先,爲了提供您自己的邏輯實現,您需要創建自己的廣播接收器類擴展ParsePushBroadcastReceiver
。當你這樣做時,你必須更新你的Manifest文件並將<receiver>
指向你的班級,而不是ParsePushBroadcastReceiver
。
在新創建的類中,getNotification()
方法負責創建通知。如果您不希望顯示通知,或者創建自己的Notification
並將其返回或調用super
實現爲默認Notification
,則覆蓋它以返回null
。
在接收推送時,您有許多其他「掛鉤」(可覆蓋的方法)來執行您的邏輯,每個接收Context
和Intent
作爲參數。在每一種方法你可以得到你JSON
數據,只需撥打:
JSONObject notificationData = new JSONObject(intent.getStringExtra(KEY_PUSH_DATA));
你可以做到這一點通過創建自己的廣播接收器來過濾解析的行動。爲此,您需要用您自己的接收器替換ParsePushBroadcastReceiver(在這種情況下爲NotiReceiver)。例如..
在AndroidManifest.xml
<receiver
android:name=".NotiReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
</intent-filter>
在你NotiReceiver,
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals("com.parse.push.intent.RECEIVE")) {
Log.i("Data : ", intent.getExtras().getString("com.parse.Data"));
}
}
希望這將是對你有用。
如果你按照通知的生命週期,你會發現它仍然有可能實現你想要的,而不必做很多你自己的實現。控制推送通知(特別是顯示或不顯示它們)的最簡單和最基本的方法是覆蓋ParsePushBroadcastReceiver
的onReceive
方法。如果您撥打super.onReceive()
,則通知將繼續通知的生命週期並顯示 - 如果您不撥打super.onReceive()
,則生命週期結束,並且通知不會顯示(因此根本不會顯示getNotification()
)。目前接受的答案是您不必要地將生命週期延續到getNotification()
並返回null
,但如果super.onReceive()
未被調用,則getNotification()
也不會。下面是一個更簡潔的方法,以更少的代碼獲得你想要的東西。
public class MyParsePushBroadcastReceiver extends ParsePushBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (shouldShowNotification){
super.onReceive(context, intent);
}
//proccess the notification without being displayed
}
@Override
protected Notification getNotification(Context context, Intent intent) {
//this is only called if super.onReceive() is called
Notification n = super.getNotification(context, intent);
n.sound = Uri.parse("android.resource://" + context.getPackageName() + "/some_sound.mp3");
return n;
}
}
即使你想不顯示通知它也被用在當前接受的答案,你就必須建立自己的通知,這也是不必要的,因爲可以自由定製解析SDK提供的通知建議對於你,以及在getNotification()
方法中返回它之前。但既然你不想顯示任何東西,你不必擔心這一點。這包含在上面的示例代碼中。
但如果應用程序在前臺,然後顯示通知內的應用程序與cutom textview ...而如果用戶不使用我們的應用程序,然後顯示通知欄上的通知如何實現這一目標? – Erum 2015-06-05 08:14:47
- 1. 解析推送通知
- 2. 解析.NET推送通知
- 3. 解析推送通知iOS
- 4. 解析推送通知
- 5. 解析API:批量推送通知
- 6. 解析正在推送通知? 8/15
- 7. 在解析推送通知框架
- 8. 解析爲Firebase增強推送通知
- 9. 推送通知服務如解析?
- 10. 使用REST API解析推送通知
- 11. 使用解析IOS推送通知
- 12. 推送通知iOS與解析
- 13. 使用解析實現推送通知
- 14. 包括推送通知(解析php sdk)
- 15. ios8的解析推送通知中沒有聲音
- 16. 我的應用程序沒有收到解析推送通知
- 17. Cloudkit沒有發送推送通知
- 18. 推送通知
- 19. 推送通知
- 20. 推送通知
- 21. 推送通知
- 22. 推送通知
- 23. Android GCM推送通知沒有給出任何通知
- 24. 蘋果推送通知服務 - 設備上沒有通知
- 25. 有沒有辦法,從通知中心獲取挖掘推送通知? (從服務器推送通知)
- 26. 推送推送通知
- 27. Android推送通知沒有收到
- 28. 沒有APNS的推送通知
- 29. 沒有收到推送通知
- 30. 沒有收到推送通知 - IOS
但如果應用程序在前臺,然後用cutom textview顯示應用程序內的應用程序...而如果用戶不使用我們的應用程序,然後顯示通知欄上的通知如何實現這一目標? – Erum 2015-06-05 08:15:07
如果您不想顯示通知,則可以覆蓋'getNotification'方法返回null。 – 2015-06-05 12:28:11