Open Another App with android.intent.action.VIEW - java

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.

Related

How can I know the intents needed to open system activities

I have the need to open android's default screen settings, and previously I wanted to open android's default alarm configuration activity, in the future I'm thinking I would want to open GPS settings.
How can I get the information needed to start this activities?
Where can I found the documentation about this?
What's the process for getting this information without googling for the specific activity?
Check the Common Intents listing in the documentation.
It's a pretty comprehensive listing of the actions, URI formats and MIME types for building Intents for the standard Android applications.
There is a list of Actions in the documentation listed here.
You can launch any of the sub activities in the settings app using something like:
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));

Android Intent choose set default app

I am working on an android app and when a user clicks on a link and/or file, I want to give them the choice of choosing which app they want to use to open that link and/or file. At the moment it works the way it was intended to, but I am having trouble trying to let the user select a checkbox which lets them choose the default app to open that file with so they won't have to keep selecting it each time. I was thinking of having a checkbox in the dialog and then committing the value of it to the Shared prefs along with the app choice. After that, each time they click that file, the default app will be opened. In essence I am trying to get a dialog like this one,
But I keep getting this one,
Here is the code:
Intent intent = new Intent(Intent.ACTION_VIEW).setDataAndType(uri, mimeChoice);
startActivity(Intent.createChooser(intent,getActivity().getString(R.string.open_with_title)));
like tambykojak point out, the "The Android OS will take care of this depending on the Intent you've constructed" and thereĀ“s no option for default app. But you will construct your own custom dialog by gettin the apps installed determined by the package:
for example:
Facebook: "com.facebook.katana"; Whatsapp: "com.whatsapp"; Twitter: "com.twitter.android"; Google Playstore: "com.android.vending"; Chrome: "com.android.chrome" etc...
And saving the "default" option in preferences.
More info:
How to force Share Intent to open a specific app?
How to filter specific apps for ACTION_SEND intent (and set a different text for each app)

Launch an application in a different "context"

First of all, sorry for the "context" in the question title, I didn't know which word to use. I successfully launch my app by clicking over a URL from another application, but when I launch the task manager I realize that my application is not actually loaded: the caller app holds the activities. I would like how to:
Launch my app in a different "context" (sorry for the word again, which would be better?)
Be able to reload my app in the case it was already loaded (something like restarting it).
Thank you so much.
You can modify the behavior by setting "launchMode" attribute in AndroidManifest.xml to either "singleTask" or "singleInstance", both would cause your Activity to be created as the root of a new task. However it doesn't restart the Activity if it exist already, instead you should handle the Activity.onNewIntent(Intent intent) callback.
To learn more on launchMode see here: http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
In addition to launchMode that Kai mentioned, you might also want to look at taskAffinity and allowTaskReparenting, depending on how your app is structured.
This is an excerpt from there that seems to match how you describe your app:
For example, if an e-mail message contains a link to a web page, clicking the link brings up an activity that can display the page. That activity is defined by the browser application, but is launched as part of the e-mail task. If it's reparented to the browser task, it will be shown when the browser next comes to the front, and will be absent when the e-mail task again comes forward.

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);

Categories