broadcastreceiver

android communicate between activity and broadcast receiver

亡梦爱人 提交于 2019-12-01 20:10:44
问题 I have an activity which displays some data fetched from the server. If no connection is available, activity displays some cached data; if connection is available, activity fetches data and displays it. It all works as expected. Now, I would like to make my activity reload the data as soon as the connection occurs. I am using a simple Receiver that extends the BroadcastReceiver: public class ConnectionChangeReceiver extends BroadcastReceiver { @Override public void onReceive(Context context,

Android: BroadcastReceiver to restart killed/crashed app

試著忘記壹切 提交于 2019-12-01 19:26:55
I have an application and I would like to be able to restart it on the event of an error or a crash/app shutdown. I am familiar with how to register BroadcastReceivers , use alarms, etc. Is there any signal I could intercept that the app sends out when it shuts down? Or that the OS sends out when any app shuts down? Is there any signal I could intercept that the app sends out when it shuts down? Or that the > OS sends out when any app shuts down? No and no, AFAIK. 来源: https://stackoverflow.com/questions/3712245/android-broadcastreceiver-to-restart-killed-crashed-app

Broadcastreceiver to obtain ServiceState information

血红的双手。 提交于 2019-12-01 18:46:48
Does anyone know of a way to obtain the phone service state (IN_SERVICE, OUT_OF_SERVICE, EMERGENCY_ONLY, POWER_OFF) in android. I was hoping there would be a broadcastreciever to identify the changes, but I can't find anything. I know there's a listener but I'm not sure how I would use that from my app as it runs as a service using a WakefulIntentService (by thecommonsguy). With something like battery level (ie BATTERY_LOW, BATTERY_OKAY) it's quite easy, but I just can't work out a similar things for phone service changes. Register a receiver for public static final String ACTION_SERVICE_STATE

Android - Listening to NFC Adapter State Changed

微笑、不失礼 提交于 2019-12-01 18:44:36
I am trying to build an application which uses NFC. The goal is to display a DialogFragment containing a button link to go the settings and change it manually and when the feature is enabled, disable the DialogFragment. Problem: If the user enables/disables NFC using the icon in the pull down notifications tray , then the onPause/onResume doesn't get called and misses the condition entirely. I am sure there is a receiver that I can register to instead and respond appropriately in real time. Any ideas, thoughts or reference will be greatly appreciated! The following code checks if the state is

BroadcastReceiver for multipart SMS

a 夏天 提交于 2019-12-01 18:33:55
I need to store sms to a sqlite db when I receive one. At this moment it works fine with sms (160 chars), but if I receive a multipart sms it truncate the sms at about 155 chars. This is my code: SmsBR.java public class SmsBR extends BroadcastReceiver { private DBManager dbm; @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); if (bundle != null) { Object[] pdus = (Object[])bundle.get("pdus"); final SmsMessage[] messages = new SmsMessage[pdus.length]; for (int i = 0; i < pdus.length; i++) { messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]

android communicate between activity and broadcast receiver

 ̄綄美尐妖づ 提交于 2019-12-01 18:17:47
I have an activity which displays some data fetched from the server. If no connection is available, activity displays some cached data; if connection is available, activity fetches data and displays it. It all works as expected. Now, I would like to make my activity reload the data as soon as the connection occurs. I am using a simple Receiver that extends the BroadcastReceiver: public class ConnectionChangeReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { ConnectivityManager connectivityManager = (ConnectivityManager) context

how to use ACTION_PACKAGE_FIRST_LAUNCH intent-filter to start application?

杀马特。学长 韩版系。学妹 提交于 2019-12-01 18:13:11
问题 I am trying to use the intent-filter ACTION_PACKAGE_FIRST_LAUNCH to make the application do some tasks when it first launched, however it not being captured by the broadcast receiver my Manifest <receiver android:name=".reminder.ReminderActionReceiver" > <intent-filter> <action android:name="android.intent.action.PACKAGE_FIRST_LAUNCH" /> <action android:name="android.intent.action.PACKAGE_DATA_CLEARED" /> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> this my

BroadcastReceiver for multipart SMS

杀马特。学长 韩版系。学妹 提交于 2019-12-01 18:13:05
问题 I need to store sms to a sqlite db when I receive one. At this moment it works fine with sms (160 chars), but if I receive a multipart sms it truncate the sms at about 155 chars. This is my code: SmsBR.java public class SmsBR extends BroadcastReceiver { private DBManager dbm; @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); if (bundle != null) { Object[] pdus = (Object[])bundle.get("pdus"); final SmsMessage[] messages = new SmsMessage[pdus

How do I update my RecyclerView button state on click after alert dialog confirmation in activity/fragment?

爱⌒轻易说出口 提交于 2019-12-01 18:12:15
I have a pretty unique situation, where I have a button in a recyclerview, which upon click (initial state "register"), passes an intent to a broadcast receiver in fragment or activity where it throws an alert dialog , with 2 options, yes or no. If no is selected, nothing happens and the dialog dismisses, but if yes is clicked, it processes a function I defined in my presenter class (related to data) and is supposed to update my button ui state to "cancel". and same goes for the other way around where upon clicking cancel it will bring back alert, and clicking on yes will switch the ui text to

how to use ACTION_PACKAGE_FIRST_LAUNCH intent-filter to start application?

我是研究僧i 提交于 2019-12-01 18:00:16
I am trying to use the intent-filter ACTION_PACKAGE_FIRST_LAUNCH to make the application do some tasks when it first launched, however it not being captured by the broadcast receiver my Manifest <receiver android:name=".reminder.ReminderActionReceiver" > <intent-filter> <action android:name="android.intent.action.PACKAGE_FIRST_LAUNCH" /> <action android:name="android.intent.action.PACKAGE_DATA_CLEARED" /> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> this my broadcast receiver implementation this.context = context; String mAction = intent.getAction(); Log.i("r