Using the Google Cloud Print API with Android

后端 未结 3 1102
無奈伤痛
無奈伤痛 2020-12-24 09:08

I am working on an android application that needs to print to a printer. I decided on using the Google Cloud Print, as it seemed easy to set up. Initially, I followed the st

3条回答
  •  一向
    一向 (楼主)
    2020-12-24 09:27

    It looks like you need to use multipart encoding, example here:

    http://blog.tacticalnuclearstrike.com/2010/01/using-multipartentity-in-android-applications/

    FTA:

    The files needed are apache-mime4j, httpclient, httpcore and httpmime. All are opensource projects built by the Apache foundation.

    Download the 4 files and add them to your project then you should be able to use the following code to post strings and files to pages.

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://www.tumblr.com/api/write");
    
    try {
        MultipartEntity entity = new MultipartEntity();
    
        entity.addPart("type", new StringBody("photo"));
        entity.addPart("data", new FileBody(image));
        httppost.setEntity(entity);
        HttpResponse response = httpclient.execute(httppost);
    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    } 
    

    The image variable in this case is a File that contains an image captured by the camera on the phone.

提交回复
热议问题