Android Record Video With Code In Background - java

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.

Related

Java - android - change activity of app while running in the background

I'm developing an Android app with several types of alarms and triggers.
One of these alarms trigger if you stop moving (GPS tracking) while it's active.
Now, when the app runs in the background when this triggers the client doesn't update when you switch back in, and the only notification received is a push-notification from the backend service. If I enter through the notification, the client loads the alarm correctly.
The code base is quite extensive, and due to time and resources it would be best to avoid huge refactoring tasks.
Is there an easy way to make the app go from Activity A to Activity B when it's running in the background?
You cannot change the current Activity in the background without bringing the app to the foreground (using startActivity()). However, you can surely tell the app that when it is brought to the foreground it should start a certain Activity or rearrange the back stack or whatever.
Post some of the code and maybe we can help more.

Launch a radio app as my alarm for android

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.

How to have a GDK app stay active after the glass is removed from the head

I am developing an app which requires the gdk program to continue running as-is even after the device is removed from the head. Currently the program is paused when this happens seemingly by default, but I need the program to stay running because it is constantly uploading video. The desired result is that the program will continue to run and upload a video stream even if the glass is removed from the user's head.
What can I do to change this behavior?
thank you.
You probably want to perform the long running upload in a background service. Android's activity model makes it such that you can't really depend on the life of the activity to always be in the foreground and you need to use a service for tasks that shouldn't be paused.
Also if you have an activity you want to return to when you put Glass back on, ensure you specify android:immersive="true" within your declared <activity>. Without this, your activity could be completely destroyed when the screen turns off.

Android (or iOS) - Image Upload Queue

We've written an app for Android (and iOS), and it allows users to upload photos to our REST server. The issue we're hitting is that sometimes the users are in places with terrible cell signal and no WIFI. So, I was wondering if there was either a prebuilt solution, or a recommended path to take to defer these uploads until later if there are only lackluster network options available.
Right now on Android I'm using an AsyncTask to upload a stream representation of a captured image. The image's maximum dimension is cropped to 1280, and the other is aspect scaled, so the images aren't massive.
The user may have no signal for up to 2 hours I imagine, so it'd not need to attempt to upload every minute. Additionally, there may be multiple uploads, so some kind of queue is needed, I think.
I'm not positive what the iOS app is leveraging, but I can find out if it helps.
The best option would be to save the photo to the SD card and put the path to it in a database. The database here acts like a queue. So whenever the user has access to internet, the app can check whether there are any entries in the database and start uploading. Once you upload the photo, you delete that record from the database.
Now, as far as the upload is concerned, I recommend doing it in a Service as opposed to an AsyncTask. This way you can use an AlarmManager to call the service at periodic intervals and check whether there is anything to upload.
I used this method in one of my applications but for documents. It works like a charm. Hope that helped.
In iOS I used ASIHTTPRequest, but at the moment you can find other solutions (MKNetworkKit). I did an application exactly like what you are doing so what I did was:
Check if there is internet, if yes continue, otherwise stop.
Try to send one photo, if succeed go to the next one, otherwise leave the photo on the queue and go to the next photo.
Repeat process.
Let's imagine the user putted 20 photos on the queue, and start the process, at the end of the day he could check again what succeed and what didn't. Of course he could re-send what failed in the first place.

creating a service for playing audio in the background

I have searched, but can not find the answer I'm looking for.
I want to create a service and be able to call a function to play an audio file.
I have 5 different intents that will be using the service to play 5 different audio files (one each) and I have a stop button in each one. Whichever stop button is pressed I want it to stop all audio that has been called from the service.
Does any one have an example code which I can use? (Something close to what I'm looking for.)
I'm building a media player to understand how Android works, and I have a service that queues audio files to play them. You can get the full source code from github.
The service is in /src/com/augusto/mymediaplayer/services
I'm not using Intens, but binding the service to the Activities that use it, but changing it to receive intents shouldn't be that hard. Just in case, this service runs ok on Android 1.6+.
I think that to change it to receive intents, you'll need to change onStart() and do a switch on the intent.
I know that this doesn't answer your question 100% but it's a place to start :).

Categories

Resources