使用Intent.ACTION_OPEN_DOCUMENT获取完整地址

时间:2016-07-29 19:47:23

标签: android

然后打开此文件并阅读此内容

img1

    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数据库中。

img2

0 个答案:

没有答案