问题描述
我刚刚开始用phoneGap和Android。建立基本样本。我想知道,如果有一个API来获取通话记录。我想创建一个网格:
- 一段时间内未接来电的次数
- 已接来电次数
- 拨打电话
- 已接来电和来电的总时间
提前感谢
我做了一些研究,已经成功构建了一个PhoneGap插件,它将从 android.provider.CallLog
中获取CallLog。
这将返回JSON {Rows:[]}
其中行
是一个二维数组的调用记录,其中包含以下字段(如Array)以下顺序:
- 日期(以UNIX时间戳记)
- 数字 $
- 持续时间(以秒为单位)
- 新建
- 缓存名称
- 缓存号码类型
- 缓存号码标签
详细信息位于
我也使用这个插件来显示总共的一个小样本来电次数,未接来电和来电,并将其绘制在饼图中。该示例正在使用FusionCharts的饼图。
您可以从以下网址下载测试版.apk:
(使用Android版本3或更高版本的JavaScript SVG图表)
以下是源代码压缩文件,您可以深入了解:
http://www.sudipto.net/download/android/apps/CallLog/beta/calllog_phonegap_eclipseclassic_source.zip
以下是我的完整代码:
CallLog.java
package com.fusioncharts.phonegap.plugin;
import org.json。*;
import android.database。*;
import android.util.Log;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import com.phonegap.api.PluginResult.Status;
public class CallLog extends Plugin {
@Override
public PluginResult execute(String actionName,JSONArray arguments,String callback)
{
JSONObject callLogs = new JSONObject();
PluginResult result = null;
try {
switch(getActionItem(actionName))
{
案例1:
callLogs = getAllCallLog(arguments);
result = new PluginResult(Status.OK,callLogs);
break;
default:
result = new PluginResult(Status.INVALID_ACTION);
}
} catch(JSONException jsonEx){
result = new PluginResult(Status.JSON_EXCEPTION);
}
返回结果;
}
私有JSONObject getAllCallLog(JSONArray要求)throws JSONException
{
JSONObject callLog = new JSONObject();
String [] strFields = {
android.provider.CallLog.Calls.DATE,
android.provider.CallLog.Calls.NUMBER,
android.provider。 C# $ b android.provider.CallLog.Calls.CACHED_NUMBER_TYPE,
android.provider.CallLog.Calls.CACHED_NUMBER_LABEL //,
};
try {
Cursor callLogCursor = ctx.getContentResolver()。query(
android.provider.CallLog.Calls.CONTENT_URI,
strFields,
null ,
null,
android.provider.CallLog.Calls.DEFAULT_SORT_ORDER
);
int callCount = callLogCursor.getCount();
if(callCount> 0){
JSONArray callLogItem = new JSONArray();
JSONArray callLogItems = new JSONArray();
String [] columnNames = callLogCursor.getColumnNames();
callLogCursor.moveToFirst();
do
{
callLogItem.put(callLogCursor.getLong(0));
callLogItem.put(callLogCursor.getString(1));
callLogItem.put(callLogCursor.getInt(2));
callLogItem.put(callLogCursor.getLong(3));
callLogItem.put(callLogCursor.getInt(4));
callLogItem.put(callLogCursor.getString(5));
callLogItem.put(callLogCursor.getInt(6));
callLogItems.put(callLogItem);
callLogItem = new JSONArray();
} while(callLogCursor.moveToNext());
callLog.put(Rows,callLogItems);
}
callLogCursor.close();
} catch(Exception e)
{
Log.d(CallLog_Plugin,ERROR:SQL to get cursor:ERROR+ e.getMessage());
}
return callLog;
}
私有JSONObject getTimeRangeCallLog(JSONArray要求)
{
private int getActionItem(String actionName)throws JSONException
{
JSONObject actions = new JSONObject({'all':1,'last':2,'time':3});
if(actions.has(actionName))
return actions.getInt(actionName);
return 0;
}
}
calllog.phonegap.js
var CallLog = function(){};
CallLog.prototype.all = function(params,successCallback,failureCallback)
{
return PhoneGap.exec(successCallback,failureCallback,'CallLog','all',[params]);
};
PhoneGap.addConstructor(function(){
PhoneGap.addPlugin(calllog,new CallLog());
PluginManager.addService(CallLog,com.fusioncharts .phonegap.plugin.CallLog);
});
Application.java
var CallLog = function(){};
CallLog.prototype.all = function(params,successCallback,failureCallback)
{
/ * @param successCallback
* @param failureCallback
* @param插件名称
* @param action
* @param参数的JSONArray
* /
返回PhoneGap.exec(successCallback,failureCallback,'CallLog','all',[params]);
};
PhoneGap.addConstructor(function(){
//使用PhoneGap注册JavaScript插件
PhoneGap.addPlugin(calllog,新的CallLog());
//使用PhoneGap
PluginManager.addService(CallLog,com.fusioncharts.phonegap.plugin.CallLog);
})注册本机插件类;
I have just started with phoneGap and Android. Built basic samples.
I would like to know, if there is an API to get the call logs. I wish to create a grid showing:
- Number of missed calls over a period of time
- Number of received calls
- Number of calls made
- Total time of the received calls and calls made
Thanks in advance.
I did a bit of research and has successfully built a PhoneGap plugin which would fetch the CallLog from android.provider.CallLog
.
This returns an JSON { Rows: [] }
where Rows
is an 2 dimensional array of call records containing the following fields (as Array) in the following order :
- Date (as UNIX Time stamp)
- Number,
- Type (1- incoming, 2- outgoing, 3- missed)
- Duration (in seconds)
- New
- Cached Name
- Cached number type
- Cached number label
Details are in http://developer.android.com/reference/android/provider/CallLog.Calls.html
I have also made a small sample using this plugin which would show total number of outgoing calls, missed calls and incoming calls and plot them in a Pie chart. The sample is using FusionCharts' Pie chart.
You can download a beta try-out .apk from :
http://www.sudipto.net/download/android/apps/CallLog/beta/CallChart.apk.zip
(using JavaScript SVG charts that works in Android version 3 or above)
Here is the source-code zip for you to delve into:
http://www.sudipto.net/download/android/apps/CallLog/beta/calllog_phonegap_eclipseclassic_source.zip
Here is my complete code:
CallLog.java
package com.fusioncharts.phonegap.plugin;
import org.json.*;
import android.database.*;
import android.util.Log;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import com.phonegap.api.PluginResult.Status;
public class CallLog extends Plugin {
@Override
public PluginResult execute(String actionName, JSONArray arguments, String callback)
{
JSONObject callLogs = new JSONObject();
PluginResult result = null;
try {
switch (getActionItem(actionName))
{
case 1:
callLogs = getAllCallLog(arguments);
result = new PluginResult(Status.OK, callLogs);
break;
default:
result = new PluginResult(Status.INVALID_ACTION);
}
} catch (JSONException jsonEx) {
result = new PluginResult(Status.JSON_EXCEPTION);
}
return result;
}
private JSONObject getAllCallLog(JSONArray requirements) throws JSONException
{
JSONObject callLog = new JSONObject();
String[] strFields = {
android.provider.CallLog.Calls.DATE,
android.provider.CallLog.Calls.NUMBER,
android.provider.CallLog.Calls.TYPE,
android.provider.CallLog.Calls.DURATION,
android.provider.CallLog.Calls.NEW,
android.provider.CallLog.Calls.CACHED_NAME,
android.provider.CallLog.Calls.CACHED_NUMBER_TYPE,
android.provider.CallLog.Calls.CACHED_NUMBER_LABEL//,
};
try {
Cursor callLogCursor = ctx.getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI,
strFields,
null,
null,
android.provider.CallLog.Calls.DEFAULT_SORT_ORDER
);
int callCount = callLogCursor.getCount();
if(callCount>0){
JSONArray callLogItem = new JSONArray();
JSONArray callLogItems = new JSONArray();
String[] columnNames = callLogCursor.getColumnNames();
callLogCursor.moveToFirst();
do
{
callLogItem.put(callLogCursor.getLong(0));
callLogItem.put(callLogCursor.getString(1));
callLogItem.put(callLogCursor.getInt(2));
callLogItem.put(callLogCursor.getLong(3));
callLogItem.put(callLogCursor.getInt(4));
callLogItem.put(callLogCursor.getString(5));
callLogItem.put(callLogCursor.getInt(6));
callLogItems.put(callLogItem);
callLogItem = new JSONArray();
}while(callLogCursor.moveToNext());
callLog.put("Rows", callLogItems);
}
callLogCursor.close();
}catch(Exception e)
{
Log.d("CallLog_Plugin", " ERROR : SQL to get cursor: ERROR " + e.getMessage());
}
return callLog;
}
private JSONObject getTimeRangeCallLog(JSONArray requirements)
{
private int getActionItem(String actionName) throws JSONException
{
JSONObject actions = new JSONObject("{'all':1,'last':2,'time':3}");
if (actions.has(actionName))
return actions.getInt(actionName);
return 0;
}
}
calllog.phonegap.js
var CallLog = function() {};
CallLog.prototype.all = function(params, successCallback, failureCallback)
{
return PhoneGap.exec(successCallback, failureCallback, 'CallLog', 'all', [params]);
};
PhoneGap.addConstructor( function() {
PhoneGap.addPlugin("calllog", new CallLog());
PluginManager.addService("CallLog","com.fusioncharts.phonegap.plugin.CallLog");
});
Application.java
var CallLog = function() {};
CallLog.prototype.all = function(params, successCallback, failureCallback)
{
/* @param successCallback
* @param failureCallback
* @param plugin name
* @param action
* @param JSONArray of parameters
*/
return PhoneGap.exec(successCallback, failureCallback, 'CallLog', 'all', [params]);
};
PhoneGap.addConstructor( function() {
//Register the javascript plugin with PhoneGap
PhoneGap.addPlugin("calllog", new CallLog());
//Register the native class of plugin with PhoneGap
PluginManager.addService("CallLog","com.fusioncharts.phonegap.plugin.CallLog");
});
这篇关于PhoneGap API查询呼叫日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!