android-broadcastreceiver

How register Broadcast Receiver for media button in Oreo?

白昼怎懂夜的黑 提交于 2019-12-07 03:16:28
问题 I have a problem with the new Android version, that is 8.0 (Oreo). I have to register a broadcast and I do this with this code: // android.intent.action.MEDIA_BUTTON IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON); r = new MediaButtonIntentReceiver(); // this line sets receiver priority filter.setPriority(999); registerReceiver(r, filter); This works on older Android version but on Android 8 this doesn't work because it is necessary register explicit broadcast but I don't

Lifetime of BroadcastReceiver with regard to Android O changes

≯℡__Kan透↙ 提交于 2019-12-06 23:19:09
问题 If I declare a BroadcastReceiver via the mainfest file for a system broadcast (let's say for example ACTION_POWER_DISCONNECTED ) the the system will call it every time the specific broadcast is send so the lifetime of the BroadcastReceiver is unrestricted. But there are also broadcasts which can not be registered via the manifest file. For these broadcasts we have to call context.registerReceiver with a corresponding IntentFilter . Let's say I create a BroadcastReceiver for BOOT_COMPLETED and

Broadcasts are delayed

纵饮孤独 提交于 2019-12-06 19:56:51
问题 We use broadcasts to communicate state changes between a remote services and our UI. Doing this, we discovered a very strange behaviour: Sometimes (I can not find any clues why) these broadcasts are delayed around 8s. How we send them (pretty basic, mState is just a enum) (Remote process in service): Intent intent = new Intent(); intent.setAction(ACTION_STATE_CHANGED); intent.putExtra(EXTRA_STATE, mState); Service.get().sendBroadcast(intent, null); How the static receiver is registered (App):

How to receive USB connection status broadcast?

烂漫一生 提交于 2019-12-06 04:36:34
问题 I am trying to detect USB connection in my app, that is, whether or not USB is connected to device. It's being tested on Marshmallow 6.0.1 (sdk23) But I'm unable to receive the broadcast actions ACTION_USB_DEVICE_ATTACHED or ACTION_USB_DEVICE_DETACHED.. I tried using both the dynamic way and the AndroidManifest.xml way, neither worked.. Here's my code: AndroidManifest.xml : <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com

Manifest-declared BroadcastReceiver not picking up explicit broadcast when app is not running

戏子无情 提交于 2019-12-06 03:32:55
I am trying to get two apps to communicate via broadcasts. The first app sends a broadcast using code like the following: Intent outIntent = new Intent("org.example.WHATEVER"); PackageManager pm = this.getPackageManager(); List<ResolveInfo> receivers = pm.queryBroadcastReceivers(outIntent, 0); if (receivers != null) for (ResolveInfo receiver : receivers) { Log.d("Sender", String.format("Polling %s", receiver.activityInfo.packageName)); outIntent = new Intent("org.example.WHATEVER"); outIntent.setPackage(receiver.activityInfo.packageName); sendBroadcast(outIntent); } The receiving end registers

Is it possible to call onReceive method from a dialog?

你。 提交于 2019-12-06 02:10:48
I have a custom dialog with editText and save button . When button clicked, I want it call MyReceiver . But the log and Toast in MyReceiver never get displayed. Reminder final AlertDialog.Builder builder = new AlertDialog.Builder(this); LayoutInflater inflater = LayoutInflater.from(this); View promptView = getLayoutInflater().inflate(R.layout.dialog_with_edittext, null); Button save = (Button) promptView.findViewById(R.id.okBtn); final EditText task = (EditText) promptView.findViewById(R.id.task); time = (EditText) promptView.findViewById(R.id.time); date = (EditText) promptView.findViewById(R

Android BroadcastReceiver onReceive() called twice on android 5.1.1 even after one register

北战南征 提交于 2019-12-05 15:12:52
I Could not figure out what is wrong with below code. I also checked about registering receiver twice. But that's also not the case. or may be I am missing something. Could any please help. I really need it. :( import android.app.Service; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.os.IBinder; import android.telephony.TelephonyManager; import android.util.Log; import android.widget.Toast; /** * * @author Bharat * */ public class CallNotifierService extends

Why LocalBroadcastManager is not working in service?

99封情书 提交于 2019-12-05 13:06:11
I used Service and i am not recieving any broadcasted message. Need quick response. This is the intent filter string i used. public class AppConstant { public static final String FILTER = "com.sample.hmi.REQUEST_PROCESSED" ..... } My service look like this public class MyService extends Service { ..... { ..... broadcastResponse(true);//bradcastcall .... } private void broadcastResponse(boolean isTrue) { Intent intent = new Intent(AppConstant.FILTER); intent.putExtra(AppConstant.COMMAND, AppConstant.HMI_BUTTON_RESPONSE); intent.putExtra(AppConstant.DATA_IS_TRUE, isTrue); LocalBroadcastManager

Alarm Manager not working at specific given time interval

寵の児 提交于 2019-12-05 08:28:15
Hi I am using alarm Manager for specific time interval for 3 minutes and I started monitoring. It worked for sometimes and suddenly I noticed there is irregular time interval which is not correct! You can see in attached log where at "20-Jul-2016 12:22:03 pm" time varies! I connected the phone and turned off the screen and monitored! where for every 3 minutes, i hit the server and gets the response as 1. But at one time, it takes 5 minutes to hit the server! Why this strange issue happened? Here is code. public void startAt3() { Intent alarmIntent = new Intent(ActivityTracking.this,

How register Broadcast Receiver for media button in Oreo?

夙愿已清 提交于 2019-12-05 07:42:04
I have a problem with the new Android version, that is 8.0 (Oreo). I have to register a broadcast and I do this with this code: // android.intent.action.MEDIA_BUTTON IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON); r = new MediaButtonIntentReceiver(); // this line sets receiver priority filter.setPriority(999); registerReceiver(r, filter); This works on older Android version but on Android 8 this doesn't work because it is necessary register explicit broadcast but I don't know how. How can I register explicit broadcast to detect media button? This is in Manifest.xml: