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 <[email protected]> wrote:

> Thanks for the reply, I uses the permission as:
>     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
>     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"
> />
>
> I had test the code TelephonyManager tel =
> (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE) in an activity
> and it works well.
>
>
> 2009/11/30 Wojciech Topolski <[email protected]>
>
> Hi
>>
>> 2009/11/30 Zhihong GUO <[email protected]>
>>
>> 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
>> [email protected]
>> ===============================
>>
>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]<android-developers%[email protected]>
>> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
[email protected]

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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to