broadcastreceiver

How to call this even when the app hasn't even started

回眸只為那壹抹淺笑 提交于 2020-01-16 18:03:34
问题 So my app shows a notification icon on headset plugin, and it destroys itself also if the headset is removed. But that only works if the application has been opened. How could I make it so it detects the headphone plugin and runs the icon in the background? Here is the class the detects if the headset has been plugged in or not public class MusicIntentReceiver extends BroadcastReceiver { int NOTIFICATION_ID = 1234567890; NotificationManager mNotificationManager; @Override public void

How to use broadcast and receivers

≡放荡痞女 提交于 2020-01-16 14:48:10
问题 How can I use my Broadcast receiver? Like when my app starts how do I make the receiver continually run its code? My Reciver code: private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { ConnectivityManager mConnectivity; mConnectivity = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = mConnectivity.getActiveNetworkInfo(); if (info == null || !mConnectivity

Broadcast Receiver on Nexus 7

↘锁芯ラ 提交于 2020-01-16 14:34:23
问题 I am trying to write a service that runs on phone boot, and must read data off the SD card. At first I was using a reciever for android.intent.action.BOOT_COMPLETED but switched to the intent below to make sure that the SD card has been loaded. My Issue is that on a my Nexus 7, it doesn't appear to receive the MEDIA_MOUNTED intent. The Nexus 7 doesn't have an SD card (but it has separate SD card partition). I also tried the BOOT_COMPLETED intent, with the same luck. I have tested the same

instantiate inner broadcast receiver class

亡梦爱人 提交于 2020-01-16 08:49:07
问题 I just changed my external broadcast receiver class to my service since..some android method could not be used in static context. Now i receive an error Unable to instantiate activity ComponentInfo{com...}: java.lang.NullPointerException. How is it possible to fix? Below is my code for nested BroadcastReceiver class. public class ServiceX extends Service { private SharedPreferences settings = getSharedPreferences(PREFS, 0); private SharedPreferences.Editor editor = settings.edit(); private

Android - Custom action in Broadcast Intent

此生再无相见时 提交于 2020-01-16 06:07:34
问题 I am trying to allow user to post comment when he is offline such that whenever wifi/internet is turned on his comment will be posted.Fot that I am using BroadCastReceiver.But the issue i am having is that it is never going inside if (intent.getAction().equals("commentpost")) if i try switching on wifi after clicking on postcomment.However it does go inside if (wifi.isAvailable() || mobile.isAvailable()) whenever i switch on wifi.I failed to understand where i am going wrong.My log shows

Android - Custom action in Broadcast Intent

。_饼干妹妹 提交于 2020-01-16 06:06:16
问题 I am trying to allow user to post comment when he is offline such that whenever wifi/internet is turned on his comment will be posted.Fot that I am using BroadCastReceiver.But the issue i am having is that it is never going inside if (intent.getAction().equals("commentpost")) if i try switching on wifi after clicking on postcomment.However it does go inside if (wifi.isAvailable() || mobile.isAvailable()) whenever i switch on wifi.I failed to understand where i am going wrong.My log shows

BroadCast Receiver or Sync Adapter for detection of deletion of files at particular Location Android

风格不统一 提交于 2020-01-16 05:32:06
问题 I want a broadcast receiver that detects for deletion of files at particular location in android. Basically there are some files downloaded by the app whom I want to keep track of. As they gets deleted it should also be deleted from the local apps database. And if its possible a way to track when the file has moved from one location to another and is still present in the phone to get its current location. Please help. 回答1: I think you can use FileObserver for this. Just observe the files you

update fragment ui based off of Activity's Broadcast Receiver

我怕爱的太早我们不能终老 提交于 2020-01-16 01:18:32
问题 First let me say I have read through many of the questions related to fragments on SO. However, I can't seem to find a situation quite the same as mine. I have myActivity that is using the PageAdapter, each page being a fragment. I also have a service that receives updates about the network connections etc. The service triggers the receiver in myActivity. myActivity needs to update FragmentPage1 but because I am using a pageAdapter and creating my fragments at run time I cannot

Could AlarmManager.setInexactRepeating not broadcast intents when the device is in sleep mode?

时光总嘲笑我的痴心妄想 提交于 2020-01-15 16:35:31
问题 I have a very simple class that sets and cancels an AlarmManager to broadcast intents: public class MyIntentsAlarm { public void setAlarm(Context context){ AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent("MY_ACTION"); PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0); am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),5*60*1000L, pi); } public void cancelAlarm(Context context){ Intent intent = new

Could AlarmManager.setInexactRepeating not broadcast intents when the device is in sleep mode?

徘徊边缘 提交于 2020-01-15 16:34:59
问题 I have a very simple class that sets and cancels an AlarmManager to broadcast intents: public class MyIntentsAlarm { public void setAlarm(Context context){ AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent("MY_ACTION"); PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0); am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),5*60*1000L, pi); } public void cancelAlarm(Context context){ Intent intent = new