broadcastreceiver

Broadcast receiver - monitoring the Battery Level and Charging State

余生长醉 提交于 2019-12-30 04:57:22
问题 I am trying to make two toasts: one when the device is charging, and one when it`s not. But the receiver acting crazy, sending many toasts, and crashing the app. I can not find the problem. thnx! This is the receiver in Main activity: public class PowerConnectionReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); boolean isCharging = status == BatteryManager.BATTERY_STATUS

Set BroadcastReceiver to be inactive

那年仲夏 提交于 2019-12-29 08:08:58
问题 I have a BroadcastReceiver set up in my Android application that receives SMS receive events. This works fine, but I want to be able to toggle SMS receiving on and off by toggling the BroadcastReceiver on and off. Because if I have a simple boolean inside the onReceive method, even if the SMS receiving is off, my application will start. Is this possible to do? Cheers! 回答1: You can use PackageManager#setComponentEnabledSetting to enable/disable a component in your manifest file. You create a

Is there any reason to continue using IntentService for handling GCM messages?

瘦欲@ 提交于 2019-12-29 07:44:51
问题 As you know, recently Google changed their GCM documentation, and they claim that an IntentService is no longer required for handling arriving GCM messages. All the handling can be done in the BroadcastReceiver . When trying to figure out if there is any good reason to continue using the IntentService , I came across this quote: A Service (typically an IntentService) to which the WakefulBroadcastReceiver passes off the work of handling the GCM message, while ensuring that the device does not

Run service on incoming SMS in android Oreo

天涯浪子 提交于 2019-12-29 07:44:09
问题 I'm developing an app which needs to run some code (Networking) whenever an SMS is received. In API 25 and lower it's fine, I register an implicit receiver in Manifest file and start my service in the specified class which extended BroadcastReceiver . In API 26 however you cannot register android.provider.Telephony.SMS_RECEIVED in a receiver since it won't work. From Android documentation: Note: If your app targets API level 26 or higher, you cannot use the manifest to declare a receiver for

Restricting Android Broadcast Receiver from specific app

岁酱吖の 提交于 2019-12-29 04:26:07
问题 I have 2 applications. If I use service, I can set permission so only app1 can send intent to app2 : Define permission in app2 ( protection level: signature ), and use that permission in app1 . Service in app2 is protected by that permission. In this way, only app1 can send an intent to a service on app2 , and no other app (unless my signature is leaked) can send intent to service on app2 . Can I do the same with Broadcast Receiver? app1: sendBroadcast(intent, permission) app2: define

how to identify incoming call and outgoing call in android

寵の児 提交于 2019-12-29 04:20:07
问题 how to get the events of incoming call and outgoing call in android separately. Actually i was trying to develop an application that open on incoming call if number is exist in database and it work OK. but if i call from the device(outgoing call) and if number is exist in database still it open my application. i want to restrict to open my application on outgoing call. my manifest contain i receive incoming call like this: <receiver android:name=".IncomingCallReceiver" > <intent-filter >

Broadcast Receiver not working for SMS

风格不统一 提交于 2019-12-28 18:04:04
问题 First of all I already searched for possible solutions, tried everything and it still didn't work. I must be missing something. I am trying to create an app that receives/reads and writes SMS. the write part is working just fine, my broadcast receiver just doesn't catch broadcast. AndroidManifest.xml <uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.SEND_SMS" /> <uses-permission android:name="android.permission.WRITE_SMS" />

how can I notify a running activity from a broadcast receiver?

我只是一个虾纸丫 提交于 2019-12-28 09:56:31
问题 I have an activity, it needs to response to a broadcast event. Since an activity can not be a broadcast receiver at the same time, I made a broadcast receiver. My question is: how can I notify the activity from the broadcast receiver? I believe this is a common situation, so is there a design pattern for this? 回答1: The broadcast is the notification. :) If you want to say, start an activity or a service, etc., based on a received broadcast then you need a standalone broadcast receiver and you

how can I notify a running activity from a broadcast receiver?

为君一笑 提交于 2019-12-28 09:56:26
问题 I have an activity, it needs to response to a broadcast event. Since an activity can not be a broadcast receiver at the same time, I made a broadcast receiver. My question is: how can I notify the activity from the broadcast receiver? I believe this is a common situation, so is there a design pattern for this? 回答1: The broadcast is the notification. :) If you want to say, start an activity or a service, etc., based on a received broadcast then you need a standalone broadcast receiver and you

Dynamic BroadcastReceivers: LocalBroadcastManager.registerReceiver vs registerReceiver

ぐ巨炮叔叔 提交于 2019-12-28 07:05:12
问题 I'm trying to receive broadcasts from a service with 2 different receivers. One receiver update's a view so I register it in the activity's onResume method. When the app is not in the foreground I use the other receiver so I can show a system notification when the background service completes. The code below is how I'm registering my receivers: @Override protected void onPause() { // unregister local unregisterReceiver(localReceiver); // register remote registerReceiver(remoteReceiver, filter