Пример #1
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);
  }
Пример #2
0
 @Override
 public void onClick(View v) {
   // TODO Auto-generated method stub
   switch (v.getId()) {
     case R.id.txt_left:
       finish();
       break;
     case R.id.txt_save:
       if (appsAdapter.getSelectedIndex() < 0) {
         Utils.showShortToast(getApplicationContext(), "请选择一个应用");
         return;
       }
       ComplexPreferences.putObject(
           getApplicationContext(),
           Constants.SelectedSharedApp,
           apps.get(appsAdapter.getSelectedIndex()));
       setResult(1);
       finish();
       break;
   }
 }