gcm causes large battery usage - android

I have a simple Android app that does not do anything special except receiving and showing GCM notifications and - then - opening the browser (when a notification is clicked on).
GCM is configured newely as described in the current documentation. The browser is based on the class WebViewClient.
I have noticed that this app consumes 4 or 5 times more battery as any other app installed on my phone. As far as I can understand the BroadcastReceiver is always running which can cause such an extremely high battery usage.
Is there any may to reduce it? Sometimes my smartphone gets really hot without any activity from my side.
The fragment of my Manifest about GCM:
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:persistent="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<action android:name="my.package" />
<category android:name="my.package" />
</intent-filter>
</receiver>
Thank you in advance.

Probably the best that you can do is to implement GCM (Google Cloud Messaging) using pushing instead of polling.
In this way you will be able to get a "tickle" when something new happened and you will know when ask to the server for datas.

Related

BootReceiver not working in all android devices

i have been trying to overcome issue of Boot_complete receiver not working in certain devices.
Like Vivo device which have iManager app with auto-start manager.
Where user can toggle app from auto start on device boot.
What should i use along with below as intent-filter to restart my service after device reboot.
Earlier thought of using Battery_Change receiver but it won't work from manifest, as i has to be runtime receiver register.
Any suggestion would be really help-full.
Below is what i have used as intent-filter for my app. In most devices its working as expected. But not in all.
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.REBOOT" />
</intent-filter>
There is one thing my team and I discovered when facing a similar issue.
You can monitor the usb state like so:
<receiver
android:name=".MyReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_STATE" />
</intent-filter>
</receiver>
And if memory serves me right, this will send a broadcast before the regular BOOT_COMPLETED action telling you there is or isn't anything USB connected.
Some manufacturers use their own version of BOOT_COMPLETED as you can read here but the USB_STATE is an alternative, based on the things you want to do. Do note you can get multiple broadcasts using this method!
Alternatively you could look into using an AccessibilityService or the JobService from the firebase sdk. More details here.

WearableListenerService only wakes up when I open my app

I have successfully implemented communication between my phone and watch app through WearableListenerServices in both modules. This works perfectly for the most part, however, if i don't use the phone app in a while the watch app stops communicating. This suggests the WearableListenerService is not "woken" up as expected. To fix this, I have to open the phone app and for the next while the watch app communicates perfectly again.
Is there a way I can guarantee that it will be "woken" up? Or am I missing something?
Phone manifest:
<service android:name=".app.util.ListenerService">
<intent-filter>
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<data
android:host="*"
android:scheme="wear" />
</intent-filter>
</service>
Wear app:
<service android:name=".util.ListenerService">
<intent-filter>
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<data
android:host="*"
android:scheme="wear" />
</intent-filter>
</service>
If you need more on the specific implementation of the listeners I'm happy to provide it, but it doesn't seem relevant. Thanks!
We all knew that the BIND_LISTENER for wearable app is already deprecated and it is replaced by a fine-grained intent filter. So make sure that you use a correct filters for your app. You can know the meaning and purpose of individual filters here.
Try to check this documentation for Building Apps for Wearables, it shows you how to use the WearableListenerService for your app. It also provide some sample code that you can verify if you properly implemented this code in your application.

Push notifications are not received when app is not running

At least on a device running Android Jelly Bean (4.2.2) the push notifications are only received if the app is running. I think I'm doing everything right, that is, Im calling Parse.initialize on an Application class (which is referenced on my application tag on the manifest) and I have Parse's PushService and My custom Parse's Push Broadcast Receiver declared on the manifest just like this:
<service android:name="com.parse.PushService" />
<receiver android:name=".ParseCustomPushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.push.intent.RECEIVE" />
<action android:name="com.push.intent.DELETE" />
<action android:name="com.push.intent.OPEN" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
I didnt force quit my app or anything else, for the matter.
I would like my app to always receive push notifications even when is not running, much alike what happens with popular apps such as WhatsApp, Facebook, Skype, etc.
I know I'm not the first one experiencing this problem because I've seen countless posts on several forums of people complaining of Parse push notifications not being received when the app is not running, but none of the answers to those posts offer a workaround...
So, can anyone explain why this even happens?? Is it an Android bug? Is it because Parse's PushService is not sticky? If yes, then, should not it be sticky???
And if possible, please, suggest a workaround for this problem! :)
Thanks!

intent-filter for knowing when some app is being opened?

I would like to know which intent-filter use for listen when some app is being opened from my BroadcastReceiver.
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
</intent-filter>
Android OS doesn't allow this behavior. No broadcast will be sent out when a particular app is opened.
However, you can have a service that is constantly running in the background and in that service you can use the ActivityManager to get a list of the current open apps. Based on that info, you can start your activity. This is a work around.
There is no system broadcast sent out "when some app is being open", for privacy and security reasons.

I am making an app and want to know when the app is uninstalling

I am making an app and want to know when the app is uninstalling. For doing it, I used BroadcastReceiver but I don't know where is my code is wrong? (when my app is uninstalling, BroadcastReceiver can't receive any message about uninstalling)
It's my app's Manifest:
<receiver android:name="receiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_DATA_CLEARED"/>
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
<action android:name="android.intent.action.UID_REMOVED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<action android:name="android.intent.action.MEDIA_REMOVED"/>
<action android:name="android.intent.action.MEDIA_BAD_REMOVAL"/>
<action android:name="android.intent.action.BATTERY_OKAY"/>
<data android:scheme="com.example.testpermission"/>
</intent-filter>
You cannot get an event when your own app is uninstalling. See here. There is also a post on the subject here.
You can't, but if you have second installed application on the device - you can get notification via that application about the uninstallation of the first one (as far as I remember).
I believe that the application cannot monitor its own uninstall from two reasons:
It will make it much harder to uninstall application (some evil apps might even try to do something bad when their application is being removed).
If you remove application - you cannot run it, or send it events! The app should be closed for clean deletion.
About how to do it from second app:
Your second app should be a receiver to the ACTION_PACKAGE_REMOVED event (read about BroadcastReceiver, and see: http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_REMOVED)

Categories

Resources