How to print Android activity display using cloud print - java

I am trying to implement Google Cloud Print into an app, following the Integration Guide. I'm trying to keep it basic by just printing out google.com. When clicking the print button I created, it brings up the dialog, but I am getting a FileNotFoundException stating
java.io.FileNotFoundException: No content provider:
http://www.google.com
If I then select a printer and click print, the dialog gives me a "Document Missing" message, which makes sense based on the FileNotFoundException.
I took print_dialog.xml and PrintDialogActivity.java verbatim from the guide. Here is my code calling the activity:
Intent printIntent = new Intent(getActivity(), PrintDialogActivity.class);
Uri docUri = Uri.parse("http://www.google.com");
printIntent.setDataAndType(docUri, "text/html");
printIntent.putExtra("title", "Google");
startActivity(printIntent);
I'm attempting to figure out how to print a web page, but would eventually like to be able to print the activity display.
So my question is: What do I need to do in order to print a webpage or activity display?

Try to add the following to your application manifest
<uses-permission android:name="android.permission.INTERNET" />

Related

Google App Script logger.log not showing anything

I writing a simple google web app. this .gs basically open a html file that require user to input his name then click. after the user clicked it, the function checkGCR() should log the username in logger.log. but nothing show in logger.log. if run the function checkGCR(), the log does record "null" since nothing input in the input box. One thing I notice is eventhough the logger.log didn't show anything, but stackdriver log doesn't showing something going on there. Please check my code is that something wrong I did here because I follow online tutorial with exact same coding but logger.log just doesn't seem to work.
//This is code.gs
function checkGCR(myid){
Logger.log(myid);
}
//This is html
document.getElementById("btn").addEventListener("click", doStuff);
function doStuff(){
var myid=document.getElementById("mykidid").value;
google.script.run.checkGCR(myid);
}
I just found out that eventhough it doesn't show up at Logger.log, but it does show up in Stackdriver log. So I just use that instead.

Sending image to Hangouts from local folder

I'm attempting to send an image to Hangouts from within an app I'm building.
I'm working in Xamarin for VS 2015 to do this so the code below is c# but it's not much different from the equivalent Java code so I think it's easy to follow.
What I've done is set up a button on my app which has code setting up an Intent to share an image to Hangouts. I've set the image up already in the Downloads folder on the device and hardcoded the name into the code.
Intent hangoutsShareIntent = new Intent(Intent.ActionSend);
hangoutsShareIntent.SetType("image/jpeg");
hangoutsShareIntent.SetPackage("com.google.android.talk");
string downloadsPath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath;
string filePath = Path.Combine(downloadsPath, "shared.jpg");
hangoutsShareIntent.PutExtra(Intent.ExtraStream, filePath);
StartActivity(Intent.CreateChooser(hangoutsShareIntent, "Share with"));
When I run this, I get the option to select a chat in Hangouts that I want to send the content to. Upon selecting the chat, I get a blank message box and no image.
I've swapped the above code over to use text/plain and pass the filePath variable to the message. When I copy the file path into Chrome to check it, the image loads so I have to figure that the image is where I've said it is... right?
I get no errors (probably because the issue is in Hangouts rather than my app so I have nothing to debug there). Logcat shows nothing except an error I can't find much about on Google: ExternalAccountType﹕ Unsupported attribute readOnly
The only information I could find on that error implied some issue with permissions but I've made sure my app has runtime permissions checked for Read/Write using this code (which wraps the above):
if ((CheckSelfPermission(Permission.ReadExternalStorage) == (int)Permission.Granted) &&
(CheckSelfPermission(Permission.WriteExternalStorage) == (int)Permission.Granted))
NOTE: I'm running this on a HTC One M8 - no SD card but does have external storage on device. I've also added the above permissions to the manifest for earlier Android versions.
The documentation for this (here) isn't overly helpful either so any advice AT ALL here is welcome :)
Thanks!
If you use the file provider instead of sending just the URI on its own. This should get around the permission issues you are seeing.
There is a guide available here which might be useful.
Intent shareIntent = new Intent(Intent.ActionSend);
shareIntent.SetType("image/gif");
Java.IO.File file = new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory + "/myimage.gif");
Android.Net.Uri fileUri = Android.Support.V4.Content.FileProvider.GetUriForFile(this, "com.myfileprovider", file);
shareIntent.SetPackage("com.google.android.talk");
shareIntent.AddFlags(ActivityFlags.GrantReadUriPermission);
shareIntent.PutExtra(Intent.ExtraStream, fileUri);
StartActivity(Intent.CreateChooser(shareIntent, "Share with"));

How to start file browser app from Android application?

I have an App that is started from "share via" menu and get the list of the selected files as an input. Now, what I would like to do is to let the user be able to run file browsing app from my App and then get back the results.
I know for example that I can start phonebook and obtain the choosen contact(s) with following code:
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
So the question is: is there a similar way to run the file browser and to get in return a list of all files selected?
EDIT: the "possible duplicated post" is actually only partially similar, as it ask how to start the file manager inside a specific path, and by the way hasn't an accepted answer. What I really need, if it is possible, is to start the file manager (if there is one) to a specific path and then get in return the selected files.
thank you all very much
Cristiano

How do I change the text shown in GooglePlayServicesUtil.getErrorDialog()?

I am trying to follow the gcm tutorial from Googles docs. They say to call this method if Play Services are out of date:
GooglePlayServicesUtil.getErrorDialog(resultCode, activity, 9000).show();
That's fine, but it puts a dialog that says "This app won't run unless you update Google Play Services" with an "Update" button. I want to change the title and the message text. My users CAN skip the update, and the app will still run. They just won't get push notifications. How do I change the message of the dialog?
I would like to do something like:
Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(resultCode, activity, 9000);
errorDialog.setTitle("out of date");
errorDialog.setMessage("Please update or push notifications won't work. Thank you");
errorDialog.show();
You can override desired string value in your application's strings.xml like this. Simply add these lines in your strings.xml
For message on dialog
<string name="common_google_play_services_update_text" msgid="448354684997260580">This app won\'t run unless you update Google Play services.</string>
For title on dialog
<string name="common_google_play_services_update_title" msgid="6006316683626838685">out of date</string>
EDIT
You could find more information here
http://blog.elsdoerfer.name/2010/04/08/android2po-managing-android-translations/
and What's the meaning of attribute 'msgid' in strings.xml?
msgid is used in android internal strings for localization but I never found any documentation about it. Two reference I have as above. I believe if you remove the msgid still it would work, although I never tried it.
The source of this code is
android_sdk\extras\google\google_play_services\libproject\google-play-services_lib\res\values\common_strings.xml

Button to start the Gallery on Android

I'm trying to make a button in my App open the built in gallery.
public void onClick(View v) {
Intent intentBrowseFiles = new Intent(Intent.ACTION_VIEW);
intentBrowseFiles.setType("image/*");
intentBrowseFiles.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentBrowseFiles);
}
This results in an error message "The application Camera (process com.android.gallery) has stopped unexpectedly."
If I set the Intent action to ACTION_GET_CONTENT it manages to open the gallery but then simply returns the image to my app when a picture is selected which is not what I want.
I'm trying to make a button in my App open the built in browser.
Your question subject says "Gallery". Your first sentence in the question says "browser". These are not the same thing.
If I set the Intent action to ACTION_GET_CONTENT it manages to open the gallery but then simply returns the image to my app when a picture is selected which is not what I want.
Of course, actually telling us "what [you] want" would just be too useful, so you are making us guess.
I am going to go out on a limb and guess that you are trying to open the Gallery application just as a normal application. Note that there is no Gallery application in the Android OS. There may or may not be a Gallery application on any given device, and it may or may not be one from the Android open source project.
However, for devices that have the Android Market on them, they should support an ACTION_VIEW Intent with a MIME type obtained from android.provider.MediaStore.Images.Media.CONTENT_TYPE.

Categories