broadcastreceiver

Can't register receiver dynamically

安稳与你 提交于 2019-12-01 01:06:47
问题 Can't register receiver dynamically at boot. I have no activity. And I do not want to register it in the service. Boot Receiver where I register another receiver: package zzz.zzz.zzz; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; public class AutoStart extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if ((intent.getAction() != null) && (intent.getAction(

how to get broadcast for screen lock in android

让人想犯罪 __ 提交于 2019-12-01 00:44:55
How to get trigger that screen is locked or on in android?? i tried using SCREEN_OFF & SCREEN_ON action in broadcast receiver but it's not working. public void onReceive(Context context, Intent intent) { Log.d("XYZ", "Screen ON/OFF"); Toast.makeText(context, "screen",10000).show(); if(intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { ....... } } in activity i have registered broadcast like- screen is object of my broadcast receiver IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); mContext.registerReceiver(screen, filter); Call the

Android - launch app from broadcast receiver

微笑、不失礼 提交于 2019-12-01 00:09:39
问题 I want the broadcast receiver to launch my app this way: If the app is not in the foreground or background, launch it as if it is launched from launcher. If the app is in the background, bring it to the foreground with the state it was last in. If the app is in the foreground, do nothing. Here is my code: @Override public void onReceive(Context context, Intent intent) { Intent launch_intent = new Intent("android.intent.action.MAIN"); launch_intent.setComponent(new ComponentName("com.example

Registering BOOT_COMPLETED receiver in Android 8

时光毁灭记忆、已成空白 提交于 2019-11-30 22:52:41
问题 We are about to update our App Android API 26. In the documentation about Broadcast receiver it says that Apps that target Android 8.0 or higher can no longer register broadcast receivers for implicit broadcasts in their manifest Implicit broadcast receivers are described as a broadcast that does not target that app specifically. For example, ACTION_PACKAGE_REPLACED So I assume that android.intent.action.BOOT_COMPLETED is considered an implicit receiver. Further it states that implicit

Receiving broadcast from notification on Android Oreo

戏子无情 提交于 2019-11-30 22:49:37
问题 I have a custom button in a sticky notification. I used to attach a PendingIntent to it for receiving button clicks: Intent intent = new Intent(); intent.setAction("com.example.app.intent.action.BUTTON_CLICK"); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 2000, intent, PendingIntent.FLAG_UPDATE_CURRENT); contentViewExpanded.setOnClickPendingIntent(R.id.button, pendingIntent); When i run this code on Oreo , i get BroadcastQueue: Background execution not allowed in logcat

BroadcastReceiver not working after BOOT_COMPLETED

隐身守侯 提交于 2019-11-30 22:38:13
问题 I'm trying to intercept incoming SMS right after boot_completed but i'm having a problem with a NullPointerException in this line: Object[] rawMsgs=(Object[])intent.getExtras().get("pdus"); Here's my manifest: <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.RECEIVE_BOOT_COMPLETED"></uses- permission> <uses-permission android:name=

Emulate a broadcast in Android

萝らか妹 提交于 2019-11-30 22:04:30
I need to know how to emulate a broadcastreceiver . I have the following code, but I have no clue how to actually see when it is receiving a broadcast. public class LocationBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Bundle b = intent.getExtras(); Location loc = (Location)b.get(android.location.LocationManager.KEY_LOCATION_CHANGED); Toast.makeText(context, loc.toString(), Toast.LENGTH_SHORT).show(); Log.d("com.dennis.test","LOCATION: " + loc.toString()); } } In my manifest I have the following: <receiver android:name="com

Android keep BroadcastReceiver in background

南楼画角 提交于 2019-11-30 22:00:17
I created a BroadcastReceiver and it runs only when my app shown in recent apps menu. If I remove my app from the recent apps the BroadcastReceiver will stop working. How can I keep the BroadcastReceiver in background? I register the BroadcastReceiver from my main activity (in OnCreate()). IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); registerReceiver(receiver, intentFilter); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { } }; This is not how you should register a receiver. You receiver

Boot/ScreenOn Broadcast Receiver not working

只谈情不闲聊 提交于 2019-11-30 21:56:41
I have a blank HelloWorld Application: package tutorials.TestReceivers; import android.app.Activity; import android.os.Bundle; public class TestReceiversActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } With this BootReceiver.Java: package tutorials.TestReceivers; import android.content.BroadcastReceiver; public class BootReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent arg1) { Intent intent = new Intent

How can I discover that my device has rebooted, given that HONEYCOMB BOOT COMPLETED is no longer supported?

大憨熊 提交于 2019-11-30 21:15:36
问题 I am developing app in Android 4.0.3. I've read that the HONEYCOMB BOOT COMPLETED event is no longer supported, according to Google's documentation. Given this, how can I discover that my device has rebooted? CODE - Java Class :- public class MyStartupIntentReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { Logger.i("Device", "REBOOT"); Logger.i("Device", "REBOOT"); Logger.i("Device", "REBOOT"); Logger.i("Device", "REBOOT"); Logger.i("Device"