Skip to main content
July 26, 2011
Question

Print from AIR for Android Application

  • July 26, 2011
  • 1 reply
  • 2126 views

Hello!

I would like print a html document, that is inside the phone memory, from my AIR for Android Application.

My question is, is it possible?

I have read about Google Cloud Print and GCP Intent to print documents form Android. But If you want print using

Google Could Print, you need Internet.

Is possible print without Internet? Can I print using AIR functionality or Google Could Print is always necesary? Are there any workarround to print without GCP Intent?

Thanks!

This topic has been closed for replies.

1 reply

July 29, 2011

Hi!

After I have read a lot about Printbot, Print 2 Page, Google Could Print...
I think the best solution is open the file with application by default. So, the user can decide what application use to print the document.
I tried to use openWithDefaultApplication function of the File class, but this don´t worked over my Samsung Galaxy Tab 7". Although, it work ok over the emulator.

This is my code:

            public var file:File = null
            public function print():void
            {
                file = File.documentsDirectory.resolvePath(appTest\\xml_arts\\html\\art_10383883.htm");
                if (file.exists)
                {
                    try{   
                        file.openWithDefaultApplication();
                    }
                    catch(e:Error)
                    {
                        trace("Hubo un error");
                    }
                }
            }

I try to copy the file to temporary file, and use this to call, but i get the same error.

                try{   
                    var tempFile:File;
                    file.copyTo(tempFile);
                    tempFile.openWithDefaultApplication();
                }
                catch(e:Error)
                {
                    trace("Hubo un error");
                }

I have these permission in the application's manifest:

            <manifest android:installLocation="auto">
                <!--See the Adobe AIR documentation for more information about setting Google Android permissions-->
                <!--Removing the permission android.permission.INTERNET will have the side effect
        of preventing you from debugging your application on your device-->
                <uses-permission android:name="android.permission.INTERNET"/>
                <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
                <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
                <!--<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>-->
                <!--The DISABLE_KEYGUARD and WAKE_LOCK permissions should be toggled together
        in order to access AIR's SystemIdleMode APIs-->
                <!--uses-permission android:name="android.permission.DISABLE_KEYGUARD"/-->
                <uses-permission android:name="android.permission.WAKE_LOCK"/>
                <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
                <!--<uses-permission android:name="android.permission.CAMERA"/>-->
                <!--<uses-permission android:name="android.permission.RECORD_AUDIO"/>-->
                <!--The ACCESS_NETWORK_STATE and ACCESS_WIFI_STATE permissions should be toggled
        together in order to use AIR's NetworkInfo APIs-->
                <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
                <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
            </manifest>

Can anyone tell me where is the problem? Or any workaround?

Thanks!!