I'm rebooting the phone and I expect a log message. I've registered the BroadcastReceiver in Androidmanifest, but no message is being received. What am I Missing?
androidmanifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Receives an event when the device has completed a reboot -->
<receiver
android:name=".BootReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.BOOT" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
BootReceiver:
class BootReceiver : BroadcastReceiver() {
override fun onReceive(p0: Context, p1: Intent) {
Log.i("BootReceiver", "Boot event received")
}
}
When I filter in the logging for "boot" I see several other apps logging the event, but not my own App:
I/NU.LockBootCompleteReceiver: onReceive : Intent { act=android.intent.action.LOCKED_BOOT_COMPLETED flg=0x89000010 cmp=com.samsung.android.app.telephonyui/.netsettings.ui.receiver.LockBootCompleteReceiver (has extras) }
I/BCL#CoreSvc: (CoreServiceComponentEnabler) updateComponent() : class com.samsung.android.bixby.receiver.token.BootCompleteReceiver | 2
I/BCL#CoreSvc: (CoreServiceComponentEnabler) updateComponent() : class com.samsung.android.bixby.receiver.token.LazyBootCompleteReceiver | 1
I/CIDManager: [onReceive(BootReceiver.java:20)] onReceive: android.intent.action.LOCKED_BOOT_COMPLETED
I/ActivityManager: Start proc 7201:com.samsung.android.game.gametools/u0a79 for broadcast {com.samsung.android.game.gametools/com.samsung.android.game.gametools.floatingui.receiver.GameBoosterBootCompleteReceiver}
I/GameTools: BootCompleteReceiver already enabled.
I/GameTools: GameBoosterBootCompleteReceiver: onReceive: Intent.ACTION_LOCKED_BOOT_COMPLETED
I/GameTools: GameBoosterBootCompleteReceiver: clear runtime settings on boot complete.
I/GameTools: GameBoosterBootCompleteReceiver: register Intent.ACTION_USER_UNLOCKED
I/GameTools: GameBoosterBootCompleteReceiver: register Intent.ACTION_USER_UNLOCKED via EventDelegationManager
I/ORC/FbeBootReceiver: onReceive : android.intent.action.LOCKED_BOOT_COMPLETED
I/ORC/FbeBootReceiver: FBE islocked : true
I/CS/MsgFMMReceiverService: PCW LOCK. handlePCWLockMessage. LockedBootComplete : true
I/CS/xmsFbeJobService: onLockedBootCompleted()
I/ORC/FbeMigrationJobService: onLockedBootCompleted()
I/StateUtils: isDirectBootMode On : true
I/PackageManager: !#Start postBootUpdate
I/PackageManager: !#Finish postBootUpdate dexopted: 3
Remove:
<category android:name="android.intent.category.DEFAULT"/>
Categories are normally only used on activities, not broadcasts.
The code above is working fine.
I have checked on device ->
google pixel 4a, os 12
mi a1, os 11
i am able to see logs every time i reboot my device.
Try changing your device and test.
check the manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.MyApplication">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".BootReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.BOOT" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
</application>
</manifest>
Related
I am trying to code a service that started when device booted.
java.lang.RuntimeException: Unable to start receiver packagename.BootReciever: android.content.ActivityNotFoundException: Unable to find explicit activity class {packagename/packagename.MainActivity$Companion}; have you declared this activity in your AndroidManifest.xml?
In my manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="packagename">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INJECT_EVENTS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.Translucent"
android:fullBackupContent="#xml/backup_descriptor">
<activity android:name="packagename.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="packagename.RemoteService">
<intent-filter>
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
</intent-filter>
</service>
<receiver android:name="packagename.BootReciever"
android:enabled="true"
android:exported="true">
<intent-filter android:directBootAware="true">
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.REBOOT"/>
</intent-filter>
</receiver>
</application>
</manifest>
When i open app, it will work well, however i want to launch application when boot completed. I push it into system/app and it crushes.
override fun onReceive(p0: Context?, p1: Intent?) {
if(p1?.action.equals("android.intent.action.BOOT_COMPLETED")){
Log.e("Ahmet ","START PLSSSSSSSSSSSSS")
val startIntent = Intent(p0,MainActivity.javaClass)
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
p0?.startActivity(startIntent)
}
}
}
MainActivity
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
appContext = applicationContext
ServiceModul.startServices(this)
finish()
}
companion object {
lateinit var appContext: Context
}
}
I signed the application, it has permissions, however on boot, it could not find MainActivity. I check package names like 3-4 times. What should i do?
I've installed a broadcast receiver a few weeks ago in Java, now I want to do it in Kotlin, but unfortunately it does not work.
My Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.test"
android:installLocation="internalOnly">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.test.test.BootReceiver"
android:enabled="true"
android:exported="true"
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
</application>
</manifest>
My receiver:
package com.test.test
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.Intent.ACTION_BOOT_COMPLETED
import android.util.Log
class BootReceiver : BroadcastReceiver() {
override fun onReceive(c: Context, intent: Intent?) {
val action = intent?.action
Log.d("ASD123123", "RECEIVED BOOT")
val b = intent?.toUri(Intent.URI_INTENT_SCHEME)
when (action) {
ACTION_BOOT_COMPLETED -> startWork(c)
}
}
private fun startWork(context: Context) {
Log.d("Test", "Test")
}
}
When I reboot my device (Android 8.0.0) it does not start the service. Neither does it when I run
adb shell
am broadcast -a android.intent.action.BOOT_COMPLETED
With
am broadcast -a android.intent.action.BOOT_COMPLETED -n com.test.test/.Bootreceiver
it works though. What is wrong with my code?
BOOT_COMPLETED broadcast receiver has been deprecated and no longer works.
<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" /> // add this line
</intent-filter>
And in Broadcast receiver :
private fun startWork(context: Context) {
Log.d("Test", "Test") // remove this and toast
Toast(context,"Test", Toast.LENGTH_SHORT).show()
}
I am trying to send push notification(FCM) to my android app using this link.Everthying works fine when the app is in background but once i kill the app then i dont receive any notofication.I use Lenovo Tab with Android 7.1 OS.I also tried signing the app and installing as APK.Below is my gradle file and logcat output :-
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name"
android:value="YOUR NOTIFICATION CHANNEL NAME"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description"
android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color"
android:resource="#android:color/white"/>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.liappmanager" />
</intent-filter>
</receiver>
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name=".FirebaseIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
</application>
logcat output :-
03-02 12:00:15.673 1489 1536 W BroadcastQueue: Unable to launch app
com.liappmanager/10279 for broadcast Intent {
act=com.google.android.c2dm.intent.RECEIVE flg=0x10000010
pkg=com.liappmanager (has extras) }: process is not granted
03-02 12:00:15.676 2369 2369 W GCM : broadcast intent callback:
result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE
flg=0x10000000 pkg=com.liappmanager (has extras) }
As you can see from logcat i understood the permission is not granted but i added the permission in gradle file.Am i still missing something regarding permission.
[SOLVED]:Finally i solved it if your using Lenovo Just go to Settings->Battery Optimization -> All apps -> {YOUR APP} -> Don't Optimize(Check it) that's it this(restart the device), will solve the problem for further reference check this .
I really do not know what is wrong, but my if widget is update by system by "APPWIDGET_UPDATE" it throws following exception. I tried several things, exporting receiver (true/false), I tried it on emulators and real phones, but it is same. I added several intent-filters, but it did not work.
11-06 20:10:10.279: W/ActivityManager(61): Permission denied: checkComponentPermission() reqUid=1000
11-06 20:10:10.279: W/ActivityManager(61): Permission Denial: broadcasting Intent { act=android.appwidget.action.APPWIDGET_UPDATE (has extras) } from com.ency.easychange (pid=1196, uid=10034) requires null due to receiver com.android.settings/com.android.settings.widget.SettingsAppWidgetProvider
My AppWidgetProvider is only declared, because I tried to eliminate possibilities, but the exception is throw before ExchangeRateWidgetProvider.onReceive() is called.
public class ExchangeRateWidgetProvider extends AppWidgetProvider {
public static final String tag = "ExchangeRateWidgetProvider";
#Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
}
}
My Manifest:
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<!-- TODO: Remove, only for traces -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="#drawable/ic_launcher_main"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".EasyChange"
android:label="#string/title_activity_easy_change" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".ExchangeRateWidgetService"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
</intent-filter>
</service>
<receiver
android:name=".ExchangeRateWidgetProvider"
android:label="#string/exchange_rate_widget_name"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/exchange_rate_widget_providerinfo" />
</receiver>
<activity
android:name=".WidgetConfigSmall"
android:label="#string/title_activity_widget_config_small"
android:theme="#android:style/Theme.Holo.Dialog"
android:excludeFromRecents="true"
android:exported="true" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
</activity>
</application>
I appreciate if you can take a look ...
Your problem lies somewhere in your Java code, where you are attempting to send the android.appwidget.action.APPWIDGET_UPDATE broadcast. That is to be broadcast by the OS, not by apps, and that is what the Permission Denial is about.
Manifest:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".AlarmActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<receiver android:name="CallReciver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE">
</action>
</intent-filter>
</receiver>
<receiver android:name=".SmsReceiver">
<intent-filter android:priority="1000">
<action android:name=
"android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<receiver android:name=".OnBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:enabled="true"
android:name=".AlarmService">
</service>
</application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED">
</uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE">
</uses-permission>
<uses-permission android:name="android.permission.WRITE_SMS">
</uses-permission>
<uses-permission android:name="android.permission.READ_SMS">
</uses-permission>
<uses-permission android:name="android.permission.SEND_SMS">
</uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS">
</uses-permission>
<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
Receiver:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class OnBootReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
Log.d("Test","booot");
Toast.makeText(context, "Test", Toast.LENGTH_LONG).show();
}
}
Receiver doesn't work. I turn off and on my device and nothing happens.
SMS And Call Receiver in this project work good.
SMS Receiver and CallReceviver - works good.
First post updated - added full manifest.
If you have HTC device you also need to register for "android.intent.action.QUICKBOOT_POWERON". So the entry in manifest should be:
<receiver android:name=".OnBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
On my HTC, if I turn off the device and turn it on for a while I got QUICKBOOT_POWERON and no BOOT_COMPLETED.
If I turn off the device and remove the battery for a while - I got BOOT_COMPLETED after start.
Put permission
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
Also know that in Android >= 3.1 the app gets installed in 'stopped' state and will not get boot and shutdown events until the user 'does something' with the app at least once. See this post on the topic.
Try this::
<receiver android:enabled="true" android:exported="true"
android:name=".OnBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Cheers...!!!