android-service

Android O Replacement for getRunningServices

∥☆過路亽.° 提交于 2019-11-29 01:54:41
问题 In previous versions of Android, I used this method to find if a service from another app was up and running. It worked reliably for me: ActivityManager manager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> services = manager.getRunningServices(Integer.MAX_VALUE); However, with Android O this is now deprecated and will only return information about the calling apps services. I've looked into other solutions, but I don't want to ask the user for more

How to stop running services?

戏子无情 提交于 2019-11-28 23:14:31
I have this code that describes a service: public class navigation_web extends Service { Context context; public void navigation() { Cursor mCur = getContentResolver().query(Browser.BOOKMARKS_URI, Browser.HISTORY_PROJECTION, null, null, null); mCur.moveToFirst(); if (mCur.moveToFirst() && mCur.getCount() > 0) { while (mCur.isAfterLast() == false) { Log.v("titleIdx", mCur.getString(Browser.HISTORY_PROJECTION_TITLE_INDEX)); Log.v("urlIdx", mCur.getString(Browser.HISTORY_PROJECTION_URL_INDEX)); mCur.moveToNext(); } } // Browser.clearSearches(getContentResolver()); } public void onCreate() { //

How to cancel a foreground service from using the notification (swipe dismiss) or clear all notifications?

情到浓时终转凉″ 提交于 2019-11-28 22:46:15
问题 I'm currently creating a foreground service with a notification that appears in the notification bar when the service starts. If the service stops, the notification dismisses. My question is, is there a way to stop the service when "clear all notifications" or a dismiss of the notification (swipe) occurs? Updated to include implementation of notification: public int onStartCommand(Intent intent, int flags, int startId) { Log.d(CLASS, "onStartCommand service started."); if (getString(R.string

Android - Using Google Analytics v4 Campaign Measurement

喜你入骨 提交于 2019-11-28 21:59:07
I have implemented Google Analytics Campaign Measurement according to this guide . Then I want to test if everything works good by following this guide . I have added these on AndroidManifest.xml : <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <meta-data android:name="com.google.android.gms.analytics.globalConfigResource" android:resource="@xml/global_tracker" /> <!-- Used for Google Play Store Campaign Measurement-->; <service android:name="com.google.android.gms.analytics.CampaignTrackingService" /> <receiver android:name=

Detect Lock Screen Incorrect Password by user in Android

流过昼夜 提交于 2019-11-28 20:56:16
I am building a security app and I need to know if the user is giving incorrect password . Suppose user phone is locked by pattern lock system , and unfortunately user has forgotten the pattern password.When user give wrong pattern 5 time, there will be a penalty for 30 sec . I need to catch that penalty event . In my app, i have to do some task (for the safety of user) when this even come . Please help me, You can set up a DeviceAdminReceiver that will be notified about failed password attempts, as well as a successful password attempt that occurred after a failed attempt. This is covered in

Android java.lang.IllegalArgumentException: Service not registered

僤鯓⒐⒋嵵緔 提交于 2019-11-28 20:54:24
问题 I have a setup that looks something like this: class MyFragment implements SomeEventListener { Application mAppContext; boolean mBound; boolean mDidCallUnbind; MyIBinder mBinder; ServiceConnection mConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { mBound = true; mBinder = (MyIBinder) service; mBinder.getThings();... } @Override public void onServiceDisconnected(ComponentName name) { mDidCallUnbind = false; mBound = false;

How to display Toast from a Service after main Activity finishes?

ε祈祈猫儿з 提交于 2019-11-28 20:44:55
UPDATE: I don't agree that this is a duplicate - because I am seeking for a way to exit the main app and still show a Toast from the service. In a very simple test app I have 2 buttons: Clicking any of the buttons will run a service with a corresponding action string ("open" or "flash") - OpenActivity.java : public class OpenActivity extends Activity { private Intent mServiceIntent; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_open); mServiceIntent = new Intent(this, RegionService.class); } public void openCar

Keep location service alive when the app is closed

好久不见. 提交于 2019-11-28 19:53:42
I have a service which sends a notification when the user changes his/her location. This service is working fine, but the problem arises when the user closes the app as the service closes too. How I can make the service still alive even though the application was closed? My Service is: public class LocationService extends Service implements LocationListener { public final static int MINUTE = 1000 * 60; boolean isGPSEnabled = false; boolean isNetworkEnabled = false; boolean canGetLocation = false; Location location; // location double latitude = 0; // latitude double longitude = 0; // longitude

Persistent service

对着背影说爱祢 提交于 2019-11-28 19:38:38
I know that some peoples view is that you should not create persistent services. But for those of us that want to increase our knowledge, how does one go about creating one in theory? I have been playing around, and noticed that services that use startForeground are killed in low memory situations. I have seen a, now deprecated, permission PERSISTENT_ACTIVITY , but that didn't do much. So what is the secret? You can only make your service persistent if you are developing system apps. These services will be basically un-killable, and are labeled as "PERS" in the output of the "adb shell dumpsys

Android Emulator: How can I get a list of services that are running

限于喜欢 提交于 2019-11-28 18:41:16
I have the Android Emulator running in my Ubuntu VM and just installed an apk file trough the console. The emulator and adb have many options to view what is going on on the device. But how can I get a list of services that are currently running? I'm trying to find out if a specific app installes a notify service to view (unwanted) ads. I even know the services' name. PS.: I'm an advanced beginner - but not advanced enough. So thanks for your help. You can get the list with the following command : adb shell dumpsys activity services If you just need a simple list without all the detail dumpsys