我想知道如何使用parse.com服务在Android手机上推送通知。 哪些字段可用,并且是否可以对推送通知的颜色,图像和格式[粗体,斜体,...]进行样式设置? 谢谢如何使用parse.com通过JSON推送通知[Android]
0
A
回答
0
0
你可以开发你自己的风格 第一: 添加自定义推送接收器清单中像自爆:
<receiver android:name=".CustomPushReceiver" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.USER_PRESENT"/>
<action android:name="com.parse.push.intent.RECEIVE"/>
<action android:name="com.parse.push.intent.DELETE"/>
<action android:name="com.parse.push.intent.OPEN"/>
</intent-filter>
CustomPushReceiver:
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
import com.parse.ParsePushBroadcastReceiver;
import mainViews.MainPage;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Created by SadSad on 01/06/15.
*/
public class CustomPushReceiver extends ParsePushBroadcastReceiver {
private final String TAG = CustomPushReceiver.class.getSimpleName();
private NotificationUtils notificationUtils;
private Intent parseIntent;
public CustomPushReceiver() {
super();
}
@Override
protected void onPushReceive(Context context, Intent intent) {
super.onPushReceive(context, intent);
System.out.println(intent.getExtras().getString("com.parse.Data"));
if (intent == null)
return;
try {
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
System.out.println(json);
Log.e(TAG, "Push received: " + json);
parseIntent = intent;
parsePushJson(context, json);
} catch (JSONException e) {
Log.e(TAG, "Push message json exception: " + e.getMessage());
}
}
@Override
protected void onPushDismiss(Context context, Intent intent) {
super.onPushDismiss(context, intent);
}
@Override
protected void onPushOpen(Context context, Intent intent) {
super.onPushOpen(context, intent);
}
/**
* Parses the push notification json
*
* @param context
* @param json
*/
private void parsePushJson(Context context, JSONObject json) {
try {
System.out.println(json);
boolean isBackground = json.getBoolean("is_background");
JSONObject data = json.getJSONObject("data");
String title = data.getString("title");
String message = data.getString("message");
if (!isBackground) {
Intent resultIntent = new Intent(context, MainPage.class);
showNotificationMessage(context, title, message, resultIntent);
}
} catch (JSONException e) {
Log.e(TAG, "Push message json exception: " + e.getMessage());
}
}
/**
* Shows the notification message in the notification bar
* If the app is in background, launches the app
*
* @param context
* @param title
* @param message
* @param intent
*/
private void showNotificationMessage(Context context, String title, String message, Intent intent) {
// you can use custom notification
notificationUtils = new NotificationUtils(context);
intent.putExtras(parseIntent.getExtras());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
notificationUtils.showNotificationMessage(title, message, intent);
}
}
相关问题
- 1. 如何使用Delphi通过Parse.Com发送推送通知?
- 2. Parse.com回复推送通知
- 3. Parse.com Android的推送通知包含URL
- 4. Android parse.com无法接收推送通知
- 5. Parse.com用数据发送推送通知
- 6. 如何使用Parse.com发送推送通知Cloudcode
- 7. Parse.com android无法接收JSON推送通知
- 8. Parse.com推送通知不起作用
- 9. Android,使用parse.com推送通知,自动启动应用程序
- 10. parse.com使用build.phonegap的REST API Javascript推送通知Android和iOS
- 11. 如何使用Parse.com的推送通知功能来更改PFObjects?
- 12. Android:通过C2DM推送通知
- 13. 地理推送通知与Parse.com
- 14. parse.com action-loc-key推送通知
- 15. 如何通过门户向Android发送Azure推送通知?
- 16. 如何在C#.Net上通过GCM发送Android推送通知
- 17. Android推送通知
- 18. 推送通知 - Android
- 19. 通过WiFi推送通知
- 20. Android如何禁用推送通知?
- 21. 未使用JSON的GCM推送通知
- 22. Xcode - 推送通知Json
- 23. 推送通知:如何使用Pubnub向特定设备发送推送通知?
- 24. 通过UISwitch启用推送通知
- 25. 如何通过iphone应用发送单个推送通知?
- 26. 使用gcm的android推送通知
- 27. 使用FCM向Android推送通知(c#)
- 28. Android Firebase推送通知使用php
- 29. Android:我应该怎样使用android推送通知? Google Cloud Messaging或Parse.com
- 30. Parse.com推送通知不显示在android上的背景
只需了解如何在android中为通知设置风格,因为无论是从parse.com推送到您的设备,都会按照您的android应用程序的代码(用于通知)以风格显示给用户,但不会解析.com推送通知代码。请参阅[本教程](http://www.tutorialspoint.com/android/android_notifications.htm)了解如何处理android通知。 – 2014-09-12 22:35:43