如何在Android中读取或下载Google驱动器文本文件

时间:2019-03-23 12:17:20

标签: android google-drive-api

我要从Android上的Google云端硬盘读取文本文件 我的文本文件地址在Google云端硬盘https://drive.google.com/file/d/1zGDm2iEIg632QZyJlM_5FfZXsOy5qsWc/view?usp=sharing上 我的代码在底部,但这不起作用 请指导我 谢谢

 private void gettext ()
{
    new Thread(new Runnable(){
        public void run(){
            ArrayList<String> urls=new ArrayList<String>(); //to read each line
            try {
                mygooglelink="https://drive.google.com/file/d/1zGDm2iEIg632QZyJlM_5FfZXsOy5qsWc/view?usp=sharing";
                URL url = new URL(mygooglelink); //My text file location
                HttpURLConnection conn=(HttpURLConnection) url.openConnection();
                conn.setUseCaches(false);
                conn.setConnectTimeout(1000);
                BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));       
                String str="";
                str = in.readLine(); //Just the first line 
                in.close();
                Log.d("string=",srt);
            } catch (Exception e) {
                Log.d("MyTag",e.toString());
            }
            MainActivity.this.runOnUiThread(new Runnable(){
                public void run(){

                }
            });
        }
    }).start();
}

0 个答案:

没有答案