我试图在Android Studio中实施一些虚假的通话记录。当我在安装了应用程序的情况下运行模拟器时,它首先说Launcher 3已经停止工作,然后当我点击添加呼叫日志按钮时,它说“不幸的是,callLog应用程序已经停止工作”#39;我想我可能需要解析器if if statement中的内容,它以红色突出显示并显示需要用户权限的提示。主要活动类的代码是:
package com.example.calllogexample;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;
import android.provider.CallLog;
import android.util.Log;
public class CallLogActivity {
public void AddNumToCallLog(ContentResolver resolver ,String strNum, int type, long timeInMiliSecond) {
while (strNum.contains("-")) {
strNum = strNum.substring(0, strNum.indexOf('-')) + strNum.substring(strNum.indexOf('-') + 1, strNum.length());
}
ContentValues values = new ContentValues();
values.put(CallLog.Calls.NUMBER, strNum);
values.put(CallLog.Calls.DATE, timeInMiliSecond);
values.put(CallLog.Calls.DURATION, 0);
values.put(CallLog.Calls.TYPE, type);
values.put(CallLog.Calls.NEW, 1);
values.put(CallLog.Calls.CACHED_NAME, "");
values.put(CallLog.Calls.CACHED_NUMBER_TYPE, 0);
values.put(CallLog.Calls.CACHED_NUMBER_LABEL, "");
Log.d("AddToCallLog", "Inserting call log placeholder for " + strNum);
if (null != resolver) {
resolver.insert(CallLog.Calls.CONTENT_URI, values);
}
}
public void DeleteNumFromCallLog(ContentResolver resolver, String strNum) {
try {
String strUriCalls = "content://call_log/calls";
Uri UriCalls = Uri.parse(strUriCalls);
if (null != resolver) {
resolver.delete(UriCalls, CallLog.Calls.NUMBER + "=?", new String[]{strNum});
}
} catch (Exception e) {
e.getMessage();
}
}
}
答案 0 :(得分:0)
在清单标记
下的清单文件中写入权限<uses-permission android:name="android.permission.READ_CALL_LOG" />