コード例 #1
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    switch (id) {
      case R.id.with_action_search:
        File d = new File("/storage/emulated/0/DCIM/Camera/");
        File d1 = new File("/storage/emulated/0/DCIM/");
        for (File file1 : d.listFiles()) {
          Log.i(thisClass, file1.getName());
        }
        for (File file1 : d1.listFiles()) {
          Log.i(thisClass, file1.getName());
        }
        break;
      case R.id.with_action_add:
        // show chooser to show file
        Intent intent = IntentUtil.intentWithChooser(this, Intent.ACTION_GET_CONTENT);
        if (IntentUtil.intentSafe(intent, this)) {
          startActivityForResult(intent, PICK_FILE_REQUEST_CODE);
          Log.i(thisClass, "when will app run to here");
        } else {
          // remind use that no apps to open to add
          Intent remind = new Intent(this, RemindDialog.class);
          remind.putExtra(RemindDialog.REMIND_MSG, "no app to get content");
          startActivity(remind);
        }
        break;
      case R.id.with_action_settings:
        break;
    }

    return super.onOptionsItemSelected(item);
  }