2016-04-25 80 views
-2

我有一個谷歌播放商店URL「https://play.google.com/store/apps/details?id=com.apusapps.launcher&hl=en」從這個URL我必須存儲「com.example.launcher」在一個單獨的變量和比較從包名稱「com.example.launc」如果比較我必須發送一個JSON我的要求。如何能做到這一點如何通過在android中拆分url來獲取字符串?

+0

你可以使用子()方法來獲得你想要的字符串 –

+0

使用子串來獲得包名稱:) –

+0

你是否閱讀過'android.net.Uri'文檔? – pskink

回答

0

試試這個:

String s = "https://play.google.com/store/apps/details?id=com.apusapps.launcher&hl=en"; 
String s2 = s.substring(s.indexOf("=")+1, s.indexOf("&")); 
Toast.makeText(this,"Milad: "+s2,Toast.LENGTH_LONG).show(); 
0

你可以這樣做:

String urlString = url.toString(); 
String finalString = urlString.substring(urlString.indexOf("=")+1,urlString.lastIndexOf("&")); 
if(finalString.equals(getApplicationContext().getPackageName())){ 
    //Your code 
}