broadcastreceiver

Android - How to trigger a Broadcast Receiver to call its onReceive() method?

做~自己de王妃 提交于 2019-12-03 22:55:49
I have scheduled alarm for my application. I have implemented broadcast receiver to be triggered once the alarm time reaches. How to manually call broadcast receiver to execute the code inside of onReceive method without replicating the code twice. I thought of having the code in utility singleton call and call that method by having util class instance from anywhere. But is that any other way to call that onReceive method directly or else broadcast intent problematically. android:exported="false" //Additional parameter of receiver when defining in manifest file. Another question is what is

how to get the state for outgoing calls

蓝咒 提交于 2019-12-03 22:01:36
In the OnReceive method I have something like this: Bundle bundle=intent.getExtras(); String phonenumber=intent.getStrngExtra(Intent.EXTRA_PHONE_NUMBER); How to chech if the dialing call is still on or the client hanged up the call? How to check if the call was answered? I need to print up a toat when the client hanged up the call or when the called client answered to the call. you can use the below code for handling call state::: private Runnable callMonitor = new Runnable() { public void run() { try { EndCallListener callListener = new EndCallListener(); TelephonyManager mTM =

Receive volume key press events when phone is in deep sleep

Deadly 提交于 2019-12-03 21:43:43
I'm trying to catch Volume Up/Down pressing events when phone is in deep sleep mode. I have read several articles and here what I have done. In Activities onCreate method I set a WakeLock PowerManager mgr = (PowerManager)this.getSystemService(Context.POWER_SERVICE); WakeLock wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock"); wakeLock.acquire(); I have read that even if my screen is locked if I set this my application will respond to events. Also I have added permission in to Android Manifest. <uses-permission android:name="android.permission.WAKE_LOCK" /> Then in the

Activity Listener - Google Cloud Messaging - BroadcastReceiver

怎甘沉沦 提交于 2019-12-03 20:22:38
I have implemented GCM in my android application and it's working fine with receiving messages. The BroadcastReceiver is set up in the manifest-file according to the examples provided by Google. My question is the following: If the user is having the application open and I want to update some results in that view - how can this be done? I was first thinking of registering this activity as a listener on whatever the BroadCastReceiver recieves. However, this must then be a static list of listeners, as a new instance of the BroadcastReceiver will be set up - but maybe this is not the way to do

Calling SetContentView() from broadcast receiver

非 Y 不嫁゛ 提交于 2019-12-03 20:15:03
In my application there are two class one is InternetActivity which only extends Activity and sets contentview to main. and MyClass that extends broadcast receiver. I have 2 TextView and 2 ImageView of WIFI and GPRS in main.xml file. When changes in connectivities are happening,brodcast receiver is getting called and according to what is enabled and what is not i want to set visibility of TextView and ImageView. But it is only showing both the images and not the changes. here is MyClass.java file. how can i do it?? public class MyClass extends BroadcastReceiver { private static ImageView wifi

Close Activity Using BroadcastReceiver

删除回忆录丶 提交于 2019-12-03 20:11:20
i have one activity Main.java is open in my application, i want to close the activity using broadcast receiver , how to close the activity? Firstly your Main.java needs to be registered as a receiver. You could register it in Main.java's onResume(): @Override public void onResume() { registerReceiver(broadcastReceiver, new IntentFilter(BroadcasterClassName.NAME_OF_ACTION)); } Then handle the broadcast and finish your activity: private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals

What is the difference between a Listener and a Receiver (Android)?

♀尐吖头ヾ 提交于 2019-12-03 18:49:09
问题 For instance, I need a BroadcastReceiver to get these events: REBOOT or SHUTDOWN SCREEN ON or OFF battery status (voltage, plugged in, temperature) physical button presses (camera, media, etc.) But I need Listener to get these events: EventListener for sensor events (acceleration,magnetic fields, orientation, proximity, temperature, light level, etc.) LocationListener for location events (Network location, GPS) It seems like both Receivers and Listeners both exist so that I can receive events

BroadcastReceiver within a Service not receiving broadcasts Android

北城余情 提交于 2019-12-03 18:10:22
问题 I've got this app, in which users update certain variables in an Activity, and this Activity passes the new variables to a IntentService using a BroadcastReceiver. However, the BroadcastReceiver in the IntentService doesn't seem to be receiving the broadcasts. This is the code within the service to create the broadcast receiver protected class UpdateReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent){ Log.d("receiver", "Got message: "); //state

ConnectivityManager.EXTRA_NO_CONNECTIVITY is always false on Android Lollipop

自古美人都是妖i 提交于 2019-12-03 17:47:43
问题 I am using this piece of code to detect Internet connection state changes. It works fine on Android<5.0, but on API 21 this: intent.getExtras().getBoolean(ConnectivityManager.EXTRA_NO_CONNECTIVITY) is always false. How to make this code to work on Android 5.0? My BroadcastReceiver: public class NetworkStateReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, final Intent intent) { if(intent.getExtras()!=null) { final ConnectivityManager

ACTION_USER_PRESENT in manifest with BroadcastReceiver

孤人 提交于 2019-12-03 17:39:36
问题 There seems to be different opinions on whether it is possible to catch the ACTION_USER_PRESENT screen unlock through the manifest. This thread implies no it can't be done: Android Broadcast Receiver Not Working This thread implies yes it can be done: Broadcast Receiver for ACTION_USER_PRESENT,ACTION_SCREEN_ON,ACTION_BOOT_COMPLETED I'm not able to get the event working with either a 2.3.3 or 3.2 emulator. Does anyone else have recent experience with this? And perhaps a code sample to share?