コンピューティング プロジェクト用の Android アプリを作成しています。Web ページの html をダウンロードして文字列として保存するコードのセクションがありますが、html の本文全体はダウンロードされません。
以下は私が使用しているコードです:
package com.example.pete.computingproject;
import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;
import android.preference.PreferenceManager;
import android.content.SharedPreferences;
public class async extends AsyncTask<String, String, String> {
private Context mContext;
public async(Context context) {
mContext = context;
}
@Override
protected String doInBackground(String... strings) {
String content = null;
URLConnection connection = null;
// TODO Auto-generated method stub
try {
connection = new URL("https://stars.cirencester.ac.uk/index_bypass.php?view=tab_content/timetable&wk=6&stu_id=142669").openConnection();
Scanner scanner = new Scanner(connection.getInputStream());
scanner.useDelimiter("\\Z");
content = scanner.next();
} catch (Exception ex) {
ex.printStackTrace();
}
System.out.println(content);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("timetable1", content);
editor.apply();
return (content);
}
}
下記ページのソースをダウンロードしたい(右クリック、ソース表示) https://stars.cirencester.ac.uk/index_bypass.php?view=tab_content/timetable&wk=6&wk_num=&year=2015&stu_id=142669
しかし、私が使用しているコードは、何らかの理由で 40 行目で停止します。アプリケーションが機能するには、すべてのコードが必要です。どんな助けでも大歓迎です!可能であれば、現在のコードを微調整したいだけです。ただし、まったく別のコードを使用せずにそれを行う方法がない場合は、お知らせください。ありがとう!