Reputation: 199
uri.getPathSegments().get(1);
Basically the get(1)
part
Upvotes: 14
Views: 5925
Reputation: 1970
In my tests, calling getPathSegments on the Uri below:
content://example.cs454.sunshine/weather/90015/1463468400000
yielded a List with these contents:
index 0 weather
index 1 90015
index 2 1463468400000
Upvotes: 2
Reputation: 3120
That will return you the path segment with index '1'.
By that, I mean, If you have content://com.myapp/first/second/third/
It will return 'second'.
get(2) will return 'third'
and so on...
Upvotes: 23
Reputation: 20309
You haven't told us what uri's type is but if it is a Uri
object then looking at the Android URI Docs we can see that getPathSegments
returns a List of Strings. Then calling get(1)
returns the 2nd item in the list returned by getPathSegments()
.
The code could be re-written as follows:
List<String> segments = ui.getPathSegments();
String secondItem = segments.get(1);
Upvotes: 1