broadcastreceiver

Android - Network State broadcast receiver does not receive intent

旧城冷巷雨未停 提交于 2019-12-06 05:50:45
问题 I have a broadcast receiver that needs to listen to network changes - BroadcastReceiver networkStateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); if(!noConnectivity) { //some stuff } } }; I register it using - public void startListening() { IntentFilter filter = new IntentFilter(); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);

Block SMS in android

情到浓时终转凉″ 提交于 2019-12-06 05:37:13
i developing an application where i want to block SMS of some specific numbers.For testing i do SMS from that number that i have in IF CONDITION but this code is not blocking that number SMS. i try best but did't resolved. any one help me.Here is my code Sms.java public class Sms extends BroadcastReceiver { final SmsManager sms = SmsManager.getDefault(); @Override public void onReceive(Context context, Intent intent) { // Retrieves a map of extended data from the intent. final Bundle bundle = intent.getExtras(); try { if (bundle != null) { final Object[] pdusObj = (Object[]) bundle.get("pdus")

Check if background restriction data is enabled or not?

﹥>﹥吖頭↗ 提交于 2019-12-06 05:03:34
问题 I have a service which is running on the main thread not in the background. In the service I'm checking net connection via broadcastreciver. When I enable restriction data enabled in Settings, broadcastreciver is catching intent well, but internet connection(Mobile data) is disabled to my app although it has on my device. I've seen this question, and android docs. intentFilter.addAction("android.net.conn.ACTION_BACKGROUND_DATA_SETTING_CHANGED"); intentFilter.addAction("android.net.conn

Dynamically registering a broadcast receiver [duplicate]

跟風遠走 提交于 2019-12-06 04:46:51
问题 This question already has an answer here : BroadcastReceiver as inner class (1 answer) Closed 2 years ago . I registered my broadcast receiver like this(given below) in the manifest file. its working fine. <receiver android:name="MyIntentReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.HOME" /> </intent-filter> </receiver> But it stays registered through out. Ie whenever the phone is booting my

preventing a crash when someone mounts an Android SD card

杀马特。学长 韩版系。学妹 提交于 2019-12-06 04:37:37
问题 I have a file open on the SD card. When someone mounts the SD card, it winds up crashing my application. I am trying to register for the ACTION_MEDIA_EJECT broadcast event, and i receive that, but it seems like i'm getting that too late. By the time I get that, it's already crashed my application. Is there any way to get notified before crashing my application? Added some very simple sample code. When I do this, it winds up crashing the service when I turn on USB (MSC mode). Test.java /**

Trying to have a Broadcast Receiver with No filter

时光总嘲笑我的痴心妄想 提交于 2019-12-06 04:23:03
问题 IntentFilter intentFilter = new IntentFilter("test"); registerReceiver(mReceiver, intentFilter); I would like to have no filter like registerReceiver(mReceiver, null) but my app crashes as a result of that. Can I have new IntentFiler() as an empty filer? 回答1: Because the BroadcastReceiver returns null when there is no match via the criteria from the IntentFilter , it is not possible with the API to accomplish what you hope to accomplish (which I'm assuming is sending any and all Broadcasts to

Android: Is there a way to stop AlarmReceiver fired in BootReceiver

前提是你 提交于 2019-12-06 04:12:23
I am using a Boot receiver to fire AlarmManager,so that it repeats it's task every minute. I'd like the user to have in app option to enable/disable action that is done in every repeat of AlarmManager. So far I only used only a lame solution. I set user's preference in SharedPreferences and in every repeat of AlarmManager I check for user's preference in SharedPreferences and based on this preference the functionality is either executed or ignored. So far to my best knowledge, there is no way to completely destroy AlarmManager from within itself. but I might be wrong. Also, since boot receiver

How to create BroadcastReceiver without Activity

旧时模样 提交于 2019-12-06 03:55:58
问题 I would like to create a application that would respond to receiving SMS messages and display a dialog. How can I register the receiver in the manifest without defining within an activity? I tried to keep the receiver/intent-filter tags in the manifest out of the activity tag but the emulator will not install the apk since there is no launch activity. Keeping the BroadcastReceiver as the main activity results in an "Unable to instantiate activity" error in the Logcat. Any help? Thanks, Sunny

best practice where to register broadcast receiver?

雨燕双飞 提交于 2019-12-06 03:53:50
quick opinion question on where its 'best' to register a receiver? In my case my service sends a broadcast each time the UI needs updating. Options as i understand them . Manifest . Oncreate . Onstart . Onresume With the corresponding unregister of course. I think for a UI update scenario makes sense to put in onresume and onpause... your thoughts? If the receiver is only to receive events that would cause you to update the GUI then there are two options. Register to receive them in OnResume and unregister in OnPause if you want it to only update when the activity is in the foreground. OR

Some devices does not receive GCM push eventhough all messages succeed from server

感情迁移 提交于 2019-12-06 03:28:06
We're developing an application that uses GCM. It works fine on most phones, however, we have two phones (galaxy note 2 and galaxy s plus) which does not receive the messages. Or maybe it's just the broadcast receiver not being called. Server side push: $data = array( 'data' => array('message' => $messageData), 'delay_while_idle' => false, 'type' => 'New', 'flag' => 1, 'registration_ids' => $registrationIdsArray ); $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send"); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,