Android 尝试在onActivityResult()中的意图上获取Intextra(),在使用选择器时始终为null?
我想知道使用选择器是否意味着您无法向接收服务器发送额外的自定义数据 我称之为这样的文件选择意图Android 尝试在onActivityResult()中的意图上获取Intextra(),在使用选择器时始终为null?,android,csv,android-intent,onactivityresult,Android,Csv,Android Intent,Onactivityresult,我想知道使用选择器是否意味着您无法向接收服务器发送额外的自定义数据 我称之为这样的文件选择意图 public static void receiveFiles(final AppCompatActivity activity, int which) { Intent receiveIntent = new Intent(Intent.ACTION_GET_CONTENT); receiveIntent.setType("text/comma-separated-values");
public static void receiveFiles(final AppCompatActivity activity, int which) {
Intent receiveIntent = new Intent(Intent.ACTION_GET_CONTENT);
receiveIntent.setType("text/comma-separated-values");
String[] mimetypes = {"text/csv", "text/comma-separated-values", "application/csv"};
receiveIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
receiveIntent.addCategory(Intent.CATEGORY_OPENABLE);
receiveIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false);
receiveIntent.putExtra(IMPORT_OPTION_WHICH, which); //this line
activity.startActivityForResult(Intent.createChooser(receiveIntent, "Pick CSV"), REQUEST_IMPORT_CSV);
}
但在用户选择文件后的onActivityResult中:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case REQUEST_IMPORT_CSV:
if (data != null) {
Uri uri = data.getData(); //is correct
int which = data.getIntExtra(IMPORT_OPTION_WHICH, -1);
//but this always -1!
}
break;
}
}
}
我怎样才能让它正确地提取我传递给intent的值