I can't figure out how to use the built-in Uri stuff to build Uris
that will work in the Google Maps interface.
Here's my program:
----
package com.eyebrowsoftware.example;
import java.util.LinkedList;
import android.app.ListActivity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class UriFun extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinkedList<String> outList = new LinkedList<String>();
// using Uri.parse
Uri uri = Uri.parse("geo:0,0");
outList.add("Uri.parse: " + uri.toString());
uri = uri.buildUpon().appendQueryParameter("q", "street
+address").build();
outList.add("Uri.parse w/ query: " + uri.toString());
// using the Uri.Builder
Uri.Builder b = new Uri.Builder();
b.scheme("geo").opaquePart("0,0");
outList.add("Builder w/ opaque part: " + b.build().toString
());
b.appendQueryParameter("q", "street+address");
outList.add("Opaque part w/ query: " + b.build().toString());
// try using Uri.fromParts
uri = Uri.fromParts("geo", "0,0", null);
outList.add("Uri.fromParts: " + uri.toString());
uri = uri.buildUpon().appendQueryParameter("q", "street
+address").build();
outList.add("Uri.fromParts w/ query: " + uri.toString());
String[] sa = {};
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1,
outList.toArray(sa));
this.setListAdapter(aa);
}
}
The output is mostly wrong, in my opinion.
Uri.parse("geo:0,0") produces:
geo:0,0
which is what they say they want in
http://developer.android.com/guide/appendix/g-app-intents.html
when I try to add a query to the above result of Uri.parse, it removes
the "opaque part" of the Uri:
geo:?q=street%2Baddress
So I try building it from scratch using the Uri.Builder and the opaque
part, which produces:
geo:0%2C0
and when I append a query to that, it does the same thing as before:
geo:q=street%2Baddress
So, I tried using Uri.fromParts which produces the same thing the
Builder produces:
geo:0%2C0
and, of course, adding the query munges it, again:
geo:?q=street%2Baddress
I think this is too bad. The Uri stuff has worked for me up to now and
now seems broken with this kind of Uri.
Any suggestions?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en