First time posting.
I want to make an alarm app that launches a radio app at the set alarm time.
The app works fine when the phone is awake, the radio app launches and the radio plays at the time specified by the alarm, my issue is when the phone is locked/asleep, the radio app I want to launch will launch but not attempt to connect to the radio stream until I unlock the phone. When I unlock the phone the app is open and starts to buffer then works.
How do I get the app to connect to the radio stream while the phone is asleep?
I have tried WakeLocks (Partial WakeLocks) thinking that keeping the CPU alive would allow the app to connect to its radio stream but this did not work.
Would appreciate any input here.
EDIT: I have downloaded an app that does what i want and it seems the radio plays within the notification.
Would this be the correct direction to investigate?
Well, I figured it out after eventually.
using media player and connecting to the correct steam sorted it for me.
For anyone struggling:
Main activity you want to create all the actions for the button clicks, build an Intent and get the time from the time picker.
Alarm receiver to handle the pending Intent
Radio service class to play radio stream using Media player.
It actually was very simple in the end.
one of the things that was holding me up was the incorrect use of the stream source I was using:
I was trying: http://www.lbc.co.uk/london/radio/player/
I needed: http://www.lbc.co.uk/london/radio/player/
I obtain the correct streaming link from FAQs on the radio website.
I will post a finished sample code once I have done cleaning the app.
Related
I am developing an App, which can play a tone at a fixed frequency to the users by using the Audiotrack Java class. Now the sound can be played when a button is pressed, I want to keep the sound keep playing when the screen is off, because the users may want to listen to the sound for 20 minutes at night where doesn't require the screen on all the time. Anyone can help with this?
I have tried the WakeLock according to other posts on Stack overflow, but it doesn't work. when I go to the activity, the app stops and quits.
To keep sound playing when the screen is off, use a foreground service to play the sound and when the user clicks the start button, you should start your service
I've implemented OneSignal push notifications in my Android app. I'd sending push notifications with URL as a payload attatched to them. That URL sends an intent that can be opened by another activity of my app or the browser. So, when some activity of my app is in foreground and I choose to open the notification in my app, there are 2 instances of my app. So, even if a user taps Exit in the now top-most activity, the one that was already opened still remains. Basically, users have to exit twice from my app (and possibly more times if this keeps on happening).
So, is there any way by which I can finish the foreground Activity when the user taps on the notification (and chooses to open it in my app instead of the browser) and then proceed..?
Also, I have tried all the launch modes: normal, singleTop, singleTask and singleInstance, all produced the results that they were designed to, but, none could suit my case.
I don't know which code should I include here.
If this can't be done, is there any way to launch all activities of my app (no matter from where they're launched) into the same instance?
For this you will have to start activity from notification by using activity flag like this
yourintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
it will clear foreground activity instance and your new activity instance create on top.
I was wondering what the best way to do this is. What I'm hoping to do is have a user push a button and automatically take a 10 second video, then save it to the SD card. I've seen how to do it through creating a new Intent, but the user then has to do the extra step of pushing record after selecting that they want to go to video. My goal is for them to push one button--one in my app that says "record", have it start recording for 10 seconds, then stop and save. In addition, I'd like to have some code executing in the background without being interrupted during said recording. What is the best way to do this?
Opening the camera with an Intent is simply opening the system camera app to take a picture/video. For more advanced usage, you can control the camera directly. Full details are in Controlling the Camera (from Android Developers).
You should make a service for that.
I want my users to be able to launch my app by long pressing back button, recent apps button or home button. Or even long press on volume up/down or power button.... something which would allow users to execute my app without touching a screen icon.
I offer similar voice solution to Google Now, which btw. opens after a long press on home button. Any way I can do the same? I get this question from my users almost daily...
I don't think your users will be able to do this without rooting. I found this thread which is worth reading:
http://forums.androidcentral.com/samsung-galaxy-s3/183113-button-remapping.html
alternatively they mentioned Go Launcher app
I've read through the list of ACTIONs that you can use for starting an activity through intents, but can not find any of the ones you wanted. If you do find any other ACTION useful there is more info on how to actually do it here.
I'm new to Android Java programming.
I've created a simple chat app. Things are going well, but I've hit a small snag. I've set launchMode="singleTop" in my manifest's application tag, and overrided the back button, so now the chat app remains running (in the background) when the user presses the back or home button. I've also created some notifications that pop up in that status bar when a new chat appears (with intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP) set), and when the user clicks the notification it brings the already running chat app to the front. That's all working fine; the problem arises after I bring up the app from the status bar notification, then click back or home, then choose to open the app from the applications menu or a shortcut on the launcher, and thats when it opens up a second instance of the app.
Is that clear?
If the app isn't running and I choose to run it from app menu, it runs (doesn't display any chats because it hasn't received any). I receive a chat and see it on screen in the app, I press back button, I go back and open app through app menu, it runs and has the chat messages from before. Good. Now I press back (so app is in background, but still running), I receive a chat, it pops up a status bar notification, I click it, it opens up the app and shows chat messages from before. Good. Now I click back (so app is running in background). I then open the app through the app menu (like I did the first and second time), but this time it doesn't show the previous chat messages, and if I receive a chat, it makes 2 notification sounds, so I know it has started a new instance of the app.
Any idea what's wrong?
Thanks.
set the activity launchMode to singleInstance in manifest.