2016-07-20 174 views
0

我用這個代碼,它的工作時,我從活動和片段如何在android中獲取廣告ID?

import com.google.android.gms.ads.identifier.AdvertisingIdClient.Info; 


Info adInfo = null; 

try { 
    adInfo = AdvertisingIdClient.getAdvertisingIdInfo(mContext); 
} catch (IOException e) { 
    e.printStackTrace(); 
} catch (GooglePlayServicesAvailabilityException e) { 
    e.printStackTrace(); 
} catch (GooglePlayServicesNotAvailableException e) { 
    e.printStackTrace(); 
} 

String AdId = adInfo.getId(); 

稱爲但是,當我從待定像包裝意圖刪除然後叫我想打電話給當時的Web服務我需要廣告ID,但我得到null.if你以前做過的人請提前告訴我。提前感謝。

回答

0

嘗試使用應用程序上下文

的接收器可以使用活動內容或應用程序上下文 - 取決於誰&如何開始接收

AdvertisingIdClient.getAdvertisingIdInfo(context.getApplicationContext()); 
相關問題