java – TELEPHONY_ The service constant is not recognized in one class, but in another

It feels very much like another situation where you don't see the woods

I have written a small (non extended) class for my application, which currently contains only one method to grab the provided URL and return a string I want to include the device ID at the end of the query string, so I added the following line:

import android.telephony.TelephonyManager;
import android.content.Context;
...
TelephonyManager m_tmgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

However, according to eclipse, telefony_ Service constant cannot be resolved to variable If I copy and paste these lines into another class in the package (all other classes are active and may be related to it at present?), business as usual.

What obvious things did I miss?

Solution

TELEPHONY_ Service is a member of context class, which is a superclass of activity class Therefore, this constant is only available in activity or context subclasses

http://developer.android.com/reference/android/content/Context.html#TELEPHONY_SERVICE

You can access context TELEPHONY_ SERVICE

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>