Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (print)
Viewing all articles
Browse latest Browse all 20

Printing support on Android?

$
0
0

I'm wondering if anyone has actually gotten printing to work on Android with Titanium?

I've gotten as far as creating an intent, starting the activity and thus opening the app for printing (HP ePrint using the org.androidprinting.intent.action.PRINT intent), but HP ePrint crashes upon opening. There error in HP ePrint is: "Oops! Your SDcard is not available or couldn't be found. Please verify if your SD card is in use to continue".

I believe the problem is that HP ePrint somehow can't access the image file I save in my own app. Hope someone can help!

Here's the code I use to launch the print app:

var some_blob = some_view.toImage();
 
    if (!Ti.Filesystem.isExternalStoragePresent()) {
        alert("Could not write to external storage");
        return;
    }
 
    var dir = Ti.Filesystem.externalStorageDirectory;
    var new_file = Ti.Filesystem.getFile(dir, "my_image.png");  
    new_file.write(some_blob.media);
 
    if (!new_file.exists()) {
        alert("Could not write to external storage");
        return;
    }
 
 
    var intent = Ti.Android.createIntent({ 
        action:     "org.androidprinting.intent.action.PRINT",
        type:       "image/*",
        uri:        new_file.nativePath,
    });
    intent.addCategory(Ti.Android.CATEGORY_DEFAULT);
 
    try {
        Ti.Android.currentActivity.startActivityForResult(intent,function(e){
            alert(JSON.stringify(e));
        });         
    }catch(err){
        alert("No printing apps appear to be installed");
    }

Viewing all articles
Browse latest Browse all 20

Trending Articles