在android中如何通过拆分url获取字符串?

在android中如何通过拆分url获取字符串?,android,Android,我有一个google play store url“”,从这个url我必须将“com.example.launcher”存储在一个单独的变量中,并与包名“com.example.launc”进行比较,如果比较我必须发送一个json请求。我如何才能做到这一点 String s = "https://play.google.com/store/apps/details?id=com.apusapps.launcher&hl=en"; String s2 = s.substring(s.in

我有一个google play store url“”,从这个url我必须将“com.example.launcher”存储在一个单独的变量中,并与包名“com.example.launc”进行比较,如果比较我必须发送一个json请求。我如何才能做到这一点

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();
您可以这样做:

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

您可以使用substring()方法获取所需的字符串使用substring获取包名:)那么您是否阅读了
android.net.Uri
文档?