2014-03-29 36 views
0

我試圖使用此代碼: TelephonyManager telephonyManager;在android中的列表片段中的電話管理器

 telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 
     imeistring = telephonyManager.getDeviceId(); 

撥打的電話的ID,但是當我是一個列表裏面的片段,它給我的錯誤。「不能在從活動類型的非靜態方法getSystemService(String)將靜態參考。

我還能有別的就能夠得到這個手機號?

它可以在活動的文件,但不ListFragments ...

+0

請如果答案有用的接受和/或給予好評它 –

回答

2
telephonyManager = (TelephonyManager)getActivity.getSystemService(Context.TELEPHONY_SERVICE); 
imeistring = telephonyManager.getDeviceId(); 
+0

我試過這個,但它讓我創建一個getActivity參數。當我這樣做,它是空的.. –

+0

沒關係。這是因爲我需要telephonyManager =(TelephonyManager)getActivity()。getSystemService(Context.TELEPHONY_SERVICE); –