android-service

keeping background service alive after user exit app

假装没事ソ 提交于 2019-12-17 18:38:20
问题 I'm trying to create a service that will do background jobs for me even after the user closes the app from the running processes menu(by shifting process out of the screen). What I tried to do is create service in a different process by declaring it like this: <service android:name=".service.Service" android:enabled="true" android:icon="@drawable/ic_launcher" android:process=":my_process" > </service> and the onStartCommand() is: @Override public int onStartCommand(Intent intent, int flags,

How to call a method in activity from a service

拥有回忆 提交于 2019-12-17 17:48:18
问题 There is a service that listens for some voice. If voice matches a string a certain method is invoked in the service object. public class SpeechActivationService extends Service { public static Intent makeStartServiceIntent(Context pContext){ return new Intent(pContext, SpeechActivationService.class); } //... public void onMatch(){ Log.d(TAG, "voice matches word"); } //... } This is how I start the service in my activity: Intent i = SpeechActivationService.makeStartServiceIntent(this);

PendingIntent does not send Intent extras

前提是你 提交于 2019-12-17 17:33:54
问题 My MainActicity starts RefreshService with a Intent which has a boolean extra called isNextWeek . My RefreshService makes a Notification which starts my MainActivity when the user clicks on it. this looks like this: Log.d("Refresh", "RefreshService got: isNextWeek: " + String.valueOf(isNextWeek)); Intent notificationIntent = new Intent(this, MainActivity.class); notificationIntent.putExtra(MainActivity.IS_NEXT_WEEK, isNextWeek); Log.d("Refresh", "RefreshService put in Intent: isNextWeek: " +

Get Exception when showing Alert Dialog from Service - Unable to add window — token null is not for an application

冷暖自知 提交于 2019-12-17 16:47:07
问题 Get Exception when showing Alert Dialog from Service. Following is the code in my Service class: I am trying to show an AlertDialog. But I get the error: Unable to add window -- token null is not for an application I am also attaching snapshot of my Log to this Question. if(!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)&& !mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){ Log.d("TrackingService","H: Exception after this"); AlertDialog.Builder builder =

Restart service after force stop

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 16:38:15
问题 I am developing an application which is used as application locker, an app which is able to protect other installed apps by asking the user for a password on opening those apps, my app is here The problem is that the application can be easily skipped by force close it from the android task manager, how can I overcome this? Also what is the best way to check for a new application open, to make a service which check every one second for the app on the top of tasks or to fire alarm with alarm

Can anybody explain what is difference between unbound and bound service in android

試著忘記壹切 提交于 2019-12-17 15:29:06
问题 Can anybody explain what is difference between unbound and bound service in android and explain about intent service Thanks 回答1: Bound Service A service is bound when an application component binds to it by calling bindService(). A bound service offers a client-server interface that allows components to interact with the service, send requests, get results, and even do so across processes with interprocess communication (IPC). When the last client unbinds from the service, the system destroys

Android fullscreen app - prevent access to status bar

本秂侑毒 提交于 2019-12-17 14:56:09
问题 I am creating a fullscreen app which will run in "kiosk" mode, so the user will not be able to exit. The app is defined as a launcher (home screen). The Activity in the manifest is defined with: android:theme="@android:style/Theme.NoTitleBar.Fullscreen" Additionally, the Activity ensures full screen mode with the following in its onCreate() : getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); However,

Bad notification posted - Couldn't expand RemoteViews for: StatusBarNotification

陌路散爱 提交于 2019-12-17 10:56:35
问题 I am trying to post a notification with a custom view in the notification area from an IntentService , and getting the Couldn't expand RemoteView error. Here's what I am doing in onCreate() : mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); icon = R.drawable.icon; tickerText = "data upload in progress"; contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notiflayout); contentView.setImageViewResource(R.id.image, R

Android O - Detect connectivity change in background

Deadly 提交于 2019-12-17 10:52:59
问题 First off: I know that ConnectivityManager.CONNECTIVITY_ACTION has been deprecated and I know how to use connectivityManager.registerNetworkCallback . Furthermore if read about JobScheduler , but I am not entirely sure whether I got it right. My problem is that I want to execute some code when the phone is connected / disconnected to/from a network. This should happen when the app is in the background as well. Starting with Android O I would have to show a notification if I want to run a

Android O - Detect connectivity change in background

让人想犯罪 __ 提交于 2019-12-17 10:51:33
问题 First off: I know that ConnectivityManager.CONNECTIVITY_ACTION has been deprecated and I know how to use connectivityManager.registerNetworkCallback . Furthermore if read about JobScheduler , but I am not entirely sure whether I got it right. My problem is that I want to execute some code when the phone is connected / disconnected to/from a network. This should happen when the app is in the background as well. Starting with Android O I would have to show a notification if I want to run a