android-broadcast

Start a service automatically when app installed to device [duplicate]

被刻印的时光 ゝ 提交于 2020-01-16 00:27:05
问题 This question already has answers here : How to start a Service when .apk is Installed for the first time (10 answers) Closed 5 years ago . I want to start a service automatically when the app is installed. Service is working properly after a launch or after a device boot. So, is it possible to launch a service after installation of the app? 回答1: Google shows the correct answer as the first hit so ... have you done some research on this? How to start a Service when .apk is Installed for the

Android get current song playing and song changed events, like Musixmatch

烈酒焚心 提交于 2020-01-12 09:52:16
问题 What i want to achieve is very similar to what Musixmatch is doing. I need to be informed when the music starts playing and when the song is changed. All this in the service because my app may be closed (even musicmatch does this). In the above case even if Musixmatch app is not running i get a notification when ever i change the song on spotify or any player. Can anyone pls tell me how to achieve this. I don't need the code help, just what to know how to achieve it. I'm really confused how

Android Services: START_STICKY does not work on Kitkat

↘锁芯ラ 提交于 2020-01-11 15:30:21
问题 I am using services in an application to listen for how many times the user presses his/her power button. The implementation was working fine on all devices. But when I tested the app on the Android Kitkat, I noticed something wrong. As soon as I swipe the application away from the recents apps, the application no longer listens for the power button. Here is the code that I am working with: public class Receiver extends Service { Notification notification; private static final int

Alarm receive don't work

爱⌒轻易说出口 提交于 2020-01-11 13:15:10
问题 I'm making an alarm receiver, but the alarm is not triggered. This is my code : Start alarm in MainActivity : private void setupAlarm(){ Intent intent = new Intent(this, com.logdata.AlarmReceiver.class); PendingIntent pIntent = PendingIntent.getService(this, 0, intent, 0); AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,SystemClock.elapsedRealtime() + 1, 1000, pIntent); Log.e("setupAlarm", "Setup alarm

Intent extras don't seem to refresh

醉酒当歌 提交于 2020-01-06 08:14:30
问题 When I press the button it calls a method which gets user input and sets it to a variable, then that variable is put to an intent extra and sent to BroadcastReceiver which decides what to do depending on that value. It only works the first time, on all the next presses intent extra value isn't changed no matter if that variable value changes. It forever holds the value which is set at the first press. How to rewrite intent extra with a new value? How I set the extra: Intent intentForReceiver

I would like to use Loader manager and its call backs inside broadcast receiver when broadcast fire?

百般思念 提交于 2020-01-05 08:39:13
问题 I m not able to get getSupportLoaderManger or getLoaderManager I m confuse how to resolve this, public class MyBroadCastReceiver extends BroadcastReceiver implements LoaderManager.LoaderCallbacks<Cursor> { int cpValue; private CursorLoader cursorLoader; private Context mContext; @Override public void onReceive(Context context, Intent intent) { mContext = context; mContext.getSupportLoaderManager().initLoader(1, null, context); } private void doTheTask(MyAsync task, Intent intent) { if (Build

Is it OK to unregister 'dynamic' BroadcastReceiver from receiver's own onReceive() method?

微笑、不失礼 提交于 2020-01-03 15:32:51
问题 That is, I have this BroadcastReceiver I create on the fly to listen for one broadast, after which I want it to unregister itself. I haven't found any sample code that does it this way, but neither have I found any rule in the android online docs that forbids this. But I cannot let it hang around for as long as the activity, and it is in an anonymous class anyway, so the containing class does not even know the variable name. That is, the code looks something like this: myInfoReceiver = new

Is it OK to unregister 'dynamic' BroadcastReceiver from receiver's own onReceive() method?

99封情书 提交于 2020-01-03 15:32:34
问题 That is, I have this BroadcastReceiver I create on the fly to listen for one broadast, after which I want it to unregister itself. I haven't found any sample code that does it this way, but neither have I found any rule in the android online docs that forbids this. But I cannot let it hang around for as long as the activity, and it is in an anonymous class anyway, so the containing class does not even know the variable name. That is, the code looks something like this: myInfoReceiver = new

sendBroadcast does not get called in Activity when Activity is opened

别来无恙 提交于 2020-01-03 02:29:11
问题 I am making an app where I receive XMPP packets. My app starts in foreground and starts a Sticky Service if not started and start receive messages in backgrounds and make notifications of them. The notifications works well and when clicked they show the data. Issue comes (that too sometimes in some mobile phones) when I make a sendBroadcast call from service so that I can asynchronously update the text of message in Activity when it is opened. My app is made with a Activity and within that

Open fragment from notification when the app in background

五迷三道 提交于 2020-01-01 16:56:27
问题 I am using parse to push Json notifications to my app with custom receiver because I want to navigate to different places in the app and that's depends on Json value I receive, I have 2 cases to navigate: a) 7 b) 1, 2, 3, 4, 5, 6 case a opens an activity and that's works as normal. case b open a fragment in the `MainActivity. "Here's the problem." I tried to open the MainActivity with normal intent then replace the container of it with the fragment. When I try to open case b I got