Opening pdf from activity - java

I am developing an app which has one activity that contains a lot of text (really a lot). I thought it would be the best solution to make a PDF with the information in it and open that file right from the app. So when people open the activity, the PDF is opened in a PDF capable viewer installed.
Do you guys know how I have to work this out, because I think I will need to use an Intent, but which one? And how to direct open the viewer?
Thanks for all the help or any energy you put in this question in advance.

Do you guys know how I have to work this out, because I think I will need to use an Intent, but which one?
Use this:
Intent i=new Intent(Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(pathToYourPdfFile), "application/pdf");
startActivity(i);

Related

How to send a SharedPreference from an App to another?

Hey I have an app(Let's call it app A) on the playstore and I want to replace it with another completely different app(Let's call it app B) but I need some of the SharedPreference in app A to be sent to app B but I don't know how to send data from an app to another does anyone know how or if it's even possible. I tried creating a file containing the data on the sdcard but I don't like that idea since it is not secure, so if you anyone has a better idea please help me.
I think best variant for you would be sending an intent with all preferences you want to store from the first app. In second app you need to register intent receiver that will get all data from intent and store it in preferences. Here is an article that described this approach more detailed.

Open Another App with android.intent.action.VIEW

I want to open another app and open a specific page in it!
in their guide they said to use the bellow for default action
android.intent.action.VIEW
and use a kind of intent, which didn't get which, like bellow to go to that specific page:
somecompany://details?id=com.example.calendar
but i don't know how!
And i tryed a ton of solutions but coudn't do it !
Thanks for your help.
I think this is what you're asking for. This will open a specific app's page in the Google Play store.
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(
"market://details?id=com.mycompany.mypackage")));
Don't replace the word market. That is specifically reserved by Android to open the Google Play store.
You can launch an app using intents. But to go to a specific page in the app, there should be a pre defined intent to reach there. Either it can be custom intent defined by that app and exposed to others or may be predefined system app. For example, you can open Settings application and reach a particular page in it based on the intents "Setting Application" has defined. Another example is "Camera Application". You can launch it and reach some page in it but not all pages.
In your case you may try something like this though:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/mp4");
I hope you understand what I meant.

Launching system and third party apps in android

I have searched ALOT now, i cant find a solid way to run apps like calendar, camera, facebook, twitter, insatgram, and all kinds of apps in android. I know that i need to use intents, but HOW can i do it? I really need help! Please help me and thanks alot!
There is no such concept in Android as "run apps". You start activities. Talented developers do not focus on specific apps (e.g., "facebook, twitter, insatgram"), because those apps may not exist on any given device. Instead, you focus on generic capabilities (e.g., use an ACTION_SEND Intent with startActivity() to share something, create a launcher by using PackageManager to find those activities that support ACTION_MAIN and CATEGORY_HOME).
If you want to launch some other application from your android application then you should know the package name for that particular application For example for launching facebook use
Intent intent = new Intent("android.intent.category.LAUNCHER");
intent.setClassName("com.facebook.katana", "com.facebook.katana.LoginActivity");
startActivity(intent);
Otherwise this can also be used
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);
If you want to launch the default android applications installed for some particular kind of operation then you can use implicit intents for that. For example to start a browser you can use
Uri webpage = Uri.parse("http://www.android.com");
Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage);
startActivity(intent);
You should take also take a look at intents and intent filters and how to allow other apps to open your application.

Is htmlview too elementar?

This is certainly a very basic question, please excuse me if this is well known.
I made a Java app that generates a HTML file 'fileout' to be viewed locally (essentially a page with thumbnails that open bigger images with some javascript (not really needed); both thumbnails and images are in my sdcard). Then my app calls an intent to open the page, in the usual way:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(fileout), "text/html");
startActivity(intent);
The problem is that the app calls HtmlView, that behaves too restrictive: no back action to open another image, horrible title bar (I want full screen), not really good rendering of thumbnails, etc. So my question is:
Is there a way to configure Htmlview? How configurable is it? Does it understand javascript?
Moreover, if you think I would be better served with the default browser, how do I tell the app to open the browser instead of htmlview?
Sorry for the several-in-one questions, but they are all linked.
Thanks!
L.
Do you mean WebView rather than HtmlView? While WebView is fairly configurable and you could make it into a reasonable browser experience, it's a bit of work to do so. WebView does support JavaScript, but you have to enable it. As for "not really good rendering of thumbnails", that's rather vague. All in all, unless you have some specific need to run it in your own view, I would tend to prefer to just open the file in a browser if that experience is acceptable. Your current code should actually already do so... Perhaps the app selector popped up and you set it to use your app by default?
You can use WebView that will load html file you want and js hand by hand. This will allow you not to leave your activity or application at all.
WebView can be configured as you want it.
Idea:
Start new activity that will run with no title bar/windows fullscreen.
Read:
http://developer.android.com/reference/android/view/Window.html
for setting different window flags.
In your activity set content view to some WebView
Read:
http://developer.android.com/reference/android/webkit/WebView.html
Pay attention on .setJavaScriptEnabled(true);

Android posting to Twitter

I have seen that there are a few good libraries out there. These seem to come with all the bells and whistles.
My application only needs to post a status update to a twitter account. Each time the user would have to enter their details. This is not the major part of my app, so I was wondering if there are any condensed libraries or simpler ways to achieve this without including all of the features that come with larger libraries.
Any advice greatly appreciated.
You can use the ACTION_SEND intent. Any application capable of sharing, including a twitter and facebook apps if installed, listens for that intent. The system will then show a dialog to let the user choose how they want to share the message. Use something like the following code:
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(intent, getString(R.string.share)));

Categories