Friday, 8 March 2019

How to find specific key and value from any URL in java or in Android

https://myurltest.com/takeElement?exp=androidHubb&rollnumber=10
//pass takeElement and rollnumber

1. Method :- one way 
UrlQuerySanitizer sanitizer = new UrlQuerySanitizer(url);
String takeElement = sanitizer.getValue("takeElement"); // get your takeElement
String rollnumber = sanitizer.getValue("rollnumber"); // get your rollnumber
Log.d(TAG,"takeElement:: "+ takeElement);Log.d(TAG,"rollnumber:: "+ rollnumber);
intent.putExtra("takeElement", TextUtils.isEmpty(experienceName)?"": takeElement);
intent.putExtra("rollnumber", TextUtils.isEmpty(experienceName)?"": rollnumber);


2. Method :- 2nd way 
Uri uri = Uri.parse(url);
String experienceName = uri.getQueryParameter("takeElement");
String rollnumber = uri.getQueryParameter("rollnumber");

No comments:

Post a Comment