Android:从设备浏览并上传应用程序中的PDF或Word文件

时间:2014-11-28 05:25:38

标签: android pdf ms-word

我正在创建一个Android移动应用程序,用户可以上传他/她的简历,然后可以将其发送到服务器。

简历可以是pdf格式或单词形式。

如何浏览pdf和word文件,应该给出哪些类型来浏览这些文件?喜欢图像,我们有图像。

感谢。

1 个答案:

答案 0 :(得分:2)

使用此功能:

 private void getDocument()
        {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("application/msword,application/pdf");
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            // Only the system receives the ACTION_OPEN_DOCUMENT, so no need to test.
            startActivityForResult(intent, REQUEST_CODE_DOC);
        }



    @Override
    protected void onActivityResult(int req, int result, Intent data)
    {
        // TODO Auto-generated method stub
        super.onActivityResult(req, result, data);
if (result == RESULT_OK)
        {
        Uri fileuri = data.getData();
                    docFilePath = getFileNameByUri(this, fileuri);
}
}

// get file path

    private String getFileNameByUri(Context context, Uri uri)
    {
        String filepath = "";//default fileName
        //Uri filePathUri = uri;
        File file;
        if (uri.getScheme().toString().compareTo("content") == 0)
        {
            Cursor cursor = context.getContentResolver().query(uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA, MediaStore.Images.Media.ORIENTATION }, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

            cursor.moveToFirst();

            String mImagePath = cursor.getString(column_index);
            cursor.close();
            filepath = mImagePath;

        }
        else
            if (uri.getScheme().compareTo("file") == 0)
            {
                try
                {
                    file = new File(new URI(uri.toString()));
                    if (file.exists())
                        filepath = file.getAbsolutePath();

                }
                catch (URISyntaxException e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            else
            {
                filepath = uri.getPath();
            }
        return filepath;
    }

我希望这会对你有所帮助。