I have a registered Broad Cast receiver in my app to store USB connected/disconnected state in Shared Preferences. Its working Fine.
Now i wanted to perform a task immediately if USB connected and my application is running. how can i do this?
If my application is not running , i ll perform the task in my first activity based on the Shared Preference value.
Please give some ideas to do this..
I have paste some code which shows how to check for running services here.
If you looking for activity use RunningTaskInfo instead of RunningServicesInfo.
Related
I have made an app, in that I need to check if internet is available then it should work otherwise should give popup.
As I have made whole app I want to avoid writing the internet connectivity check function in each activity or calling it multiple times.
So I am wondering is there an easy way to check internet connectivity of app in whole app by writing it in either Manifest or other way?
Thanks in Advance
In Android, there is a pretty neat resource called Broadcast Receiver. What you need to do is to declare a new class that extends a BroadCast Receiver object and then register in your manifest file for the "specific filter" that you are looking for, and whenever the connectivity goes away, or the network status change the Android SDK will launch an Intent in your app.
Check this question. :
Broadcast receiver for checking internet connection in android app
How can an apps application class run at once the device starts?
Hello,
I have an application where the application class is running it's onCreate, but no activites on device startup. And i don't mean when the BOOT broadcast is sent, i mean at once the device is started.
I can see this since i've added file logging to the appliation class, but i cannot see that it comes any further (into any activities).
My manifest has
No receivers
No services with their own process id
Is there anything else that could start my application class on device start?
When i click and start the application on my device, i see logs in the application class again, but this time it has another process id than it had.
Thanks in advance!
===================
ok, so after commenting out all obvious code and manifest entries, i finally set my Sync Adapter Service to enabled=false, and then the problem did not occur. Is this normal behaviour of a sync adapter service?
I'm looking to expand my app to handle Guest Mode, introduced in Android L. I found that if I create a service with android:singleUser in AndroidManifest, with permission INTERACT_ACROSS_USERS, and I'm a system app by installing it in /system/priv-app, then my service is running even as I switch user. But my app needs to interact with the user, by being able to launch an activity, show a toast or notification. All of those things seems to not be possible. Is there a particular flag I need to set when I call startActivity so that it will launch a new activity from my service?
I found a way to do it. Basically have a singleton Service, which is a service with the android:singleUser="true" and with INTERACT_ACROSS_USERS and have the APK installed in /system/priv-app. Then have it broadcastAsUser to all users. You'll need to use reflection to access methods in UserManager. Then have a receiver instance which will receive the broadcast in the guest user's space, and then have the receiver startActivity.
There are several internal apis (comments as #hide) like Context.startActivityAsUser, NotificationManager.notifyAsUser to support it, but it needs build from source also with platform signature.
I want to implement an app which can detect what app launched, to do something with that!
for example I have a list of installed applications in my app and mark one favorite app. and when I start that marked app from default launcher or anyway, I could detect it and do something with that by a background service or broadcast receiver(For example launch a toast message).
How can I do this?
this isnt possible.. to be able to monitor all intents would make android extremely insecure
http://groups.google.com/group/andro...ddc9d36a24d77b
but there are ways to know when an application is launched. you just have to be creative.
this will give you a list of all the applications running.
Code:
ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();
however to know when an app is launched you would need a timed loop and then check between versions of the List to see if there is a new app. this would suck the juice and be inneficient
AppProtector seem to access the eventlog. maybe you could have a ContentObserver attached to the event log
http://developer.android.com/referen.../EventLog.html
http://developer.android.com/referen...tObserver.html
EDIT
Interesting.
I also found this which solve your problem.
When you open any app from launcher below code will return the info of opened app so now you need to compare a package name with your favourite app package name which you already stored in your app database.
Code:
String str = ((ActivityManager.RunningTaskInfo)this.am.getRunningTasks(1).get(0)).topActivity.getPackageName();
I am working on one network app, i have problem with tracking those red
marks check box. means that if "Data Enable" is check than
pro-grammatically i know in my App this Data Enable is check or
UN-check.
so like that all Data roaming and Use only 2G networks Also track.
i was lots of try to maintain track this but i can't success, i
really want help.
Thanking you.
There are several ways for this...
You have ConnectivityManager class in android. Did you try using that?
http://developer.android.com/reference/android/net/ConnectivityManager.html
This is available to let you know about the network state of your device.
What you can do?
And you can receive automatic notification of when the connection state changes via the CONNECTIVITY_ACTION broadcast
You can setup your Broadcast receiver and register your application to broadcast an Action
Alernatively you can also work with services depends upto Architecture of your application
I guess any internet connection should be fine for you if you only worried about Internet
Then start your process as you want to. :)