Mobile back-end cloud Platform Bmob Introduction

Source: Internet
Author: User

for independent developers on the mobile side, the most painful thing is to build a background server. There is no foundation to learn from the beginning, there are technical and build maintenance backstage, very troublesome. The advent of the mobile back-end cloud platform is a boon for every independent developer, offering free paper servers, data file services, and social functions. The mainstream of the domestic alliance, Aurora Push, Bmob,avos Cloud, and so on, the following describes the bmob of all ages

how to link to the BMOB Server development documentation has, the development document is not specifically described is the file download function. File download, first of all through data query to obtain

Bmobfile object, and then obtains the download link through the object's Getfileurl () method, and finally downloads through the link. Here is an example of adding data, querying data, uploading files, downloading files, and pushing features:

Package Com.example.bombexample;import Java.io.file;import Java.io.fileinputstream;import Java.io.FileOutputStream ; Import Java.io.ioexception;import Java.io.inputstream;import java.util.arraylist;import Java.util.List;import Org.json.jsonobject;import Com.lidroid.xutils.httputils;import Com.lidroid.xutils.exception.httpexception;import Com.lidroid.xutils.http.responseinfo;import Com.lidroid.xutils.http.callback.requestcallback;import Cn.bmob.push.bmobpush;import Cn.bmob.v3.bmob;import Cn.bmob.v3.bmobinstallation;import Cn.bmob.v3.BmobPushManager ; Import Cn.bmob.v3.bmobquery;import Cn.bmob.v3.datatype.bmobfile;import Cn.bmob.v3.listener.findlistener;import Cn.bmob.v3.listener.getcallback;import Cn.bmob.v3.listener.getlistener;import Cn.bmob.v3.listener.SaveListener; Import Cn.bmob.v3.listener.uploadfilelistener;import Android.os.bundle;import Android.os.environment;import Android.app.activity;import Android.util.log;import Android.view.menu;import Android.view.view;import android.widget.tOast;public class Mainactivity extends Activity {private list<user> users=new arraylist<user> ();p rivate Httputils Httputils=null; Bmobfile bmobfile =null; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.activity_main);  Bmob.initialize (This, "3b728750d1755e56dd680fa76c4a8386");    Initialization operation when using the push service bmobinstallation.getcurrentinstallation (this). Save ();    Start the push service bmobpush.startwork (this, "3b728750d1755e56dd680fa76c4a8386"); Httputils=new httputils ();} Add data to the service period public void Add (view view) {for (int i=0;i<10;i++) {User user=new User (); User.setname ("Gaigai" +i); User.setpassword ("HLB" +i); users.add (user);} For (final User user:users) {User.save (this, new Savelistener () {@Overridepublic void onsuccess () {Toast.maketext ( Mainactivity.this, "Add Data Success" +user.getobjectid (), Toast.length_short). Show (); @Overridepublic void onfailure (int arg0, String arg1) {toast.maketext (Mainactivity.this, "Add Data Failed", Toast.length_short). Show ();}});}} Query server data public void query (view view) {bmobquery<user> query=new bmobquery<user> (); Query.getobject (This, "F69efc2ca8", new Getlistener<user> () {@Overridepublic void onsuccess (User arg0) {Toast.maketext ( Mainactivity.this,arg0.getname () + "" +arg0.getpassword (), Toast.length_short). Show (); @Overridepublic void onfailure (int arg0, String arg1) {}});} Query server all data public void Queryall (view view) {bmobquery<user> query=new bmobquery<user> (); Query.findobjects (This, new findlistener<user> () {@Overridepublic void onsuccess (list<user> arg0) { Toast.maketext (Mainactivity.this, arg0.size () + "", Toast.length_short). Show (); @Overridepublic void OnError (int arg0, String arg1) {//TODO auto-generated Method stub}}); Push function public void Data_push (view view) {Bmobpushmanager Bmobpush = new Bmobpushmanager (this); Bmobpush.pushmessageall (" Haha, haha. ");} File upload public void upload (View v) throws Ioexception{inputstream in=getassets (). Open ("byx.jpg"); File file=new FilE (environment.getexternalstoragedirectory () + "/byx.jpg"), if (!file.exists ()) {file.createnewfile ();} FileOutputStream out=new fileoutputstream (file); int len=0;byte []buffer=new byte[1024];while ((len=in.read (buffer))! =-1) {out.write (buffer, 0, Len);} Out.close (); In.close (); bmobfile = new Bmobfile (file); Bmobfile.upload (this, new Uploadfilelistener () {@Overridepublic void Onsuccess () {//TODO auto-generated method Stubtoast.maketext (Mainactivity.this, Bmobfile.getfileurl ( Mainactivity.this) + "", Toast.length_short). Show (); LOG.I ("Url", Bmobfile.getfileurl (Mainactivity.this));} @Overridepublic void onfailure (int arg0, String arg1) {//TODO auto-generated method Stubtoast.maketext ( Mainactivity.this, "Upload file Failed", Toast.length_short). Show ();}}); File download public void download (View v) {bmobquery<test> query=new bmobquery<test> (); Query.getobject (This, " Nt7raaag ", new Getlistener<test> () {@Overridepublic void onsuccess (Test arg0) {arg0.getthumbnail (). Getfileurl ( Mainactivity.this); LOG.I ("url", ARG0.getthumbnail (). Getfileurl (mainactivity.this));d Ownloadpic (Arg0.getthumbnail (). Getfileurl (MainActivity.this) , Arg0.getthumbnail (). GetFileName ());} @Overridepublic void onfailure (int arg0, String arg1) {//TODO auto-generated Method stub}}); public void Downloadpic (String url,string filename) {httputils.download (URL, environment.getexternalstoragedirectory () + "/" +filename, New Requestcallback<file> () {@Overridepublic void onsuccess (responseinfo<file> Responseinfo) {log.i ("Download", "File Store Path" +responseinfo.result.getpath ());} @Overridepublic void OnFailure (httpexception error, String msg) {//TODO auto-generated Method stub}});}

Project: http://download.csdn.net/detail/aehaojiu/8653135


Mobile back-end cloud Platform Bmob Introduction

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.