How to open a file with JSR 211 CHAPI (Content Handler API)
Please note that this is a question about MIDlets, i.e. Java ME (not "ordinary" Java SE).
I'm looking for the correct way to invoke content on a mobile phone using JSR 211, i.e. CHAPI - Content Handler API. I always get to the IOException in the code below. The mobile phone I'm running on supports JSR 211 (it's a Sony Ericsson C902).
doInvoke("file:///e:/jpgimage.jpg"); //earlier in the code
void doInvoke(final String url) {
(new Thread() {
public void run() {
try {
Registry registry = Registry.getRegistry(this.getClass().getName());
Invocation invoc = new Invocation(url);
invoc.setAction(C开发者_运维问答ontentHandler.ACTION_OPEN);
boolean mustExit = registry.invoke(invoc);
if (mustExit) {
notifyDestroyed();
} else {
// stay put
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}).start();
}
Just because a phone supports CHAPI, it doesn't mean it can specifically handle a .jpg file accessed via a Java "file://" URL.
You should only use CHAPI when the phone manufacturer directly confirms that it supports exactly what you are trying to do.
In the case of the C902, you may be better off trying to send the .jpg url (or maybe something that looks more like "/memorycard/jpimage.jpg", i.e. not a Java URL per se) to the Content-Handler-ID of the handset media center.
精彩评论