Reputation: 3135
Given the following Android Java code:
import android.net.Uri;
String humanEnteredString = "google.com";
Uri uri = Uri.parse(humanEnteredString);
Why is uri.getPath() == "google.com"
, and not uri.getAuthority()
?
How to force Uri.parse to see "google.com" as the authority?
Is that what classes like this are for? https://github.com/android/platform_frameworks_base/blob/master/core/java/android/net/WebAddress.java
Why is this WebAddress
class not accessible in the Android SDK?
Is there any pre-built class that can generate a valid <scheme>://<authority><path>
browsable Uri from a human entered string that may be missing the scheme?
Obviously, I can test for and prefix "http[s]://" as necessary/appropriate, but shouldn't there already be a bulletproof class that does this already?
Thanks,
Pv
Upvotes: 0
Views: 676
Reputation: 1006964
Why is uri.getPath() == "google.com", and not uri.getAuthority()?
Because "google.com"
is not a valid Uri
.
How to force Uri.parse to see "google.com" as the authority?
Use a valid Uri
: one with a scheme, such as https://google.com
.
Is there any pre-built class that can generate a valid :// browsable Uri from a human entered string that may be missing the scheme?
Not in the Android SDK, at least that I can recall.
Upvotes: 1