然后打开此文件并阅读此内容
botonExplorar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
// Filter to only show results that can be "opened", such as a
// file (as opposed to a list of contacts or timezones)
intent.setType("text/plain");
intent.addCategory(Intent.CATEGORY_OPENABLE);
// it would be "*/*".
//startActivityForResult(intent, READ_REQUEST_CODE);
startActivityForResult(intent, EDIT_REQUEST_CODE);
} catch (ParseException e) {
e.printStackTrace();
}
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
textInfo1.setText("");
textInfo2.setText("");
Uri mediaUri = data.getData();
String mediaPath = mediaUri.getPath();
textInfo2.setText(mediaPath);
String selectedImagePath;
//MEDIA GALLERY
selectedImagePath = PathUtils.getPath(getApplicationContext(), mediaUri) ;
Log.i("Image File Path", ""+selectedImagePath);
textInfo2.setText(selectedImagePath);
textInfo1.setText(mediaUri.toString());
//Toast.makeText(getBaseContext(), data.getData(),Toast.LENGTH_SHORT).show();
Toast.makeText(this, "image saved to:\n" + data.getData(), Toast.LENGTH_LONG).show();
}
}
我真正想要的是打开带有标签的txt文件,然后将它们添加到SQLite数据库中。