I am developing an app which records unlocks of mobile. But I am having problem when my app is manually killed i.e. when you remove app from recent apps. How can i record broadcast even when app is killed?
I am using ACTION_USER_PRESENT for recording unlocks.
You'll need to create a Service and inside this service create the broadcast receiver that you need.
This answer Certainly will help you : Implement Broadcast receiver inside a Service
Related
I have simple app for show pageView with text, I want to notify user at specific time every day to open my app at specific page.
So I test my App by Marshmallow device, I am using alarmManager for this task, but once I close App from main screen notification stop showing.
I used Broadcast Receiver with remote process android:process=":remote" but Alarm not work also I used service also it killed with closing App.
So what is right sequence to achieve this job?
You don't need to use Service. AlarmManager and a BroadcastReceiver to restart alarm service on device boot.
Check this example:
http://stacktips.com/tutorials/android/repeat-alarm-example-in-android
When I was making alarm clock app for me Service with WAKE_LOCK was waking up the phone when it was blocked or the app was killed by user.
This class(with some notification displayed) is preventing app from being killed :
https://github.com/mrkostua/SmartAlarm/blob/master/app/src/main/java/com/mrkostua/mathalarm/alarms/mathAlarm/services/WakeLockService.kt
So after scheduled intent can be send to BroadcastReceiver.
Basically I am trying to make an activity containing a button which reboots the device and after the reboot returns to the same activity.
I understand that this question may get confused with others about rebooting the device, but that is not the focus of this question as I can get the device to reboot fine.
I have made the button reboot the device but the only way I can get it to start the activity after it's finished rebooting is to register a broadcast receiver for BOOT_COMPLETED in the manifest. The trouble is that this method starts the activity every time the device boots which is undesirable. When I register the receiver on the button click listener it does not start the activity after the reboot.
I was wondering if there might be an extra in BOOT_COMPLETED that I could use to decide if it had been purposefully rebooted.
Any advice would be appreciated, thanks in advance!
Just save an integer corresponding to device purposely being rebooted through your activity. Use SharedPreference for the same. On reboot, in your broadcast receiver, check if the value is set. If it is set, start your activity, otherwise, let it go.
EDIT :
Always, unset this value when reboot is complete and your Activity is in front.
Your XML should be stored in a file named AndroidManifest.xml, not manifest.java.
Another reason your code is not being run, might be that your App is installed on external storage (sdcard). BOOT_COMPLETE is sent to applications before external storage is mounted. So if application is installed to external storage it won't receive BOOT_COMPLETE broadcast message.
If that isn't the problem, there is already a very good description of how to get boot completed receivers working on Android.
Trying to start a service on boot on Android
I am using Google Voice in my android app, and I am connected the app to Bluetooth module, each time I call the Google Voice, the app try to connect to Bluetooth again, each time Google voice window Popped up, the connection lost, and once the window disappear, and the connection comes back again. So, Is there any way to keep them connected even I call the Google Voice window? Any ideas or help I will be appreciated.
You need to create background service for your problem. If you need persistent connection with your Bluetooth you can use intent service. If you are using android studio then it is very easy to create service. Just make sure you must have all necessary information about services and how to make then persistent in background.
Because of this your application will drain your device battery drastically. Make sure service is closed when application exit or all activities are finished.
See this link for more information
https://developer.android.com/training/run-background-service/create-service.html
Place the Bluetooth related processing in a Service. Make the service foreground service.
Activity can connect/disconnect from service anytime.
In my android application i am using android push notification everything works fine until the user forces the application close(It happens always nowadays especially with the task monitoring application available in the play store).No more notifications are visible or possible.After some googling i found that From android 3.1, if the user force closes an app, it will stop to be notified of any broadcast until the user does not start your the again.
Is there any solution to prevent the broadcast receiver killing or any other possible (like making a Que of messages that aren't received by the device and send them later)?
if the user force closes an app, it will stop to be notified of any broadcast until the user does not start your the again.
sorry, that's not true. for sure.
I think you are confusing with something else: from android 3.x - broadcast receivers would never react to a broadcast until the app is launched for the first time.
if you implemented properly your GCM client side - it should work even if user force close the application. that's because the operating system waking up your application if it has the right broadcast intent filter and receiver, what mean that your application don't have to be running in order to receive this broadcast.
No more notifications are visible or possible
If your indication that the GCM not received is the fact that you don't see any Notification, then it's not necessarily true - there is no direct connection between GCM message to the system bar notifications. that's true that usually you'll show notification when push received, but it's deferentially not must.
what I'm saying basically - maybe you have a bug that takes affect after the user force close your app that causing the notifications not to be shown.
I am working on Push Notifications in Android. Now the issue is that I want to keep running my Push Notifications on the back ground as soon as the app start because I have no idea when the server will push the data to the devices.
The main requirement is that our corporate app is having more than 10 activities and based on the notification received, I have to bring the related activity on the foreground so that user can preform action on that or do some silent action in the background regardless the activity is in foreground.
Can somebody suggest how can I implement this type of requirement. Do I need to do it in a Service.
Thanks
An Android application on an Android device doesn't need to be running to receive messages. The system will wake up the Android application via Intent broadcast when the message arrives, as long as the application is set up with the proper broadcast receiver and permissions.
take look at this;
http://developer.android.com/guide/google/gcm/gcm.html
when message received from gcm server
onMessage(Context context, Intent intent): method of GCMIntentService gets fire,
so you write your code there
take sample example from here
https://github.com/ketanpatel25/GCM-Demo/tree/master/gcm
What you're trying to do defeats the purpose of push notifications. In push notifications, the server sends the message through Google APIs. These APIs then send a broadcast message to your app, which you listen for. Continuously keeping the app open in the background and asking the server for new messages is called polling.
Read up on the GCM documentation. Whenever you receive a message, Android will ca the onMessage(); method of your GCMIntentService.