Examples of this article for you to share the use of Android afinal for your reference, the specific contents are as follows
1. Annotation function
1 Inheritance: finalactivity (need to copy Afinal_0.5.1_bin.jar to Lib)
2) @ViewInject ()
public class Afinalactivity extends Finalactivity {
@ViewInject (Id=r.id.bt_afinal_loadimage,click = "Bt_afinal_ Loadimage_click ")
private button bt_afinal_loadimage;
.....
}
2. Load Picture function
Finalbitmap Finalbitmap = Finalbitmap.create (this);
The picture
Finalbitmap.configloadingimage (R.drawable.atguigu_logo) that is displayed by default when the network requests the picture;
Start loading picture
Finalbitmap.display (iv, "yun_qi_img/160347.30270341.jpg");
3. Request text data function
Finalhttp finalhttp = new Finalhttp ();
String url = "Http://api.m.mtime.cn/PageSubArea/TrailerList.api";
Finalhttp.get (URL, new ajaxcallback<object> () {
@Override public
void OnStart () {
Tv_afinal_ Result.settext ("Start loading");
Super.onstart ();
}
@Override public
void onsuccess (Object o) {
//Show Results
Tv_afinal_result.settext (o.tostring ()) after successful loading;
Super.onsuccess (o);
}
@Override public
void OnFailure (Throwable t, int errorno, String strMsg) {
tv_afinal_result.settext ("Load failed");
super.onfailure (t, Errorno, STRMSG);
}
);
4. File Download function
Finalhttp finalhttp = new Finalhttp ();
Request the address of the network resource
String url = "Http://vfx.mtime.cn/Video/2016/10/11/mp4/161011092841270064_480.mp4";
Store video files to local location
String target = getfilesdir () + "/afinalmusic.mp4";
Finalhttp.download (URL, target, new ajaxcallback<file> () {
@Override public
void onsuccess (file file) { C8/>tv_afinal_result.settext ("Successful download File");
super.onsuccess (file);
@Override public
void OnFailure (Throwable t, int errorno, String strMsg) {
tv_afinal_result.settext ("Download file failed" );
Super.onfailure (t, Errorno, STRMSG);
@Override public
void OnStart () {
tv_afinal_result.settext ("Start Download");
Super.onstart ();
}
);
5. File Upload function
Finalhttp finalhttp = new Finalhttp ();
The location where the file is uploaded to the server
String url = "Http://192.168.0.103:8080/FileUpload/FileUploadServlet";
Ajaxparams params = new Ajaxparams ();
Gets the local resource to be uploaded
try {
params.put ("File", New file (Getfilesdir () + "/afinalmusic.mp4"));
FileNotFoundException e) {
e.printstacktrace ();
}
Finalhttp.post (URL, params, new ajaxcallback<object> () {
@Override public
void OnStart () {
tv_ Afinal_result.settext ("Start uploading");
Super.onstart ();
}
@Override public
void onsuccess (Object o) {
tv_afinal_result.settext ("Upload succeeded");
Super.onsuccess (o);
}
@Override public
void OnFailure (Throwable t, int errorno, String strMsg) {
tv_afinal_result.settext ("Upload failed");
super.onfailure (t, Errorno, STRMSG);
}
);
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.