android-service

PendingIntent to launch and stop a Service

谁都会走 提交于 2019-12-06 21:41:19
问题 I'm trying to make a simple widget with a button that start a Service with the OnClickPendingIntent() . I can start it fine but I can't figure out a way to stop it (I know I can do it with a BroadcastReceiver or something similar but I would like to avoid hardcode). This is my code: Intent intent = new Intent(context, myService.class); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.my_widget

Add my app to AutoStart apps list in android programmatically

对着背影说爱祢 提交于 2019-12-06 17:48:20
问题 I want my app to be in the autostart list after installation. I know when I install an app like (whatsapp) it goes automatically to the autostart list. I want my app to be the same I tried the code in this question How to Autostart an Android Application? but unfortunately non of the answers actually made the app autostart. Not sure if I am doing something wrong the reason that I need the app be autostart is just to get notifications from the webservice. as the app does not get notifications

Android - Bind to a service from an other app

依然范特西╮ 提交于 2019-12-06 16:54:40
I have written 2 applications. MyServiceApplication and MyActivityApplication . On boot I launch MyService which runs as a remote service. I want MyActivityApplication to communicate with it however MyActivityApplication does not have access to MyServiceApplication classes. All the examples I see online band an activity to a service in the following way: bindService(new Intent(Binding.this, MyService.class), mConnection, Context.BIND_AUTO_CREATE); My Application needs to communicate with MyService . The code is based off Google's MessengerService example. The trouble as I mentioned earlier is

Multiple AudioTrack Instances (and Threads) in a Single Service?

送分小仙女□ 提交于 2019-12-06 16:50:28
I have a streaming music application that can play two streams simultaneously by using two separate services utilizing one AudioTrack each, on their own threads. Now I'd like to able to play more than two streams, and I guess having more services is not the way to go. Is it possible to have a single service having dynamically instantiated AudioTracks? How can I implement separate threads for each of the AudioTrack instances? How will I access the dynamically instantiated AudioTracks? 来源: https://stackoverflow.com/questions/27493521/multiple-audiotrack-instances-and-threads-in-a-single-service

How to receive missed messages on resuming connection lost in pubnub?

一笑奈何 提交于 2019-12-06 16:14:56
I tried https://github.com/pubnub/java/tree/master/android#connection-durability-reconnecting--resuming-when-a-connection-is-lost-or-changed but still I'm not able to figure out how to use setResumeOnReconnect() . I'm running android-service and added following code snippet inside onCreate() of the service. pubnubBroadcastReceiver =new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); int networkType = intent.getExtras().getInt

How to turn off vibration of Notifications in android

懵懂的女人 提交于 2019-12-06 15:37:30
I'm developing an app that handles sound and vibration of apps' notifications . I am listening to notifications using NotificationListenerService . I am able to turn on or off notification's sound using AudioManager as follows: // It turns off notification's sound myAudioManager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true); // It turns on notification's sound myAudioManager.setStreamMute(AudioManager.STREAM_NOTIFICATION, false); I have also tried to turn on or off notification's vibration with following code but it didn't work on my phone which has Android KitKat 4.4.4 // to turn off

How to send a custom event to AccessibilityService?

最后都变了- 提交于 2019-12-06 15:31:57
My program purpose: trigger the BACK button in a service I tried many ways, no one can achieve this purpose, finally I discovered AccessibilityService, it may be the most possible ways to implement this function. I created this AccessibilityService, and tested it is work package com.accessibilityservice; public class MyAccessibilityService extends AccessibilityService { public MyAccessibilityService() { } @Override public void onAccessibilityEvent(AccessibilityEvent event) { performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK); } @Override public void onInterrupt() { } } <?xml version=

calling onCreate from different threads at the same time

流过昼夜 提交于 2019-12-06 13:55:41
问题 I have read Android documentation in which a piece of code is synchronized inside the onCreate method, Sync Adapter. AFAIK Android only creates one instance of a Service so, can Android call onCreate from different threads at the same time? or is it possible to call a Service method before onCreate has finished (using AIDL)? 回答1: The documentation you linked to (regarding creating SyncAdapter in a thread-safe manner) makes no sense. onCreate() of a Service is only ever called on the main

How to configure Android AccessibilityService

杀马特。学长 韩版系。学妹 提交于 2019-12-06 12:07:04
I am investigating Android AccessibilityService and wanted to see all possible types of events, gestures and Key Events. I am able to receive all public void onAccessibilityEvent(final AccessibilityEvent accessibilityEvent) {} however my service nevers receives protected boolean onGesture(int gestureId) {} or protected boolean onKeyEvent(KeyEvent event) {} calls. When I enable my accessibility service in the accessibility settings I see the service connect OK and I can see the service logging out from the public void onAccessibilityEvent(final AccessibilityEvent accessibilityEvent) {} method

Turn on/off flashlight while app is minimized

早过忘川 提交于 2019-12-06 11:44:36
问题 In my application I have an activity and a service. The service continously manages some data. In certain cases the service sends a broadcast request to the activity to turn on flashlight. This works very well. However it does not work when app is minimized (manually or by incomming call). As soon as I bring the app back to the front it starts to work again. As I observed the log I saw that the service is still running when app is minimized. However since the activity is not present anymore