Napisałem program w javie i chciałbym go przepisać na androida ale nie działa program pobiera źrodło strony i wyszukuje w nim informacje. Oto kod napisany w javie i kod z androida proszę o pomoc nie działa mi pobieranie źrodła strony zna ktoś jakieś funkcję które to ułatwiają albo pozwalają na jego pobranie proszę o nazwy książek albo link itd
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
public class zrodlo
{
public static String pobierz(String link) throws MalformedURLException, IOException
{
String source = "";
URL akt = new URL(link);
BufferedReader in = new BufferedReader(new InputStreamReader(akt.openStream(),"utf-8"));
String linia;
while ((linia = in.readLine()) != null)
{source += linia+"\n";}
in.close();
return source;
}
public static String szukaj (String s,String s2,String s3)
{
String a="";
int b1=s.indexOf(s2);
a=s.substring(b1, b1+120);
int b2=a.indexOf(s3);
return s.substring(b1, b1+b2);
}
public static void main(String[] args)
{
String s="",s2="",s3="";
try
{
s=pobierz("http://www.pwsz.krosno.pl/harmonogramy-zajec-i/");
}
catch (MalformedURLException ex)
{
ex.printStackTrace();
}
catch (IOException ex)
{
ex.printStackTrace();
}
System.out.println(szukaj(s,"/download/gfx/pwszkrosno/pl/defaultopisy/265/2/1/",((char)34)+""));
System.out.println(szukaj(s,"Harmonogramy mogą ","<"));
}
}
package com.example.zimny.podzial;
import android.content.Context;
import android.provider.ContactsContract;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public static String szukaj (String s,String s2,String s3)
{
String a="";
int b1=s.indexOf(s2);
a=s.substring(b1, b1+120);
int b2=a.indexOf(s3);
return s.substring(b1, b1+b2);
}
public void Pobierz(View view) throws MalformedURLException, IOException
{
TextView tx =(TextView)findViewById(R.id.textView);
Button b = (Button)findViewById(R.id.button);
tx.setText("12");
try {
String source ="";
String link = "http://wwwex.pwsz.krosno.pl/harmonogramy-zajec-i/";
URL akt = new URL(link);
BufferedReader in = new BufferedReader(new InputStreamReader(akt.openStream(), "utf-8"));
String linia;
while ((linia = in.readLine()) != null) {
source += linia + "\n";
}
in.close();
tx.setText(szukaj(source,"/download/gfx/pwszkrosno/pl/defaultopisy/265/2/1/",((char)34)+"").toString());
} catch (Exception e) {
Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_LONG);
}
}
}