我正在尝试显示来自我的手机的已拨电话记录,并且我获得了成功。但现在的问题是,当我将数据发送到我的getter setter类时,它会显示一些错误,我不知道如何摆脱它。
public class OneFragment extends Fragment {
RecyclerView recyclerView;
public OneFragment() {
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_one, container, false);
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
recyclerView = (RecyclerView) getView().findViewById(R.id.fragRecycler1);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(linearLayoutManager);
getDialledList();
}
private void getDialledList() {
List<CallList> callList = new ArrayList();
CallList logList;
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
ContentResolver cR = getActivity().getContentResolver();
if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
Cursor cursor = cR.query(CallLog.Calls.CONTENT_URI, null, null, null, strOrder, null);
//managedQuery(CallLog.Calls.CONTENT_URI,null,null,null,strOrder);
int phName = cursor.getColumnIndex(CallLog.Calls.CACHED_NAME);
int phNumber = cursor.getColumnIndex(CallLog.Calls.NUMBER);
int phType = cursor.getColumnIndex(CallLog.Calls.TYPE);
int phDate = cursor.getColumnIndex(CallLog.Calls.DATE);
int phDuration = cursor.getColumnIndex(CallLog.Calls.DURATION);
while (cursor.moveToNext()) {
String name = cursor.getString(phName);
String number = cursor.getString(phNumber).toString();
String date = cursor.getString(phDate);
Date callDate = new Date(Long.valueOf(date));
String duration = cursor.getString(phDuration);
String type = cursor.getString(phType);
int dircode = Integer.parseInt(type);
//Log.e(String.valueOf(getActivity()),"Values :" +temp);
if(dircode == 1){
logList = new CallList();
callList.add(number); //getting java.lang.string error here
}
RecyclerAdapter1 recyclerAdapter1 = new RecyclerAdapter1(callList,getContext());
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(recyclerAdapter1);
}
cursor.close();
//callList.add(logList);
}
}
答案 0 :(得分:0)
您要将number
String
添加到callList
ArrayList<CallList>
。如果您只关心号码,请将其更改为ArrayList<String>
,或callList.add(logList)
logList
是CallList
对象