I'm curious on the Intent.createChooser() method. I've done some research but haven't been able to find the specific answer I was looking for.
I have a requirement that depending on which application the user picks (either email or text) I'm to format the text differently. I'm OK with the chooser displaying other applications (I'd prefer to not remove options for users) but is there a way for my application to know which external application the user selected? From there I could maybe overload the initial Intent and send the properly formatted data.
Thank you in advance for any help.
I'm OK with the chooser displaying other applications (I'd prefer to not remove options for users) but is there a way for my application to know which external application the user selected?
No, sorry.
For that, you would need to create your own chooser dialog, using PackageManager and queryIntentActivities(). Based on what the user chooses in that dialog, you can then set the appropriate extras on the Intent, along with the selected ComponentName, and use the resulting Intent with startActivity().
(one of these days, I'll write one of these dialogs, as this question comes up a lot...)
Related
I would like to show a notification and play a sound when the user taps onto that notification. It works somehow when I use an activity to play the sound, as I have written in my own answer to this question: How can I create a notification that plays an audio file when being tapped? (in this question and answer there is also the source code showing how I create the notification and how my PlaySoundActivity looks like.
Yet, I have realized, that while the sound is playing, the appearance of my main application changes and it will not be restored without closing the application.
I have created my application from the "Tabbed Activity" project template.
This is how it looks after being started:
And this is how it looks when I have tapped onto the sound notification (the sections are gone):
Can anyone explain why this happens? Is it a wrong approach to play sound using an activity? But it does not work here when I use a service, I hear nothing! How to solve that?
According to the Android developer reference, "almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View)".
I had not done this. Therefore a new window was displayed, but there was no content.
The better solution for playing a sound is to use a PlaySoundService (service!!!) instead of an activity. It contains almost the same code as an activity would do, but the pending intent is created with PendingIntent.getService(...) instead of PendingIntent.getActivity(...). Using the wrong method does not result in an obvious error message, but the service won't work as expected.
Searched through the internet and couldn't find a god example of achieving the following. There is a Launcher activity. User will be navigated to the launcher activity first and inside that activity , when the user says a certain word like "Start" or something like that the app should navigate the user to another activity. I've gone through a set of tutorials , and I've seen some similar questions at SO but none of them make sense to me. What will be the best approach to achieve this ?
Basically what you have to do is
build a framework/module to handle Speech Input (speech-2-text)
Depending on Input by user, perform an action
Like getting an image. I want to give users the choice to access either the camera, gallery or any other app which can return an image.
Create dialog with three options camera, gallery, file explorer.
When user select an option from the dialog call proper intent to open selected application.
Please refer the link :http://www.theappguruz.com/blog/android-take-photo-camera-gallery-code-sample
Hope this will help you
I am new to android and was starting out by making a list of button.i want when each button click launch a same activity for them with diffrent resource such image and raw file
what is big deal here?
call same intent twice :)
refer how to start new activity here
You can the same activity/intent multiple times, just if you want the code in said activity to do something else you might want give it some extra information by using intent.putInt(<Key>, <Value>); and others
So, if you haven't noticed. Many new launchers give you the option to select an application to be launched as default for a specific category.
My launcher consists of different fragments which displays cards, these cards hold a button which has a function where when the user touches the button, they're prompted with a window where they can select which application to run for that specific view. To make things easier for the user, the intent or app they selected should be saved, so if they select the button again, they don't have to select the app again.
If you would like a few examples to what I mean, take a look at 9 Cards Launcher or Smart Launcher, or any Windows 7 Phone Launcher. They prompt you with a small pop up which lets you select the application you want to run and its set.
how can I achieve this? Please I have literally searched everywhere, but nothings making sense. There are no tutorials on this, I have also decompiled various launchers to see how this works but I don't know where to start.
It'd be great if you could help.
1st of all you need to get the Installed Applications.
Then you will get the application package info from the user selected Application.
Finally launch the intent.
Here's what you can try out:
Create an intent with action=MAIN and category=LAUNCHER
Get the PackageManager from the current context using context.getPackageManager
packageManager.queryIntentActivity(<intent>, 0) where intent has category=LAUNCHER, action=MAIN or packageManager.resolveActivity(intent, 0) to get the first activity with main/launcher
Get the ActivityInfo you're interested in
From the ActivityInfo, get the packageName and name
Finally, create another intent with with category=LAUNCHER, action=MAIN, componentName = new ComponentName(packageName, name) and setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
Finally, context.startActivity(newIntent)
I would also suggest to take a look at FreeTaskManager