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.
Related
I'm trying to implement a receiver that reacts to Bluetooth devices being connected or disconnected. However, I only receive the broacasts when the application is open.
I've added the receiver to the manifest:
<receiver android:name=".BleReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
</intent-filter>
</receiver>
And my receiver looks like this:
public class BleReceiver extends BroadcastReceiver {
private static final String TAG = "BleReceiver";
#Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Got intent: " + intent.getAction());
}
}
This works just fine when the app is open, but if I eg. use the task switcher and swipe the activity, no broadcasts are received anymore.
The output of adb shell cmd package query-receivers --brief -a android.bluetooth.device.action.ACL_CONNECTED looks just fine:
Receiver #3:
priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false
com.example.blelistenerapp/.service.ble.BleReceiver
Also, I checked the implicit broadcast exceptions, and these two actions are listed there.
Try
<receiver android:name=".BleReceiver">
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED"/>
</intent-filter>
</receiver>
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 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.
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" />
I'm trying to send a custom intent to my service that is based off IntentService but when I do context.sendBroadcast nothing seems to happen. I've checked through the logcat logs and can't even see the intent resolution failing.
My service registration in my Android.xml is
<service android:name=".Service.FbSlideShowService" android:enabled="true" >
<intent-filter>
<action android:name="com.test.fbslide.UPDATE_WALLPAPER" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</service>
I'm trying to send the broadcast from a helper class on my activity thread and passing in context using, I've tried sending it in 2 ways:
Intent changeWallpaperIntent = new Intent(mContext, FbSlideShowService.class);
mContext.sendBroadcast(changeWallpaperIntent);
And
Intent changeWallpaperIntent = new Intent(FbSlideShowService.UPDATE_WALLPAPER_INTENT, null);
mContext.sendBroadcast(changeWallpaperIntent);
But the broadcast just doesn't work.
Any ideas?
sendBroadcast works when you have a BroadcastReciever. But what you have here is a sevice
<service android:name=".Service.FbSlideShowService" android:enabled="true" >
<intent-filter>
<action android:name="com.test.fbslide.UPDATE_WALLPAPER" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</service>
Your manifest entry tells that it is a service
You need to use mContext.startService() to start the service.
If you want to start a service when device boots you can refer this answer.