本文整理汇总了Java中com.parse.ParsePushBroadcastReceiver类的典型用法代码示例。如果您正苦于以下问题:Java ParsePushBroadcastReceiver类的具体用法?Java ParsePushBroadcastReceiver怎么用?Java ParsePushBroadcastReceiver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParsePushBroadcastReceiver类属于com.parse包,在下文中一共展示了ParsePushBroadcastReceiver类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNotification
import com.parse.ParsePushBroadcastReceiver; //导入依赖的package包/类
protected Notification getNotification(Context context, Intent intent) {
JSONObject pushData = getPushData(intent);
if (pushData == null || (!pushData.has("alert") && !pushData.has("title"))) {
return null;
}
String title = pushData.optString("title", MyApp.getAppContext().getString(R.string.app_name));
String alert = pushData.optString("alert", "Notification received.");
String tickerText = String.format(Locale.getDefault(), "%s: %s", title, alert);
Bundle extras = intent.getExtras();
Random random = new Random();
int contentIntentRequestCode = random.nextInt();
int deleteIntentRequestCode = random.nextInt();
// Security consideration: To protect the app from tampering, we require that intent filters
// not be exported. To protect the app from information leaks, we restrict the packages which
// may intercept the push intents.
String packageName = context.getPackageName();
Intent contentIntent = new Intent(ParsePushBroadcastReceiver.ACTION_PUSH_OPEN);
contentIntent.putExtras(extras);
contentIntent.setPackage(packageName);
Intent deleteIntent = new Intent(ParsePushBroadcastReceiver.ACTION_PUSH_DELETE);
deleteIntent.putExtras(extras);
deleteIntent.setPackage(packageName);
PendingIntent pContentIntent = PendingIntent.getBroadcast(context, contentIntentRequestCode,
contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pDeleteIntent = PendingIntent.getBroadcast(context, deleteIntentRequestCode,
deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// The purpose of setDefaults(Notification.DEFAULT_ALL) is to inherit notification properties
// from system defaults
NotificationCompat.Builder parseBuilder = new NotificationCompat.Builder(context);
parseBuilder.setContentTitle(title)
.setContentText(alert)
.setTicker(tickerText)
.setSmallIcon(this.getSmallIconId(context, intent))
.setLargeIcon(this.getLargeIcon(context, intent))
.setContentIntent(pContentIntent)
.setDeleteIntent(pDeleteIntent)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL);
if (alert != null
&& alert.length() > SMALL_NOTIFICATION_MAX_CHARACTER_LIMIT) {
parseBuilder.setStyle(new NotificationCompat.Builder.BigTextStyle().bigText(alert));
}
return parseBuilder.build();
}