Reputation: 1676
I have both website and android application for the website.when user clicks on a link of my website it opens that up in my android application. But the problem is there is an important information present in the link which i need to fetch and the activity will make a server request upon that. To be precised the link looks like this: www.example.com/post.php?id=123 I need to get the ID part of the link when the activity is opened so that I can show information about posts bearing the ID. I have added the opening of the link in my app with help of intent filter but I am stuck at getting the GET parameter of the link.How to do that?
Upvotes: 0
Views: 29
Reputation: 303
Once your activity is opened via the link, you can retrieve that URL from the intent
like so:
String url = getIntent().getData().toString();
Then you can use .substring
to get the parameters:
String id = url.substring(url.indexOf("id=") + 3)
OR, you can use Airbnb's library to achieve the result in a more elegant way, you can learn about it on their GitHub repo.
Upvotes: 1
Reputation: 4226
myLink = string.substring(string.lastIndexOf('=') + 1);
If the string/url was www.example.com/post.php?id=123
the string will now return 123
.
Upvotes: 1