我正在使用Intent启动FileManager
private void pickFile() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*").addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, PICK_FILE_RESULT_CODE);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case PICK_FILE_RESULT_CODE: {
Log.d("Mass", "inside onActivityResult PICK_FILE_RESULT_CODE path:" + Util.getRealPathFromUri(mContext, data.getData()));
launchFileUploadActivity(Util.getRealPathFromUri(mContext, data.getData()));
}
break;
}
}
private void launchFileUploadActivity(String path) {
Intent i = new Intent(getActivity(), UploadActivity.class);
i.putExtra("filePath", path);
i.putExtra(Constants.KEY_APP_NO, mTrackData.getId() + "");
i.putExtra("isImage", false);
startActivity(i);
}
如果我没有选择FileManager
中的任何文件并点击回来,那么它会转到ANR而不了解错误的操作。它甚至没有进入onActivityResult
。请有人建议我。我想发布一个意图,就像gmail
启动附件一样。
当我在gmail应用程序中单击附件时,我得到了这个Logcat for ActivityManager
{act=android.intent.action.GET_CONTENT cat=[android.intent.category.OPENABLE] typ=*/* flg=0x3080000 cmp=com.android.documentsui/.DocumentsActivity (has extras)} from uid 10068 on display 0
I/ActivityManager( 2420): Start proc 29052:com.android.documentsui/u0a40 for activity com.android.documentsui/.DocumentsActivity
I/ActivityManager( 2420): Start proc 29074:com.android.externalstorage/u0a10 for content provider com.android.externalstorage/.ExternalStorageProvider
I/ActivityManager( 2420): Displayed com.android.documentsui/.DocumentsActivity: +988ms (total +1s334ms)
有没有办法创建这样的意图来攻击这个logcat
答案 0 :(得分:0)
在致电launchFileUploadActivity
之前,请检查data
和data.getData()
是否不是null
。
if (data != null && data.getData() != null)
launchFileUploadActivity(Util.getRealPathFromUri(mContext, data.getData()));