Using the Google Cloud Print API with Android

后端 未结 3 1083
無奈伤痛
無奈伤痛 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.

    0 讨论(0)
  • 2020-12-24 09:32

    Answering the question with a bit of an update. As of October 2013, in 4.4 and the support library, there are built in methods to handle printing. See the following documentation for how to do it properly:

    • PrintHelper - The support Library class to help with printing Bitmaps.
    • DevBytes: Android 4.4 Printing API - An Android Developers video detailing the APIs
    • Printing Content - An Android Training guide on how to use these APIs.
    0 讨论(0)
  • 2020-12-24 09:49

    Looking at the Python Sample Code SubmitJob method it seems that only the PDF typs needs to be encoded in Base64.

    0 讨论(0)
提交回复
热议问题