androidprintinggoogle-cloud-print

How to know that Printer is not registered while using Google Cloud Print?


I am using Google Cloud Print in my android application. For that I have registered my printer on google cloud and while on printing command it gives me list of registered printers on google cloud for printing.

But, How can I give message like : "Please, Register your Printer on Google cloud",,, If user not registered his/her printer on cloud ?

That means, How can I know that, there is no printer registered on Google Cloud Programmatically ?

PrintHelper printHelper = new PrintHelper(QRCodeListActivity.this);
printHelper.setScaleMode(printHelper.SCALE_MODE_FIT);
printHelper.printBitmap("Print Bitmap", result);

Solution

  • Yes , You can do it, Just make a call to Search REST API of Google cloud print. search API = https://www.google.com/cloudprint/search.

    It will return an object that contains the list of printers with details.Then you can parse that object , then you would know if any printer is registered or not. I have done using this way in AngularJS..

                            var data = {'connection_status': 'ALL', ticket: ''};
                                var req = {
                                    method: 'POST',
                                    url: 'https://www.google.com/cloudprint/search',
                                    headers: {
                                        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
                                        'Authorization': 'Bearer ' + token
                                    },
                                    params: data,
                                }
    
                                $http(req).then(function (data) {                                
                                    success(data);                               
                                }, function (data) {                                
                                    error(data);
                                });
    

    And don't forget that , you must have a valid token..