当前位置: 首页>>代码示例>>Java>>正文


Java ParsePushBroadcastReceiver类代码示例

本文整理汇总了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();
}
 
开发者ID:LibertACAO,项目名称:libertacao-android,代码行数:53,代码来源:LibertacaoPushBroadcastReceiver.java


注:本文中的com.parse.ParsePushBroadcastReceiver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。