Simple solution for using Locus as external viewer of points from other applications!
6.7.2011 - This method is DEPRECATED - use new API instead - viewtopic.php?f=29&t=767 (http://forum.asamm.cz/viewtopic.php?f=29&t=767)[s:ounfezv9]
19.4.2011 - New update of calling method - version 2working for version >= 1.5.3simple code example says more then few pages of words (use commentary as helping solution)
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);
}
}
Extra values written in code can be used for extending possibilities which user can do with point
currently supported:Call-back - "
intent;ButtonName;com.super.application;com.super.application.Main;returnData;someStringData"
intent - just identifier
ButtonName - String that shows on button
com.super.application - The name of the package that the component exists in
com.super.application.Main - The name of the class inside of
com.super.application that implements the component.
returnData - String uder which data will be stored. Can be retrieved by
String data = getIntent.getStringExtra("returnData"); someStringData - data stored in intent at
returnData StringExtra place
[/list]
[/list]
Actual application that use this featurec:geo[/s:ounfezv9]
Simple method is to check, if Locus allowed to handle points and is in system ...
use this
public static boolean isLocusAvailable(Activity activity) {
try {
// set intent
final PackageManager packageManager = activity.getPackageManager();
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("menion.points:x"));
// return true or false
return packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
} catch (Exception e) {
return false;
}
}
simple methods are very good. so that everyone can comprehend easliy
+1... I just tried this and it worked perfectly. thanks for sharing this very helpful information. :)
Quote from: "menion"Simple method is to check, if Locus allowed to handle points and is in system ...
use this
public static boolean isLocusAvailable(Activity activity) {
try {
// set intent
final PackageManager packageManager = activity.getPackageManager();
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("menion.points:x"));
// return true or false
return packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
} catch (Exception e) {
return false;
}
}
Las Vegas Show Guide (//http://lasvegas.nyctourist.com/las-vegas-show-guide) Vegas Shows (//http://lasvegas.nyctourist.com/las-vegas-shows.php)
hi,
if you wanna use such features, I highly recommend use Locus API which already include this feature and much more ...