class HttpToolKit{ static void PostMe(String str, HashMap<String,String> form,HashMap<String,String> files,Callback callback)throws Exception{ if (!str.startsWith("http://")){ str="http://"+str; } String boundary = "xx--------------------------------------------------------------xx"; MultipartBody.Builder builder = new MultipartBody.Builder(boundary).setType(MultipartBody.FORM); if (files!=null&&files.size()>0){ Iterator<Map.Entry<String, String>> it = files.entrySet().iterator(); while (it.hasNext()){ HashMap.Entry<String,String> entry=it.next(); String[] strs=entry.getValue().split("/"); String filename=strs[strs.length-1]; builder.addFormDataPart(entry.getKey(),filename,RequestBody.create(MediaType.parse("application/octet-stream"),new File(entry.getValue()))); } } if (form!=null&&form.size()>0){ Iterator<HashMap.Entry<String,String>> it=form.entrySet().iterator(); while (it.hasNext()){ HashMap.Entry<String,String> entry=it.next(); builder.addFormDataPart(entry.getKey(),entry.getValue()); } } Request request = new Request.Builder().url(str).post(builder.build()).build(); OkHttpClient client=new OkHttpClient(); client.newCall(request).enqueue(callback); } }
public class MainActivity extends Activity { ActionBar actionBar; //声明ActionBar @Override protected void onCreate( Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView( R .layout.activity_main); actionBar = getSupportActionBar(); //得 到ActionBar actionBar.hide(); //隐藏ActionBar } }
评论
发表评论