2017-10-12 111 views
1

我有一個android應用程序與webview,我想發送唯一的設備ID到PHP文件。如何在webview url上添加android_id(或設備ID,應用程序ID)?在webview url中的Android ID

事情是這樣的:

webview launchUrl = "https://www.exampledomain.com/myphp.php?androidid=ANDROID_ID"; 

ANDROID_ID= xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 
+0

您的問題是ambigous,你想要添加Android ID到PHP文件或Java文件?什麼是Android ID?來自xml的屬性ID,還是來自設備的IP值或什麼?如果在PHP剛剛添加了全局$ _GET ['andoidid'] = $ value; – user8455694

+0

ANDROID_ID = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx webview launchUrl =「https://www.exampledomain.com/myphp.php?androidid="+ANDROID_ID; 使用launchUrl concat ANDROID_ID – Sanil

+0

我需要設備ID(UUID)通過在web視圖中發送becouse我需要在PHP中註冊每個設備以基於每個設備ID發送不同的通知。例如:發票通知,服務激活停用etc.Simply我需要知道在PHP是什麼是每個設備的目標他們的身份和發送通知。 –

回答

0

我用我的Android應用科爾多瓦+網頁視圖+ Onesignal。我現在有這樣的代碼:

private static String uniqueID = UUID.randomUUID().toString(); 
private static final String PREFS_GT_PLAYER_ID = "GT_PLAYER_ID"; 

public synchronized static String id(Context context) { 
    if (uniqueID == null) { 
     SharedPreferences sharedPrefs = context.getSharedPreferences(PREFS_GT_PLAYER_ID, Context.MODE_PRIVATE); 
     uniqueID = sharedPrefs.getString(PREFS_GT_PLAYER_ID, null); 
     if (uniqueID == null) { 
      uniqueID = UUID.randomUUID().toString(); 
      SharedPreferences.Editor editor = sharedPrefs.edit(); 
      editor.putString(PREFS_GT_PLAYER_ID, uniqueID); 
      editor.commit(); 
     } 
    } 
    return uniqueID; 
} 



private void setStartUrl(String src) { 

    Pattern schemeRegex = Pattern.compile("^[a-z-]+://"); 
    Matcher matcher = schemeRegex.matcher(src); 
    if (matcher.find()) { 
     launchUrl = src; 
    } else { 
     if (src.charAt(0) == '/') { 
      src = src.substring(1); 
     } 
     launchUrl = "https://www.exampledomain.com/myphp.php?androidid=" + uniqueID; 

    } 
} 

uniqueID是隨機生成的,但我想從onesignal生成player_id。 This is a print screen from my onesignal account