aaa díky díky, opravíme ...
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu private void callLocus() {
ByteArrayOutputStream baos = null;
DataOutputStream dos = null;
try {
baos = new ByteArrayOutputStream();
dos = new DataOutputStream(baos);
// version
dos.writeInt(2);
// write objects names
dos.writeUTF("Points from my application");
// write category count - here I write three categories. Categories are defined as
// array of points that share same map icon!
dos.writeInt(3);
// write categories
writeCategory(dos);
writeCategory(dos);
writeCategory(dos);
// flush data to output stream
dos.flush();
// create intent with right calling method
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("menion.points:extraDataSomeName"));
// here put data into intent
intent.putExtra("extraDataSomeName", baos.toByteArray());
// finally start activity
startActivity(intent);
} catch (Exception e) {
Log.e(TAG, "callLocus()", e);
} finally {
try {
if (baos != null) {
baos.close();
baos = null;
}
if (dos != null) {
dos .close();
dos = null;
}
} catch (Exception e) {
// catch not needed
}
}
}
private void writeCategory(DataOutputStream dos) {
try {
// convert resource to byte array
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_gc_wherigo);
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2);
byte[] image = baos2.toByteArray();
baos2.close();
// write image data or size '0' and no data if use default image of Locus (currently just red dot)
- so if you want write image use this
dos.writeInt(image.length); // image size
dos.write(image); // image data
- and if you don't want use only this
dos.writeInt(0);
// write all points now
int pointCount = 1000;
dos.writeInt(pointCount);
for (int i = 0; i < pointCount; i++) {
// write item name
dos.writeUTF("name_" + (i + 1));
// write item description
dos.writeUTF("some description with <html>tags</html>!");
// extra values (describe below - optional)
dos.writeUTF("");
// write latitude
dos.writeDouble(50.0 + 0.01 * i);
// write longitude
dos.writeDouble(14.0 + 0.01 * i);
}
} catch (Exception e) {
Log.e(TAG, "writeCategory()", e);
}
}