1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
package com.example.android.samplesync.authenticator;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
import android.app.Activity;
public class Connect extends Activity{
static final String kuser = "test"; // your account name
static final String kpass = "temp"; // your password for the account
private String m_path;
static class MyAuthenticator extends Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
PasswordAuthentication pa = new PasswordAuthentication(kuser, kpass.toCharArray());
return pa;
}
}
public Connect(String path) {
m_path = path;
}
public BufferedReader WebsiteString() throws Exception {
Authenticator.setDefault(new MyAuthenticator());
URL url = new URL(m_path);
InputStream ins = url.openConnection().getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
return reader;
}
} |
Partager