Exemplo n.º 1
0
 private void initData() {
   selectedApps = new ArrayList<App>();
   apps =
       ComplexPreferences.getObject(
           getApplicationContext(), Constants.ExistedApp, new TypeReference<ArrayList<App>>() {});
   appsAdapter = new AppsAdapter(getApplicationContext());
   lvApps.setAdapter(appsAdapter);
 }
Exemplo n.º 2
0
  /**
   * 接收通知到达的函数。
   *
   * @param context 上下文
   * @param title 推送的通知的标题
   * @param description 推送的通知的描述
   * @param customContentString 自定义内容,为空或者json字符串
   */
  @Override
  public void onNotificationArrived(
      Context context, String title, String description, String customContentString) {

    String notifyString =
        "onNotificationArrived  title=\""
            + title
            + "\" description=\""
            + description
            + "\" customContent="
            + customContentString;
    Log.d(TAG, notifyString);
    ArrayList<SystemNotification> tongzhi =
        ComplexPreferences.getObject(
            context,
            Constants.SYSTEMNOTIFICATION,
            new TypeReference<ArrayList<SystemNotification>>() {});
    if (tongzhi == null) {
      tongzhi = new ArrayList<SystemNotification>();
    }
    SystemNotification notification = new SystemNotification();
    notification.setTitle(title);
    notification.setContent(description);
    notification.setTime(System.currentTimeMillis());
    tongzhi.add(notification);
    ComplexPreferences.putObject(context, Constants.SYSTEMNOTIFICATION, tongzhi);
    // 自定义内容获取方式,mykey和myvalue对应通知推送时自定义内容中设置的键和值
    if (!TextUtils.isEmpty(customContentString)) {
      JSONObject customJson = null;
      try {
        customJson = new JSONObject(customContentString);
        String myvalue = null;
        if (!customJson.isNull("mykey")) {
          myvalue = customJson.getString("mykey");
        }
      } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    // Demo更新界面展示代码,应用请在这里加入自己的处理逻辑
    // 你可以參考 onNotificationClicked中的提示从自定义内容获取具体值
    // updateContent(context, notifyString);
  }