public class MyService extends Service {
@Override
public IBinder onBind(Intent intent) {
return new MyBinder();
}
public void down(String url){
Log.e("######","执行");
new MyThread(url).start();
}
class MyBinder extends Binder{
public MyService getservice(){
return MyService.this;
}
}
}
下载线程
class MyThread extends Thread{
String url;
public MyThread(String url) {
this.url = url;
}
@Override
public void run() {
try {
URL uu = new URL(url);
HttpURLConnection hu = (HttpURLConnection) uu.openConnection();
hu.connect();
int cod = hu.getResponseCode();
if(cod == 200){
InputStream is = hu.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(is);
EventBus.getDefault().postSticky(bitmap);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}