Android Simple hit Jar pack

Source: Internet
Author: User

First suggest a moduel, first write a download image code:

public class LoadTest extends asynctask<void,void,byte[]>{

public static LoadTest LoadTest;

Private byte[] data;

Private String URL;
Public Setdatal listence;


public void Setdatalistence (Setdatal l) {
This.listence = l;
}
Public byte[] Getload () {

return data;
}

public void SetUrl (String s) {
This.url = s;
}
@Override
Protected byte[] Doinbackground (Void ... params) {
try {
Bytearrayoutputstream outputstream = new Bytearrayoutputstream ();
URL urlimage = new URL (URL);
HttpURLConnection urlconn = (httpurlconnection) urlimage.openconnection ();
Urlconn.setconnecttimeout (5000);
Urlconn.setrequestmethod ("GET");
int sumlenght = Urlconn.getcontentlength ();
InputStream Errorstream = Urlconn.geterrorstream ();
int code = Urlconn.getresponsecode ();
if (HTTPURLCONNECTION.HTTP_OK = = code) {
InputStream is = Urlconn.getinputstream ();
byte[] buff = new byte[512];
int Len;
while (len = is.read (buff))! =-1) {
Outputstream.write (Buff,0,len);

}
Is.close ();
Outputstream.flush ();
data = Outputstream.tobytearray ();

}

} catch (Malformedurlexception e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
}
return data;
}

@Override
protected void OnPostExecute (byte[] datainfo) {
if (null! = Datainfo) {

Listence.getdata (Datainfo);
}else {

Super.onpostexecute (Datainfo);
}
}

public interface setdatal{
void GetData (byte[] data);
}

}

Open Moduel's Gradle:
Write code:

Task Makejar (type:copy) {
Delete ' Build/libs/myjar.jar '
From (' build/intermediates/bundles/release/')
Into (' build/libs/')
Include (' Classes.jar ')
Rename (' Classes.jar ', ' Myjar.jar ')
}
executing the build jar package at the terminal
./gradlew Build
Build.finalizedby Makejar
or
Makejar.dependson (build)
./gradlew Makejar

Open Terminal Terminal Input command: Gradview Makejar

The generated jar is in the \build\intermediates\bundles\release directory. You can see a Java flag

This is OK, the import of other projects can be used a few

Demo:https://github.com/tiaodong/okhttptest

Test Demo:https://github.com/tiaodong/jartest

Android simple hit Jar pack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.