我在HTML中使用paw服务器和bean shell脚本以JSON形式返回数据我不知道从脚本中获取任何数据而我无法调试脚本。
这是代码
<bsh>
import android.net.Uri;
import android.provider.Contacts.People;
import android.provider.Contacts.Phones;
import java.text.DateFormat;
service = server.props.get("serviceContext");
delete = parameters.get("delete");
SMS_CONTENT_URI = Uri.parse("content://sms");
// ArrayList for thread information
listThreads = new ArrayList();
URI = Uri.parse("content://sms");
// --- Thread IDs
cur = service.getContentResolver().query(URI, new String[] {"DISTINCT thread_id"}, null, null, "date DESC");
threadIDs = new ArrayList();
if(cur.moveToFirst()) {
do {
threadIDs.add(cur.getInt(0));
} while(cur.moveToNext());
}
cur.close();
print("[");
//--- Get infos
Integer it = 0;
for(id : threadIDs) {
// ArrayList for this thread information
listThreadInfo = new ArrayList();
/* List content
0: Thread ID (int)
1: Address (String)
2: Name (might be null) (String)
3: Contact ID (might be 0) (int)
4: Date (Date)
5: Messages in Thread (int)
6: Body (String)
7: Unread messages (int)
*/
// -- Messages in thread
cur = service.getContentResolver().query(URI, new String[] { "COUNT(thread_id)" }, "thread_id=?", new String[] { "" + id }, null);
cur.moveToFirst();
count = cur.getInt(0);
cur.close();
// -- Unread messages
cur = service.getContentResolver().query(URI, new String[] { "COUNT(read)" }, "thread_id=? AND read == 0", new String[] { "" + id }, null);
cur.moveToFirst();
unread = cur.getInt(0);
cur.close();
cur = service.getContentResolver().query(URI, null, "thread_id=?", new String[] { "" + id }, "date DESC LIMIT 1");
if(cur.moveToFirst()) {
do {
contactId = cur.getInt(cur.getColumnIndex("person"));
address = cur.getString(cur.getColumnIndex("address"));
date = new Date(cur.getLong(cur.getColumnIndex("date")));
body = cur.getString(cur.getColumnIndex("body"));
// Only if address != null. Otherwise it's a DRAFT
if(address != null) {
name = null;
phones = service.getContentResolver().query(
android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String[] { android.provider.ContactsContract.CommonDataKinds.Phone.RAW_CONTACT_ID },
android.provider.ContactsContract.CommonDataKinds.Phone.NUMBER + "=?", new String[] { address }, null
);
if(phones.moveToFirst()) {
contactId = phones.getInt(0);
}
phones.close();
if(contactId != 0) {
contact = service.getContentResolver().query(
android.provider.ContactsContract.Data.CONTENT_URI, new String[]{android.provider.ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME },
android.provider.ContactsContract.Data.RAW_CONTACT_ID + "=? AND " +
android.provider.ContactsContract.CommonDataKinds.StructuredName.MIMETYPE + "=?", new String[] { "" + contactId, android.provider.ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE }, null
);
if(contact.moveToFirst()) {
name = contact.getString(0);
}
contact.close();
}
listThreadInfo.add(0, id);
listThreadInfo.add(1, address);
listThreadInfo.add(2, name);
listThreadInfo.add(3, contactId);
listThreadInfo.add(4, date);
listThreadInfo.add(5, count);
listThreadInfo.add(6, body);
listThreadInfo.add(7, unread);
body = body.replace("\n", "<br>").replace("\t", " ").replace("\"", "\\\"");
print("{");
print("\t\"id\" : " + id + ",");
print("\t\"addr\" : \"" + address + "\",");
print("\t\"name\" : \"" + name + "\",");
print("\t\"contactId\" : " + contactId+ ",");
print("\t\"date\" : " + date.getTime() + ",");
print("\t\"count\" : " + count + ",");
print("\t\"body\" : \"" + body + "\",");
print("\t\"img\" : \"graphics/seeContactImg.xhtml?contactId=" + contactId + "\",");
print("\t\"unread\" : " + unread);
print("}");
it++;
if(it < threadIDs.size()) {
print(",");
}
listThreads.add(listThreadInfo);
}
} while(cur.moveToNext());
}
cur.close();
}
print("]");
</bsh>
以下代码以json格式返回sms。它有一些错误,但我无法调试,因为它是用.xhtml格式编写的
答案 0 :(得分:0)
刚刚在运行Android 6.0的LG G4上测试过,它运行正常。 如果有异常,它将显示在页面源中。 要获得更详细的错误消息,您可以使用 conf / handler.xml 配置文件中BeanShell处理程序的 debug 参数:
<handler status="active">
<name>BeanShell Handler</name>
<description>BeanShell Handler</description>
<removable>true</removable>
<id>bsh</id>
<files />
<params>
<param name="bsh.class" value="org.paw.handler.BeanShellFileHandler" />
<param name="bsh.debug" value="true" />
<param name="bsh.root" value="[PAW_HOME]/html" />
<param name="bsh.suffix" value=".xhtml" />
<param name="bsh.default" value="index.xhtml" />
</params>
</handler>