Re: [android-developers] can I get system service in a my personal service?
Make sure that code is run AFTER onCreate() is called. It isn't clear where it runs, but the Service class is only fully function from onCreate() to onDestroy(); you should not use Context methods like this in the constructr. On Mon, Nov 30, 2009 at 5:14 AM, Zhihong GUO wrote: > Thanks for the reply, I uses the permission as: > > /> > > I had test the code TelephonyManager tel = > (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE) in an activity > and it works well. > > > 2009/11/30 Wojciech Topolski > > Hi >> >> 2009/11/30 Zhihong GUO >> >> Hi all, >>> >>> I got an problem on getting the TelephonyManager in my personal service. >>> The code as below: >>> >>> public class MyService extends Service { >>> >>> @Override >>> public IBinder onBind(Intent intent) { >>> return mBinder; >>> } >>> >>> /** >>> * The implementation of IMyService defined through AIDL. >>> */ >>> public IBinder mBinder = new IMyService.Stub() { >>> >>> public Map getConfig() { >>> ... >>> TelephonyManager tel = >>> (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); >>> >>> ... >>> >>> The code will throw an NullPointerException on the >>> line: (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); >>> >>> why?? >>> >> >> Maybe permission in AndroidManifest.xml is required? On TelephoneManeger >> website is information: "Note that acess to some telephony information is >> permission-protected. Your application cannot access the protected >> information unless it has the appropriate permissions declared in its >> manifest file. Where permissions apply, they are noted in the the methods >> through which you access the protected information." >> >> >> >> -- >> === >> Wojciech Topolski >> wojciech.topol...@gmail.com >> === >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to android-developers@googlegroups.com >> To unsubscribe from this group, send email to >> android-developers+unsubscr...@googlegroups.com >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en >> > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] can I get system service in a my personal service?
Thanks for the reply, I uses the permission as: I had test the code TelephonyManager tel = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE) in an activity and it works well. 2009/11/30 Wojciech Topolski > Hi > > 2009/11/30 Zhihong GUO > > Hi all, >> >> I got an problem on getting the TelephonyManager in my personal service. >> The code as below: >> >> public class MyService extends Service { >> >> @Override >> public IBinder onBind(Intent intent) { >> return mBinder; >> } >> >> /** >> * The implementation of IMyService defined through AIDL. >> */ >> public IBinder mBinder = new IMyService.Stub() { >> >> public Map getConfig() { >> ... >> TelephonyManager tel = >> (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); >> >> ... >> >> The code will throw an NullPointerException on the >> line: (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); >> >> why?? >> > > Maybe permission in AndroidManifest.xml is required? On TelephoneManeger > website is information: "Note that acess to some telephony information is > permission-protected. Your application cannot access the protected > information unless it has the appropriate permissions declared in its > manifest file. Where permissions apply, they are noted in the the methods > through which you access the protected information." > > > > -- > === > Wojciech Topolski > wojciech.topol...@gmail.com > === > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] can I get system service in a my personal service?
Hi 2009/11/30 Zhihong GUO > Hi all, > > I got an problem on getting the TelephonyManager in my personal service. > The code as below: > > public class MyService extends Service { > > @Override > public IBinder onBind(Intent intent) { > return mBinder; > } > > /** > * The implementation of IMyService defined through AIDL. > */ > public IBinder mBinder = new IMyService.Stub() { > > public Map getConfig() { > ... > TelephonyManager tel = > (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); > > ... > > The code will throw an NullPointerException on the > line: (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); > > why?? > Maybe permission in AndroidManifest.xml is required? On TelephoneManeger website is information: "Note that acess to some telephony information is permission-protected. Your application cannot access the protected information unless it has the appropriate permissions declared in its manifest file. Where permissions apply, they are noted in the the methods through which you access the protected information." -- === Wojciech Topolski wojciech.topol...@gmail.com === -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en