Push notifications on emulator working, but not on real device - android

I got a working example of a third party server to send push notifications to the device which is perfectly working in the Android emulators I use. As soon as I try to use it on my real device (Samsung Galaxy S) I don't receive my notifications anymore, even tough I reregister the device at the google server (as I use the same gmail account). I basically have no clue where to start looking as Logcat is not giving me any interesting information about it. The code is working in the emulator device, so my guess would be to start looking at the permission rules. Any ideas?
I don't know if this matters, but I am using Ubuntu 10.10 to develop/debug.

Is your ROLE Account gmail ID same as the gmail ID configured on the phone ? I did have problems with this. If so, can you try using some other gmail ID on the phone ? For more see this.

could that be a permission issue? did you set right permission in the manifest?
maybe the emulator is not so strict on lack of permissions (I've experienced that sometimes, some devices worked and other didn't, and all I was missing was a manifest permission)
you have to set both
<permission
android:name="your.packagename.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
and
<uses-permission android:name="your.packagename.matchtracker.permission.C2D_MESSAGE" />
in the main section of your manifest and declare a brodcast receiver with
<receiver
android:name=".push.RegistrationReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="your.packagename" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="your.packagename" />
</intent-filter>
</receiver>

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.

Android detect usb storage for kitkat (4.4)

I've created a webview app which hosts a website within the app in the assets-directory.
I want to update the website via an USBstick inserted in my tablets usbslot.
I tried it first with the .MEDIA_MOUNTED broadcast which doesn't work for my android 4.4. Tablet.
I've searched for an alternative and found the "MediaScannerConnection".
There are several examples here, which didn't help me much, to solve my issue.
I'm looking for an easy and clean solution and a little explanation would be nice too, to detect if an USB-Storage is connected and the chance to execute some code afterwards.
And how make this USB-check run all the time is a question in addition. I assume i have to put it in the OnResume method, but i'm not quite shure.
Please post code for your BroadcastReceiver and AndroidManifest.xml.
Manifest should look something like
<application>
<!--- ... --->
<receiver android:name=".UsbBroadcastReceiver"
android:exported="true"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<action android:name="android.intent.action.MEDIA_UNMOUNTED" />
<data android:scheme="file" />
</intent-filter>
</receiver>
</application>
Note the data tag, it's often overlooked.
In your onReceive implementation the URI to root of mount can be obtained from Intent#getData().
Also note that this will not work on Android 6.0 (M) and above. For 6.0 and above your code must request access to USB via one of two ways:
1) UsbManager#requestPermission
2) Intent#ACTION_OPEN_DOCUMENT_TREE as part of Storage Access Framework

gcm causes large battery usage

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.

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!

How to start my application on phone shutdown event

I am making an android app, in which the app must launch just before the phone is shutting down. Is that possible?
Here i am not talking about encountering phone shutdown event when my app is running.
You will need this permission in your manifest file
<uses-permission android:name="android.permission.DEVICE_POWER" />
And you will listen to the intent like this
<receiver android:name=".ShutdownReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
</intent-filter>
</receiver>
You can look at the links here for some description and here for official documentation.
I don't know the exact application where you want to use it, but you can have a background service running with the receiver for this intent.

Categories

Resources