android-broadcastreceiver

Runtime exception Android O with boot_completed

人走茶凉 提交于 2019-11-26 19:58:12
问题 I'm trying to start an IntentService within my BOOT_COMPLETED receiver, but in Android O (API 26) I get: java.lang.RuntimeException: java.lang.IllegalStateException: Not allowed to start service Intent { act=intent.action.update cmp=packageName.services.OwnService }: app is in background (Message is in one line, but this way it's easier readable) How can I do this the correct way? 回答1: Here are some options that I outlined in a blog post: Workaround #1: startForegroundService() Your

CONNECTIVITY_ACTION intent received twice when Wifi connected

依然范特西╮ 提交于 2019-11-26 10:10:09
问题 In my app I have a BroadcastReceiver that is launched as a component through a <receiver> tag, filtering android.net.conn.CONNECTIVITY_CHANGE intents. My goal is simply to know when a Wifi connection was established, so what I am doing in onReceive() is this: NetworkInfo networkInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); if(networkInfo.getType() == ConnectivityManager.TYPE_WIFI && networkInfo.isConnected()) { // Wifi is connected } It works fine, but I always