My broadcast receiver triggered by event BOOT_COMPLETED and works fine on many devices except Nomi C10103.
The message appears in the log on the device:
D/ActivityManager: send broadcast: android.intent.action.BOOT_COMPLETED, skip package: com.example.myPackageName
Sending message am broadcast -a android.intent.action.BOOT_COMPLETED com.example.myPackageName from adb shell also does not run the application.
Manifest code:
<receiver
android:name=".AutoRunReceiver">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter android:priority="1000">
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
AutorunReceiver.java:
public class AutoRunReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
//приёмник автозагрузки
if (intent != null && intent.getAction() != null) {
final String msg="intent:"+intent+" action:"+intent.getAction();
Log.d("myLogs",msg);
Toast.makeText(context,msg,Toast.LENGTH_LONG).show();
}
}
}
I realized that the problem is not in the code, but the device itself. Autoplay not working on my tablet for any application. As a workaround I have used the event "android.intent.action.USER_PRESENT", which is triggered after the device loading and screen unlocking.
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
its working fine for me.if its lenovo mobile you should wait at least 2 minutes then it will open automatically.
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>
My implementation of BootBroadcastReceiver
Permission taken in manifest :<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Intent filter in manifest for BootBroadcastReceiver :
<receiver android:name=".receivers.BootBroadcastReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE"/>
</intent-filter>
</receiver>
The additional actions are result of some threads read online.
Below is implementation class :
public class BootBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Application boot event");
Toast.makeText(context, "Boot completed", Toast.LENGTH_SHORT).show();
}
}
But somehow on reboot or power on I am not able to get this boot complete I added the toast also. No toast shown.
Also some people suggested make application install on internal memory only because the boot complete broadcast is not delivered to apps on external storage. By setting flag in manifest android:installLocation="internalOnly" I also did this but not worked for me. What might be wrong ?
Devices used for testing :
Moto E3 power (Android 6.0 ), Lenovo A6020a40 ( Android 5.1.1)
use this code
public class BootBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Log.d("startuptest", "StartUpBootReceiver BOOT_COMPLETED");
Toast.makeText(context, "Boot completed", Toast.LENGTH_SHORT).show();
}
}
}
also define in manifest file receiver like this
<receiver android:name="com.example.startuptest.StartUpBootReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
I have an activity that starts when a specific USB device is attached, as specified in a device filter file, which works great:
<activity
android:name="com.mycompany.DerpApp.MainActivity"
android:launchMode="singleTask"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="#xml/device_filter" />
</activity>
I also have a service where I want to monitor for connect and disconnect. I have BroadcastReceivers wired up, and they fire upon device attach and detach. However, I want these broadcast receivers to trigger when only a device as specified in my device_filter.xml is attached/detached.
m_usbDisconnectReceiver = new UsbDisconnectReceiver();
registerReceiver(m_usbDisconnectReceiver, new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED));
m_usbConnectReceiver = new UsbConnectReceiver();
registerReceiver(m_usbConnectReceiver, new IntentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED));
I am unsure of how to attach my device_filter file to the programatically created Broadcast Receiver. Is there something I can do in the IntentFilter for this? I think that the Intent that is provided to the onReceive() has a UsbDevice as one of its extras, but it would be best if I could filter it out so the event doesn't fire. And if that's not possible, how can I check to see if the UsbDevice is a part of my device_filter?
If you absolutely have to create your BroadcastReceiver programatically, then you need to filter the devices programatically as well.
Try this:
public void onReceive(Context context, Intent intent)
{
if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED))
{
UsbDevice d = (UsbDevice)
intent.getExtras().get(UsbManager.EXTRA_DEVICE);
if (d.getVendorId() == MY_VENDOR_ID && d.getDeviceId() == MY_DEVICE_ID)
{
// Your code here
}
}
}
I am developing an app which needs a broadcast when app opens every time. I had registered the receiver in manifest like this.
<receiver android:name="package.broadcast.example" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_RESTARTED" />
<data android:scheme="package"/>
</intent-filter>
</receiver>
But i cant able to receive the broadcast. I spent 3 hours on this still i cant find wats the mistake. Can anyone refer me the working example of this broadcast. Thanks.
Restarted Application/Package does not receive broadcast...
check the following link for details
you can check this link
http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_RESTARTED
do u have the following code which extends BroadcastReceiver, if not than try the following code:
public class AutoConnection extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if ((intent.getAction() != null)
&& (intent.getAction()
.equals("android.intent.action.PACKAGE_RESTARTED"))) {
Toast.makeText(context, "Pacakge Restarted",
Toast.LENGTH_LONG).show();
}
}
}
and in android manifest file add the following code:
<receiver android:name=".AutoConnection" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_RESTARTED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
How can I make my application to get started while my phone boots up itself.
You need to use a BroadcastReceiver with android.intent.action.BOOT_COMPLETED intent.
Add following to your manifest file:
<receiver android:name="MyApp_Receiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
MyApp_Receiver class implementing BoradcastReciever. Implement the onReceive() method and start your favorite activity from your app.
public void onReceive(Context context, Intent intent) {
// make sure you receive "BOOT_COMPLETED"
if ((intent.getAction() != null) && (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")))
{
// Start the service or activity
}
}