Dealt with a rather vague "Parse error" on an Android 2.1 device when trying to install an app (.apk file)
Not a lot of helpful write-ups for this online.
After some debugging and a lot of trial and error, the error appears to be related to the minSdkVersion in the manifest file.
If the manifest file specifies: uses-sdk minsdkversion="8", and the device is an SDK lower than Android 2.2, you will get a parse error on install, even if the app in question is built on a lower SDK.
The process typically used in Eclipse to build a signed apk of a lower SDK compatibility is as follows:
1) CREATE a new Eclipse Android project "foo_" with an older Build Target, generally recommended for compatibility with older devices is API 4 (Android 1.6)
2) IMPORT the "src" and "res" files from "foo" into the "foo_" project, as well as the manifest.xml file, which is needed to specific permissions, activity definitions, etc.
3) EXPORT the apk file using Eclipse and sign the apk (a zip file)
BUT there's a crucial step 2.5, to change uses-sdk minsdkversion="8" to uses-sdk minsdkversion="4" to avoid the parse error. The "8" is assumed when the Build Target is API 8 (Android 2.2).
That's it, now could the Android team come up with a less opaque error msg for this sort of error condition???
Wednesday, September 8, 2010
Monday, September 6, 2010
Journal Entries continued...
New forms ("intents") for health journal entries: Meals, Exercise, check it out...
Used Android date-picker, which isn't as nice as a calendar selection pop-up but will suffice...
Date conversion from Android (M-d-yyyy) to Keas (MM/dd/yyyy) was a minor but necessary chore:
SimpleDateFormat inputDate = new SimpleDateFormat("M-d-yyyy"); SimpleDateFormat putDate = new SimpleDateFormat("MM/dd/yyyy");
Date _date = null;
try {
_date = inputDate.parse(the_date);
} catch (ParseException e1) {
System.out.println("Error parsing date:"+the_date);
e1.printStackTrace();
_date = new Date();
}
the_date = putDate.format(_date); // PUT format
Download signed apk here (try test user name:jim pw:jim)
Download Eclipse project here.
Enjoy.
Used Android date-picker, which isn't as nice as a calendar selection pop-up but will suffice...
Date conversion from Android (M-d-yyyy) to Keas (MM/dd/yyyy) was a minor but necessary chore:
SimpleDateFormat inputDate = new SimpleDateFormat("M-d-yyyy"); SimpleDateFormat putDate = new SimpleDateFormat("MM/dd/yyyy");
Date _date = null;
try {
_date = inputDate.parse(the_date);
} catch (ParseException e1) {
System.out.println("Error parsing date:"+the_date);
e1.printStackTrace();
_date = new Date();
}
the_date = putDate.format(_date); // PUT format
Download signed apk here (try test user name:jim pw:jim)
Download Eclipse project here.
Enjoy.
Saturday, August 14, 2010
Android Intents
In extending an application to multiple Activities, one realizes that the Android environment is like a mini-MOM (Message Oriented Middleware) setup. Activities can message and transport data (explicitly or implicitly) between each other by the use of Intent functions.
The simplest example of data passing is one where data is returned from a sub-activity to its caller. To return data from a sub-activity to it's caller, on finishing it can do something like:
Intent i = new Intent(this, Caller.class); // note the use of Caller.class
i.putExtra("returnKey","Sub-Activity Data"); // a named piece of data
setResult(RESULT_OK, i);
finish();
The caller then get's the data (in a loosely coupled way) with:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
super.onActivityResult(requestCode, resultCode, intent);
Bundle extras = intent.getExtras();
System.out.println(extras != null ? extras.getString("returnKey"):"nothing returned");
}
What's interesting and unintuitive about this is the sub-activity's instantiation of a new Intent with the caller's class to set the data. Would have assumed instead that the caller's Intent object be somehow retrieved from it's sub-activity. Of course in other cases the messaging is between activities that do not have a calling rapport.
The official Intent examples are here.
The simplest example of data passing is one where data is returned from a sub-activity to its caller. To return data from a sub-activity to it's caller, on finishing it can do something like:
Intent i = new Intent(this, Caller.class); // note the use of Caller.class
i.putExtra("returnKey","Sub-Activity Data"); // a named piece of data
setResult(RESULT_OK, i);
finish();
The caller then get's the data (in a loosely coupled way) with:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
super.onActivityResult(requestCode, resultCode, intent);
Bundle extras = intent.getExtras();
System.out.println(extras != null ? extras.getString("returnKey"):"nothing returned");
}
What's interesting and unintuitive about this is the sub-activity's instantiation of a new Intent with the caller's class to set the data. Would have assumed instead that the caller's Intent object be somehow retrieved from it's sub-activity. Of course in other cases the messaging is between activities that do not have a calling rapport.
The official Intent examples are here.
Thursday, July 22, 2010
Journal entries
Updated Android Keas app to handle journals (a.k.a. Observations of Daily Living, or "ODLs"), Meals, Exercise, Mood.
To do this added machinery to process 2D dataTable data from Keas API, and evolved ExpandableListView to show 2nd row for journal data, sorted chronologically starting with most recent entry.
The displayed columns and 'Name' column are specified in the loadData method, example:
loadAPIdata(username,password,"keas.apitest",
"odl_exercise.*","Exercise", true, "odl_exercise.name",
"odl_exercise.date,odl_exercise.intensityname,...");
Download signed apk here (try test user name:jim pw:jim)
Download Eclipse project here. Enjoy.
To do this added machinery to process 2D dataTable data from Keas API, and evolved ExpandableListView to show 2nd row for journal data, sorted chronologically starting with most recent entry.
The displayed columns and 'Name' column are specified in the loadData method, example:
loadAPIdata(username,password,"keas.apitest",
"odl_exercise.*","Exercise", true, "odl_exercise.name",
"odl_exercise.date,odl_exercise.intensityname,...");
Download signed apk here (try test user name:jim pw:jim)
Download Eclipse project here. Enjoy.
Friday, July 9, 2010
Porting Android code to Google App Engine /J
One of the advantages of working in Java on Android is much of the back-end code can be transported to Google App Engine/Java (GAE/J) without much effort. This is quite nice as one can rev/iterate/test backend code quickly on GAE/J and then move it to Android once solid. It's also nice as one can remain in the same frame of mind while coding front and backend.
In the case of Keas API code for Android, the backend is comprised mostly for API calls and XML processing. Most of the code remains consistent between Android and GAE/J, with some subtle differences in 'framing' and underlying class assumptions.
You can see the Keas API application on GAE/J here: http://keasapi.appspot.com
The Elipse project files can be found here.
Here is one example, establishing an http connection, note the differences in http class interfaces and the details of setting header data.
Http connection from within Android:
public void getData(String username, String password, String partnerId,
String namespace) {
try {
HttpGet get = new HttpGet("https://preview.keas.com/rest/api/getdata?query="+namespace);
get.setHeader(new BasicHeader("username", username));
get.setHeader(new BasicHeader("password", password));
get.setHeader(new BasicHeader("partnerId", partnerId));
HttpResponse response = client.execute(get);
if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"), 1024);
XmlPullParserFactory xppFact = XmlPullParserFactory.newInstance();
xppFact.setNamespaceAware(true);
XmlPullParser xpp = xppFact.newPullParser();
...
Http connection from GAE/J servlet:
private void getData(HttpServletResponse resp, String uid, String pw, String query) {
try {
URL url = new URL("https://preview.keas.com/rest/api/getdata?query="+query);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("username", uid);
connection.setRequestProperty("password", pw);
connection.setRequestProperty("partnerId", "keas.apitest");
connection.connect();
Object content=connection.getContent();
if (content instanceof InputStream || content instanceof Reader) {
XmlPullParserFactory xppFact = XmlPullParserFactory.newInstance();
xppFact.setNamespaceAware(true);
XmlPullParser xpp = xppFact.newPullParser();
...
In the case of Keas API code for Android, the backend is comprised mostly for API calls and XML processing. Most of the code remains consistent between Android and GAE/J, with some subtle differences in 'framing' and underlying class assumptions.
You can see the Keas API application on GAE/J here: http://keasapi.appspot.com
The Elipse project files can be found here.
Here is one example, establishing an http connection, note the differences in http class interfaces and the details of setting header data.
Http connection from within Android:
public void getData(String username, String password, String partnerId,
String namespace) {
try {
HttpGet get = new HttpGet("https://preview.keas.com/rest/api/getdata?query="+namespace);
get.setHeader(new BasicHeader("username", username));
get.setHeader(new BasicHeader("password", password));
get.setHeader(new BasicHeader("partnerId", partnerId));
HttpResponse response = client.execute(get);
if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"), 1024);
XmlPullParserFactory xppFact = XmlPullParserFactory.newInstance();
xppFact.setNamespaceAware(true);
XmlPullParser xpp = xppFact.newPullParser();
...
Http connection from GAE/J servlet:
private void getData(HttpServletResponse resp, String uid, String pw, String query) {
try {
URL url = new URL("https://preview.keas.com/rest/api/getdata?query="+query);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("username", uid);
connection.setRequestProperty("password", pw);
connection.setRequestProperty("partnerId", "keas.apitest");
connection.connect();
Object content=connection.getContent();
if (content instanceof InputStream || content instanceof Reader) {
XmlPullParserFactory xppFact = XmlPullParserFactory.newInstance();
xppFact.setNamespaceAware(true);
XmlPullParser xpp = xppFact.newPullParser();
...
Monday, June 21, 2010
Keas Droid v0.9
v0.9 KeasDroid project, an Android app using the Keas API to show Health Profile data and color indicators.
Features:
Download signed apk here (try test user name:jim pw:jim)
Download Eclipse project here. Enjoy.
Features:
- Username/password stores as Android preferences
- Color coded indicators for Health profile attributes
- Progress bar during data load
- Direct to Keas API, on-board XML parsing, no additional middleware
Download signed apk here (try test user name:jim pw:jim)
Download Eclipse project here. Enjoy.
Saturday, June 19, 2010
Toast
Toast is quite a useful and compact widget class to provide a temporal notification for the user.
Toast.makeText(KeasDroid.this,
"Here you can maintain your user credentials.", Toast.LENGTH_LONG).show();
This is the equivalent of a modal dialog box, a timer and a dismiss of the dialog. There doesn't appear to be a reasonable way of prolonging the length of display beyond a few secs.
To notify on the status bar requires more work, here's a simple example:
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager)
getSystemService(ns);
int icon = R.drawable.icon;
CharSequence tickerText = "Click Menu to set username";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "Keas notification";
CharSequence contentText = "Please click Menu to set username";
Intent notificationIntent = new Intent(this, KeasDroid.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);
final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
Toast.makeText(KeasDroid.this,
"Here you can maintain your user credentials.", Toast.LENGTH_LONG).show();
This is the equivalent of a modal dialog box, a timer and a dismiss of the dialog. There doesn't appear to be a reasonable way of prolonging the length of display beyond a few secs.
To notify on the status bar requires more work, here's a simple example:
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager)
getSystemService(ns);
int icon = R.drawable.icon;
CharSequence tickerText = "Click Menu to set username";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "Keas notification";
CharSequence contentText = "Please click Menu to set username";
Intent notificationIntent = new Intent(this, KeasDroid.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);
final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
Subscribe to:
Posts (Atom)