android-broadcast

Access to application class in Broadcast Receiver

眉间皱痕 提交于 2019-11-29 18:50:14
问题 I want to check internet connection in Broadcast Receiver; And set result (A boolean flag) to a global variable, to use it on whole application, in if conditions; That if internet is disconnected, set a status imageview in main activity, to red image, and if connected, set it to green. I followed this topic. But there is no getApplication() in Broadcast Receiver; And iI should use getApplicationContext() instead. On another side, this topic: when writing code in a broadcast receiver, which is

Why SMS Retriever API don't work in release mode?

隐身守侯 提交于 2019-11-29 18:15:14
问题 I've implemented the SMS Retriever API like in the google tutorials and in my debug Build Variant work fine. I can read the sms and get the code to the user can do the login. My problem is when I run the app in release Build Variant the sms it doesn't work. I receive the sms but I can't read the code to do the login. I change the hash generated with AppSignatureHelper in release mode that is differente than in the debug mode. In debug work and in release no. Some help will be appreciate The

Android Wifi Scan - BroadcastReceiver for SCAN_RESULTS_AVAILABLE_ACTION not getting called

萝らか妹 提交于 2019-11-29 15:20:59
问题 Here is my code: public class FloatWifiManager implements IWifiManager { private WifiManager wifiManager; private BroadcastReceiver wifiScanReceiver; public FloatWifiManager(Context context) { ... wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); // Registering Wifi Receiver wifiScanReceiver = new BroadcastReceiver() { @Override public void onReceive(Context c, Intent intent) { if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { // not getting

Volume change Listener: Is registerMediaButtonEventReceiver preferable to onKeyDown?

和自甴很熟 提交于 2019-11-29 14:28:59
问题 Looking for a "most comprehensive & compatible (i.e. all Android versions...)" way to listen to volume changes, I found 2 different approaches to handle this: registerMediaButtonEventReceiver onKeyDown + SettingsContentObserver Which method is preferable? And why? UPDATE 1: Thanks to the comment below, I discovered that onKeyDown() actually takes over the volume key, which may not be a complete solution as one of the posts mentioned that volume could be changed via interfaces other than the

Communicate between different instances of same fragment

情到浓时终转凉″ 提交于 2019-11-29 13:54:25
The problem as follows. Let us have 3 tabs with fragments: Tab 1 (Fragment A). Needs to send data to Tab 2. Tab 2 (Fragment B). Needs to receive data from Tab 1. Tab 3 (Fragment B). Already contains data. As you see Tab 3 and Tab 2 contain the same Fragment but different instances. How do I send data (not via arguments) to exactly Tab 2? What I've tried: Set the unique ID for Fragment B via arguments when they were created. Register same Local Broadcast Receiver for both instances of Fragment B Send data from Fragment A to Fragment B with its ID In Fragment B onReceive() check if recevied ID

BroadcastReceiver not working when app is not running

▼魔方 西西 提交于 2019-11-29 13:53:12
In my manifest file I have declared the receiver. (as follows) <receiver android:name=".OnAlarmReceive" /> however, once I shut down my application, I am not able to get the alarms and the notifications. Apparently, a call to the OnReceive in my Broadcast receiver is never made. public class OnAlarmReceive extends BroadcastReceiver { @Override public void onReceive(Context context, Intent arg1) { //various stuff } } Inside the MainActivity, my alarm manager class is as the follows. AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); Intent intent = new Intent("MY_ALARM

How to send a custom broadcast action to receivers in manifest?

假装没事ソ 提交于 2019-11-29 13:37:36
问题 MyReceiver.java public class MyReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, final Intent intent) { Log.i("MyReceiver", "MyAction received!"); } } In AndroidManifest.xml (under the application tag) <receiver android:name=".MyReceiver"> <intent-filter> <action android:name="MyAction" /> </intent-filter> </receiver> MainActivity.Java public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) {

How to detected if application is closed

穿精又带淫゛_ 提交于 2019-11-29 08:40:59
I have an app that receives from the Broadcastreceiver to fetch new data from the web(json), when my app is running while it fetches; everything runs well, when the app is closed it crashes "Your app stopped working". Even the following good to check if my app is in the foreground doesn't work. i want it so if the app is closed, not running, to call an intent to open the app for it not to crash, so how do I check if application is closed? My code; public class UpdateReceiver extends BroadcastReceiver { private static long alarmTime = 0; @Override public void onReceive(Context context, Intent

android.intent.action.BOOT_COMPLETED Intent is not received at “Restart” or “Reboot”

狂风中的少年 提交于 2019-11-29 08:09:26
问题 Android android.intent.action.BOOT_COMPLETED Intent is not received if I use the "Restart" or "Reboot" , but works if I turn off and on the device. Is there Any way to make this work? 回答1: Add <action android:name="android.intent.action.QUICKBOOT_POWERON" /> also 回答2: Kindly add the below Permission: <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> and add the Receiver Class entry in manifest.zml: <receiver android:name="com.example.receivers.BootReceiver" > Now

Abort SMS Intent on Android KitKat

懵懂的女人 提交于 2019-11-29 06:36:16
I'm currently developing an application that needs to deal with SMS only if it is an SMS expected by the application (same behaviour as Whatsapp on registration). I would like to abort the SMS Intent as it is not expected to appear in the SMS box. My question is : I know that Google changed a lot about SMS behaviour in KitKat, and now, even if my SMS is well parsed by my application, the SMS also appear in SMSBox, even if I call this.abortBroadcast(); in my SMS broadcast receiver. So is there a way to avoid those SMS appearing in SMS box without having to develop a complete SMS application ?