Mimic parse.com push msging with MQTT? - android

Is it possible to mimic parse.com's push service hitting a broadcast receiver's's intent filter with MQTT?
Parse is incredibly unreliable and unscalable, I can't for see that service be able to handle possibly millions of pushes needed. But their feature to allow a push msgs to trigger an intent is invaluable.
So, As I setup up an MQTT service in android, how can I go about allowing incoming msgs to that service to then hit a broadcast receiver's filter, in turn hitting an intent.

Have a look at the code snippets in the page http://www-01.ibm.com/support/docview.wss?rs=171&uid=swg24033580&loc=en_US&cs=utf-8&lang=en ... Also download the zip that has more code.. You can actually use the process given there to send push notifications using MQTT.

Related

The right approach to listen to GCM notifications

I'm trying to build a GCM notification listener, which will basically use the notification to flag the user that some operation should be made (which involve communicating with my remote App-Server).
I assumed that I should create a UI-less application running on the device's startup and listen to the GCM notifications and issue the internal android notification. When the user opens the notification an activity will be opened which will do the rest of the job with the remote App-Server.
Looking at notification examples it seems to me that I may be missing some basic understanding since all te examples which I had found use a UI application to manipulate the notifications.
What do I miss?
The common use case for handling of GCM messages in Android apps is as follows :
Your app registers to GCM upon startup and sends the registration ID to your server.
Your server sends a GCM message to your app.
You app receives the message in a broadcast receiver, which usually starts an intent service.
The intent service usually displays a notification to the user.
The user taps the notification, which starts an activity of the app.
You can see this use case implemented in the official GCM demo and in many other examples.
The fact that the app you wish to develop has no UI doesn't prevent you from implementing the exact same use case.

How can my Android app react to a push notification and download data in the background

I'm looking to make my app more responsive by having it automatically download some data (around 10KB) when it receives a notification. My two options (I think) are:
Try and pack all the info I need into the 4k payload limit - this may be possible, but certainly wouldn't help with iOS/WP implementations, as they have much lower limits. It also would be pretty inextensible, and I'd need to hand-craft the messages.
Send a notification which the app would react to and download data in the background.
If it's going to be 2, can I do that? Can it be done when the app isn't already running in the background or foreground?
For some updates I'd like to show a notification to the user. Can this be done in the same notification, or do I need to push another one?
Any similar info about iOS much appreciated, but not essential for answering the question!
When using Google Cloud Messaging you create a broadcast receiver which receives the GCM push notification. The broadcast receiver can either handle the notification on its own or start an intent service (which is better suited for your logic that downloads data from the server, since it runs on a separate thread, and doesn't block the main GUI thread). You can display a notification and download data from your server as a result of the same notification.
Look into BroadcastReceiver, once registered you can create a listener inside of your activity that will be called once the notification has been received.

Android program - reacts when skype message received?

I am making an android program that needs to do something when I receive a message from the Skype app. My Skype will be logged in, and it will be a service or activity waiting for someone to message me, and when it does it will play a song. Does anyone know how, code-wise, I can tell if I have received a message from the Skype app?
If there is no way to do this, how can I have a service scan the notification bar for a notification that contains the text "skype" and react right when it's received?
Thanks for any help.
If skype broadcasts intent upon message reception ( look into decumentation of skype if there is one ) you may just receive it ( via broadcast receiver ) in your application and do something. Incase it does not, there may be still workauround to snoop into status bar:
Detect a new Android notification
for skype notifications
In general "no". There's no way to do that on non-modified system.
You cant intervene other app's events and/or processing directly. It is only possible if Skype itself has provided an open interface (like Service Binding, Broadcast, etc.) to allow third-party integration. But as per my knowledge, I don't think its possible with Skype's own app.
However, if you use Skype's SDK and offer your own implementation of messenger service, then of course you'll be the in-charge.
According to this post in the Skype Developer Forum, the app does not send broadcast events (which would be the usual way to be programmatically notified of incoming messages).

Service that broadcasts different message types

I want to make a service that I can register to. The service will broadcast messages of different "types" and each application can register itself to recieve messages of different type.
For example:
I want to write a servive that reads the twitter messages of some user and broadcasts to the systems the tags.
Then a consumer can register to recieve only messages of tag "foo", and recieve the tweet message.
Another consumer can register to recieve only messages of tag "bar", and recieve the tweet message.
Lets assume I know how to build a service. My first idea is to just broadcast a something, and then filtering it in the apps. But I am not happy about this solution. I know there are some android services that work similar to what I want, but I found no reference on the web on how to implement this.
Some RTFM I have done is:
http://groups.google.com/group/android-developers/browse_thread/thread/e1863d2822b22a33/90873ef925cd2aad
http://www.vogella.de/articles/AndroidServices/article.html
What is the simplest way to send message from local service to activity
How to have Android Service communicate with Activity -> not good for me, as this question is about a single process, and I need the service talking to several different processes
The main problem, is that most of the docs on the internet are about me calling the service, and not the service calling me.
Assuming you talk about Service.sendBroadcast(Intent): You can broadcast anything you want but it gets impracticable at some point. You could even define a new Action for each Twitter tag but that will just be complicated.
You could use the Data part of the Intents here, Receiving code could filter Broadcast like that:
IntentFilter ifilter = new IntentFilter("com.your.package.ACTION_TWITTER_MSG");
ifilter.addDataScheme("twitter");
ifilter.addDataAuthority("com.your.package", null);
ifilter.addDataPath("/foo", PatternMatcher.PATTERN_PREFIX);
and you send them like that:
Intent intent = new Intent("com.your.package.ACTION_TWITTER_MSG");
intent.setData(Uri.parse("twitter://com.your.package/foo"));
context.sendBroadcast(intent);

Android: Infinitely running Service for receiving events?

I have a requirement that my app, can receive events (e.g. messages) from server any time (even if app is not running). So do I need to create an infinitely running service to listen for these events?
This to me seems similar to Email apps in Smartphones, like whenever you receive a new email(event in my case), its able to show notifications and also able to update my list adapter whenever I receive an event.
But I dun know how will I implement this?
You should take a look at C2DM (push-messages):
http://code.google.com/intl/sv-SE/android/c2dm/index.html#intro
it allows a server to send messages to devices at any time.
From the link:
Here are the primary characteristics of Android Cloud to Device
Messaging (C2DM):
It allows third-party application servers to send lightweight messages to their Android applications. The messaging service is not
designed for sending a lot of user content via the messages. Rather,
it should be used to tell the application that there is new data on
the server, so that the application can fetch it.
[...]
An application on an Android device doesn’t need to be running to
receive messages. The system will wake up the application via Intent
broadcast when the the message arrives, as long as the application is
set up with the proper broadcast receiver and permissions.
[...]
Events from server are called "push notifications" and are implemented via "Cloud 2 device messaging" (C2DM). On the mobile side these messages are submitted as broadcast events (see BroadcastReceiver). For a complete example see some tutorials: Google, Vogella or here on Stackoverflow
I think you have to start a Service as soon as the device booted. There is a good tutorial here how to achieve this.

Categories

Resources