broadcastreceiver

Receiver not registered

僤鯓⒐⒋嵵緔 提交于 2019-12-04 04:00:52
问题 I have a progamm with async task and a broadcast receiver to send a result code, so that Asynctask will know that app is working. But it crashes, sayin the receiver is unreggistred in main activity. I've registred one receiver in main activity, another receiver is in AsyncTask Activity. So here the code and log cat. @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFragmentManager = getFragmentManager();

Listen to location access disable/enable in settings

谁说我不能喝 提交于 2019-12-04 03:13:08
In Android OS, in " Settings " --> " Location services ", there is a toggle button named " Access to my location " which can be used to disable & enable location info access from apps. Currently, I am developing a location service application. I am wondering, how can I listen to this setting in my Android project? Is there any broadcast receiver I can use to know right away when user disable or enable " Access to my location " ? If there isn't any broadcast receiver for it, how can I listen to this change in my Android project? This works for me: Add receiver to the Manifest file: <receiver

Bind Service to BroadcastReceiver

Deadly 提交于 2019-12-04 03:06:39
问题 I have some Service class, which registers multiple alarms. In my BroadcastReceiver class, I want the onReceive () method to call some method of the Service class. However, I don't see how I can bind them together. I tried to make the BroadcastReceiver an inner class, but then I got more errors and couldn't fire the alarm at all. Thanks 回答1: Look at http://developer.android.com/reference/android/content/BroadcastReceiver.html life cycle. BroadcastReceiver is created only for handling a

Create Notification with BroadcastReceiver

人走茶凉 提交于 2019-12-04 02:46:55
问题 I tried to create a Notification with this Code: private void setNotificationAlarm(Context context) { Intent intent = new Intent(getApplicationContext() , MyNotification.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 , pendingIntent); Log.d("ME", "Alarm started"); } public

Android background services and alarms

折月煮酒 提交于 2019-12-04 02:07:50
问题 Recently encountered with a problem when Android 4.4 killed my app's Service and AlarmManager when device going into a sleep mode ( START_STICKY param doesn't helps). I tried a lot of things, but nothing works as I need. In my task manager app I always see a lot of processes of non-default apps such as Google+, Skype, Google Drive end some else that working in real time and never were killed by the system. I want to ask more experienced developers how to create Service or Alarm that will not

Sending extras to BroadcastReceiver

痞子三分冷 提交于 2019-12-04 01:57:18
问题 I have an Activity that runs the following code (time and interval are defined): Intent buzzIntent = new Intent(getBaseContext(), BuzzReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), 0, buzzIntent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); buzzIntent.putExtra("interval", interval); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, interval * 60 * 1000, pendingIntent); and a BroadcastReceiver that has the

“com.android.vending.INSTALL_REFERRER” somehow parameters are lost and changed to (not%20set)

风格不统一 提交于 2019-12-04 01:52:51
问题 I have a problem with INSTALL_REFERRER broadcast in my app. I'm trying to create some information about campaign etc, but on most devices my url "https://play.google.com/store/apps/details?id=com.test.apptest&referrer=utm_source%3Dmy_test_source" EDIT: the same thing happens with link "market://details?id=com.test.apptest&referrer=utm_source%3Dmy_test_source" is change to something like "utm_source=(not%20set)&utm_medium=(not%20set)" I don't know what is the reason for such a behaviour of

Android BroadcastReceiver详解

血红的双手。 提交于 2019-12-04 01:36:44
1、BroadcastReceiver简介: BroadcastReceiver用于接收程序(包括系统程序和一般应用)通过sendBroadcast()方法发出的Broadcast intents。 2、程序启动BroadcastReceiver的步骤(发出广播): 1) 创建需要启动BroadcastReceiver的Intent。 2) 调用Context的 sendBroadcast ()或 sendOrderedBroadcast ()方法来启动指定的BroadcastReceiver。其中 sendBroadcast 发送的是普通广播,sendOrderedBroadcast发送的是有序广播。 当应用发出一个Broadcast Intent之后所匹配该Intent的组件都可能被启动。 3、创建BroadcastReceiver的步骤: 第一步:创建BroadcastReceiver的子类: 由于BroadcastReceiver本质上是一种监听器,所以创建BroadcastReceiver的方法也非常简单,只需要创建一个BroadcastReceiver的子类然后重写onReceive (Context context, Intentintent)方法即可。 具体代码如下: public class MyBroadcastReceiver extends

Check if Service is running from a Broadcast Receiver

风格不统一 提交于 2019-12-04 01:13:33
问题 I'll like to ask if it's possible to check a service is running from Broadcast receiver. I know that it's possible in Activity. Thanks for your precious help 回答1: yes' it's possible to detect if service is running from anywhere you have available Context object: private boolean isMyServiceRunning(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {

Android - How to start an application on the /sdcard after boot

萝らか妹 提交于 2019-12-04 00:06:16
Is there a way how to start and android application after a boot automatically if it is on the /sdcard ? Ok, probably by BroadcastReceiver . But which action is the right one? ACTION_BOOT_COMPLETED - does not work if it is on the /sdcard (documented) ACTION_MEDIA_MOUNTED - does not work if it is on the /sdcard (which is undocumented) ACTION_EXTERNAL_APPLICATIONS_AVAILABLE - does not work, I do not know why ACTION_USER_PRESENT - does not work if the BroadcastReceiver is registered in AndroidManifest (which is undocumented, but documentation bug has been reported) Thanks Jan Rahul Chaudhary