android-service

Android activity accessing service's static reference before the service is ready

旧城冷巷雨未停 提交于 2019-12-23 22:08:45
问题 I am trying to fire a Text to speech service from an activity and the activity based on certain events would cause the appropriate string to be sent to the service which speaks out. Here is my TTSService: public class TTSService extends Service implements TextToSpeech.OnInitListener{ private String str; private TextToSpeech mTts; private static final String TAG="TTSService"; public static TTSService sInstance; @Override public IBinder onBind(Intent arg0) { return null; } @Override public void

Networkonmainthread exception while executing httprequest in a bound service from another service via aidl

余生长醉 提交于 2019-12-23 18:32:09
问题 I have a service which binds another service via aidl.The bound service executes a httprequest and returns a response when the method is invoked from callign service via aidl. I am getting Networkonmainthread exception while doing this. Usage of Asynctask failed here for webservice query.Any help is appreciated :) 来源: https://stackoverflow.com/questions/6622101/networkonmainthread-exception-while-executing-httprequest-in-a-bound-service-fro

Android IntentService triggered with null intent

浪尽此生 提交于 2019-12-23 10:49:11
问题 I'm seeing a crash in Crashlytics: Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Intent.getIntExtra(java.lang.String, int)' on a null object reference at com.myapp.APKOfferQueueManagerIntentService.onHandleIntent(SourceFile:71) at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.os.HandlerThread.run

Communication between an Application class and Service in Android

白昼怎懂夜的黑 提交于 2019-12-23 06:04:10
问题 I have a requirement where I have already extended an "Application" class in my Android Project. eg: public class myApp extends Application implements myReceiver.Receiver {...} Is it possible for me to communicate through a "Service" using my - "Message.obtain" or should I use other things? Please advice. I also want to pass data to my Service which is a String/constant value. Can I do it like this : private void sendMsg(int arg1, int arg2) { if (mBound) { Message msg = Message.obtain(null,

How to close foreground app in Android service?

白昼怎懂夜的黑 提交于 2019-12-23 04:54:29
问题 I want to close current foreground app in Android service. However, it does not work in service. Could you have me to fix it? Thanks. ActivityManager manager = (ActivityManager) getApplicationContext().getSystemService(ACTIVITY_SERVICE); List<ApplicationInfo> packages; PackageManager pm; pm = getPackageManager(); //get a list of installed apps. packages = pm.getInstalledApplications(0); ActivityManager mActivityManager = (ActivityManager)getApplicationContext().getSystemService(Context

How to turn off vibration of Notifications in android

筅森魡賤 提交于 2019-12-23 04:14:17
问题 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

How to send a custom event to AccessibilityService?

故事扮演 提交于 2019-12-23 03:42:17
问题 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) {

Alarm manager for background services

可紊 提交于 2019-12-23 03:35:28
问题 I have implemented the alarm manager to wake up the background services every 15 mins periodically. It is working fine, but since the inclusion of DOZE mode Android 6.0, the seems like behaving strange and not waking up in every 15 mins. Although, I am using the method alarm.setExactAndAllowWhileIdle(), but still not working in Idle state here is my method for implementing Alarm Manager private void serviceRunningBackground() { final Intent restartIntent = new Intent(this, service.class);

Android - Bind to a service from an other app

被刻印的时光 ゝ 提交于 2019-12-23 03:30:27
问题 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

Stop the background service after particular time in android

无人久伴 提交于 2019-12-23 02:55:10
问题 Hi i need to stop the Background service which is already started after particular time.I will get the duration from server for when to stop the service.I have tried the Alarm Manager in android. Calendar cal = Calendar.getInstance(); Intent intent = new Intent(context, MyService.class); PendingIntent pintent = PendingIntent.getService(context, 0, intent, 0); AlarmManager alarm = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); // Start every 30 seconds alarm.setRepeating