In manifest in application tag I have:
<receiver
android:name=".MyC2dmReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<!-- Receive the actual message -->
<intent-filter>
<action
android:name="com.google.android.c2dm.intent.RECEIVE" />
<category
android:name="com.my.app" />
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action
android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category
android:name="com.my.app" />
</intent-filter>
</receiver>
And my receiving has sth like that
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("com.google.android.c2dm.intent.REGISTRATION")) {
handleRegistration(context, intent);
} else if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
handleMessage(context, intent);
}
}
When my app is on or in background onReceive method is fired, but when I kill app using AdvancedTaskKiller onRecived stops receiving. Why?
Why Android doesn't start my receiver? Do I need sth in manifest?
Why?
If you are on Android 3.1 or newer, it is because your application has been moved into the stopped state. This also occurs if the user force-stops you via the Settings application. Until the user manually launches your app again (e.g., taps on an icon in the launcher), none of your BroadcastReceivers will work.
Related
So, I have an alarm application which works good and behaves normally as long as the device remains online until the alarm time.
Problem is, let's say I ran out of battery, or I just want to restart the device... the alarm won't fire upon its time.
I tried something like:
public class BootCompletedReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
Utils.set_alarms(context);
}
}
}
In my BroadcastReceiver... but doesn't seem to work. Oh, and it's registered in the AndroidManifest too...:
<receiver
android:name=".receivers.AlarmReceiver" // The receiver which starts the alarm activity.
android:enabled="true" />
<receiver
android:name=".receivers.BootCompletedReceiver" // The receiver which is supposed to set the alarms after the device is online again.
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
But doesn't work... help will be appreciated.
You probably need to add the permission to receive boot completed to your manifest. See Manifest Permission: RECEIVE_BOOT_COMPLETED
Add below permission and actions
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver
android:name=".receivers.BootCompletedReceiver" // The receiver which is supposed to set the alarms after the device is online again.
android:enabled="true">
<intent-filter>
<!-- used for restart or reboot -->
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<!-- Used for cold boot -->
<action android:name="android.intent.action.BOOT_COMPLETED" />//cold start
</intent-filter>
</receiver>
I have a BroadcastReceiver which is working, but when I go into recent and swipe the app to get rid of it, the receiver stops working.
So i wanted to add this to the manifest i nhopes to prevent the receiver from dying
<receiver
android:name=".CounterReceiver"
android:enabled="false"
android:process=":counterreceiver">
<intent-filter>
<action android:name="com.example.johnbravado.zionwork.MESSAGE_PROCESSED" />
</intent-filter>
</receiver>
Send the receiver to a different process. Now, however, my receiver does not work at all. If I remove the android:process="" line, it goes back to working as expected.
Is this normal behavior or do i need to sendBroadcasta special way for the receiver to hear it since it is ona separate process?
Edit:
Here is the sending system. the sender is coming from a service
#Override
public void onMessageReceived(final MessageEvent messageEvent) {
nodeId = messageEvent.getSourceNodeId();
String incomingPath = messageEvent.getPath();
int incomingReq = Integer.parseInt(new String(messageEvent.getData()));
if(incomingPath.equalsIgnoreCase(MyConstants.MSG_COUNTER_REQ_PATH)) {
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(MyConstants.BROADCAST_ACTION_RESP);
//broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
broadcastIntent.putExtra(MyConstants.BROADCAST_DATA_REQ, incomingReq);
sendBroadcast(broadcastIntent);
}else if(incomingPath.equalsIgnoreCase(MyConstants.MSG_DEFAULT_PATH)){
}
}
The sending service manifest
<service
android:name=".MyWearableListenerService"
android:enabled="false">
<intent-filter>
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<data
android:host="*"
android:scheme="wear" />
</intent-filter>
</service>
I know i have enabled=false that is not issue as i set it to true via package manager.
I have an Android Wear app that sends messages to the handheld device. The handheld device that is supposed to receive the messages does not have any app UIs and thus no MainActivity. How do I get it to receive messages from the wearable?
Is there a broadcast triggered when Google Play Services receives a message from a wearable that I can use to launch a service?
This is what I have so far in the mobile application:
public class ListenerService extends WearableListenerService {
public ListenerService() {
}
#Override
public void onMessageReceived(MessageEvent messageEvent) {
Log.v("Test", "ListenerService.onMessageReceived()");
}
}
AndroidManifest.xml:
<service
android:name=".ListenerService"
android:enabled="true"
android:exported="true" >
</service>
The wearable sends a message but the onMessageReceived() is not fired.
Edit
BIND_LISTENER is deprecated now. It has to be replaced with
<intent-filter>
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<data android:scheme="wear" android:host="*" android:pathPrefix="/prefix" />
</intent-filter>
more info here.
old answer
You missed the intent-filter in your Manifest.
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER"/>
</intent-filter>
In my android application I am using the push notifications supplied by Parse.com. I have successfully got this working, however my application has multiple push notifications and different activities should be loaded depending on which push notification has been pressed. I expected to be able to get the message for the push notification from the intent parameter of the onPushOpen, but it seems to be empty? . Does anyone know how I could get the message in the onPushOpen method?.
For some context, I have added my current custom PushReceiver code below.
public class PushReceiver extends ParsePushBroadcastReceiver {
#Override
public void onPushOpen(Context context, Intent intent) {
Log.e("Push", "Clicked");
Intent i = new Intent(context, Splash.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
Thanks.
Make sure you've upgraded to Parse-1.8.2.
Then you'll also need to do two more things.
Add information into your AndroidManifest.xml (within )
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.GcmBroadcastReceiver" 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" />
<category android:name="com...ADD_PACKAGE_INFO_HERE..." />
</intent-filter>
</receiver>
<receiver android:name="com..ADD_PACKAGE_INFO_HERE....PushReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
Add this to AndroidManifest.xml outside the tags
Within the cloud code on Parse.com, set the uri of the broadcast to "com....ADD_PACKAGE_INFO_HERE...PushReceiver"
NB: #1 & #2 should be provided for you in the debug trace when you run your android app.
Hope this helps. I spent hours trying to get this to work and the key for me was updating to 1.8.2.
EDIT:
You should also look at overriding onReceive as well as onPushOpen...that actually gets called on a notification. Good luck.
I am new to android. I get completely stuck in using ACTION_PACKAGE_RESTARTED in my application
I have removed pacakge from my emulator, also added using adb install but get nothing. Start an app. close that one and again start that app. nothing seems work for me. There is no log in logcat.
Is there anything that i'm missing? Please help
public class RestartReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String action= intent.getAction();
Log.i("D", "Inside receiver");
}
And here is the manifest file
<application android:icon="#drawable/icon" android:label="#string/app_name">
<receiver android:name=".ReceiverTest">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.ACTION_PACKAGE_RESTARTED" />
</intent-filter>
</receiver>
</application>
the value specified in the intent filter is incorrect..actual value is
<action android:name="android.intent.action.PACKAGE_RESTARTED" />
and this broadcast can be received for other packages only. Restarted application/package doesn't receive this broadcast.
You should add a data specification to the intent-filter:
<data android:scheme="package" />