Stopping all services..

by greggnic » Fri, 10 Apr 2009 01:40:20 GMT


Sponsored Links
 Hi,

I just started writing an application for android and have run into a
wall. I would like my program to wait a certain amount of time and
then stop all currently running services. This would be useful when
falling asleep and you want to listen to music for say 30 minutes and
then the music player turns off automatically. I have tried this bit
of code:

                ActivityManager am = (ActivityManager)
context.getSystemService(Context.ACTIVITY_SERVICE);

                List<ActivityManager.RunningServiceInfo> myList =
am.getRunningServices(20);

                for(int i=0; i < myList.size(); i++){

                        //Toast.makeText(context, myList.get(i).process,
Toast.LENGTH_LONG).show();
                        android.os.Process.killProcess(myList.get(i).pid);
                 }

However, this does not work. Does anyone have a better way to do this
or any suggestions? Thanks,

-Nick

--~--~---------~--~----~------------~-------~--~----~



Stopping all services..

by Mark Murphy » Fri, 10 Apr 2009 06:12:08 GMT


 


IMHO, that would be a rather significant security issue.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android App Developer Books:  http://commonsware.com/books.html 

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Stopping all services..

by greggnic » Fri, 10 Apr 2009 07:45:38 GMT


 I see your point and definitely agree. I would really like to see a
sleep timer function for the music player though and don't think I
would be able to write a whole music player application that could
compete with the others out there...





--~--~---------~--~----~------------~-------~--~----~



Stopping all services..

by Mark Murphy » Fri, 10 Apr 2009 08:17:39 GMT


 


Well, the built-in music player is open source:

 http://android.git.kernel.org/?p=platform/packages/apps/Music.git ;a=tree

In principle, you could make a sleep-timer patch and submit it:

 http://source.android.com 

Admittedly, there is a learning curve for making changes to the source
code, more so than with many open source projects, due to the unusual
build environment and the unusual patch submission process. I haven't
climbed that curve myself.

Another possibility would be for you to create an application that let
users configure sleep timers and, when the timer elapsed, broadcast an
Intent that confirming applications would pay attention to and honor.
You might partner with OpenIntents.org, as this seems like their sort of
application, and you might be able to help get some prominent
third-party applications, such as some music players, to honor your
sleep-timer Intent. This requires as much people skills as coding
skills, though, to convince other developers to follow your sleep-timer
lead.

There are probably other ways to go about this as well -- those are just
two off the top of my head.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

_The Busy Coder's Guide to Android Development_ Version 2.0 Available!

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. android.media.MediaRecorder is Buggy !!!

http://code.google.com/p/android/issues/detail?id=4075&can=4&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars

_________________________________

I have been using API Level 3 upto 1.5 SDK

but in new SDK 1.6 i have seen following sources added too.
AudioRecorder Sources

But all Three New Sources is Buggy and Not Working

android.media.MediaRecorder.AudioSource.VOICE_CALL  ;
android.media.MediaRecorder.AudioSource.VOICE_DOWNLINK  ;
android.media.MediaRecorder.AudioSource.VOICE_UPLINK  ;

<<<<<First Source - Just Gives Error>>>>>


10-01 15:36:01.666: ERROR/AudioFlinger(556): invalid stream type
10-01 15:36:01.666: ERROR/AudioRecord(556): AudioFlinger could not
create
record track, status: -22
10-01 15:36:01.676: ERROR/MediaRecorder(779): start failed:
-2147483648

10-01 15:36:01.688: DEBUG/AndroidRuntime(779): Shutting down VM
10-01 15:36:01.688: WARN/dalvikvm(779): threadid=3: thread exiting
with
uncaught exception (group=0x4001aa28)
10-01 15:36:01.688: ERROR/AndroidRuntime(779): Uncaught handler:
thread

main exiting due to uncaught exception
10-01 15:36:01.697: DEBUG/CallNotifier(637): stopRing()... (OFFHOOK
state)
10-01 15:36:01.697: DEBUG/Ringer(637): stopRing()...
10-01 15:36:01.707: DEBUG/Ringer(637): - stopRing: null mRingHandler!

10-01 15:36:01.717: ERROR/AndroidRuntime(779):
java.lang.RuntimeException:
start failed.
10-01 15:36:01.717: ERROR/AndroidRuntime(779):     at
android.media.MediaRecorder.start(Native Method)
10-01 15:36:01.717: ERROR/AndroidRuntime(779):     at

com.its.CallRecorder.CallStateListener.Recorder_Prepare
(CallStateListener.java:75)
10-01 15:36:01.717: ERROR/AndroidRuntime(779):     at
com.its.CallRecorder.CallStateListener.onCallStateChanged
(CallStateListener.java:50)

10-01 15:36:01.717: ERROR/AndroidRuntime(779):     at
android.telephony.PhoneStateListener$2.handleMessage
(PhoneStateListener.java:298)
10-01 15:36:01.717: ERROR/AndroidRuntime(779):     at
android.os.Handler.dispatchMessage(Handler.java:99)

10-01 15:36:01.717: ERROR/AndroidRuntime(779):     at
android.os.Looper.loop(Looper.java:123)
10-01 15:36:01.717: ERROR/AndroidRuntime(779):     at
android.app.ActivityThread.main(ActivityThread.java:4203)
10-01 15:36:01.717: ERROR/AndroidRuntime(779):     at

java.lang.reflect.Method.invokeNative(Native Method)
10-01 15:36:01.717: ERROR/AndroidRuntime(779):     at
java.lang.reflect.Method.invoke(Method.java:521)
10-01 15:36:01.717: ERROR/AndroidRuntime(779):     at

com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:791)
10-01 15:36:01.717: ERROR/AndroidRuntime(779):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
10-01 15:36:01.717: ERROR/AndroidRuntime(779):     at

dalvik.system.NativeStart.main(Native Method)


<<<<< Second and Third Source >>>>>

Work Properly but only Records Audio from Mic of may be Uplink Channel
Data


________________________________

-- 

2. how to run emulator to get 1-1 pixel mapping with WVGA854

I have same problem, does anyone have any solutions?




-- 

3. New Game Development Group - OpenGL ES

4. Create a BKS keystore file for SSL support of web server and handshake process

5. how to setViewText in SimpleCursorTreeAdapter?

6. get list of contacts code examples in 2.0

7. Full version invisible in the market on Droid