コード例 #1
0
  @Override
  public void onReceive(Context context, Intent intent) {

    Bundle bundle = intent.getExtras();

    int pID;
    if ((pID = bundle.getInt(MainActivity.PLACEIT_ID, -1)) == -1)
      throw new RuntimeException("Notification not used correctly: pID not found");

    PlaceItNotification.cancel(context, pID);

    PlaceIt placeIt = PlaceItList.find(pID);
    if (bundle.get(BUTTON_TAG).equals(R.string.notification_discard)) {
      placeIt.discard(context);

      Toast.makeText(context, "Place-it discarded.", Toast.LENGTH_LONG).show();
    } else if (bundle.get(BUTTON_TAG).equals(R.string.notification_repost)) {
      placeIt.repost(context);

      Toast.makeText(context, "Place-it reposted.", Toast.LENGTH_LONG).show();
    } else throw new RuntimeException("Notification not used correctly");
  }