2 miaoyunzexiaobao miaoyunzexiaobao 于 2014.12.06 00:28 提问

Android获取未接来电失败

通过点击按钮获取为借来电的信息,并以对话框形式显示未接来电的号码。虚拟机中测试通过,但在真机上运行时会直接强制退出。
代码:

@Override
            public void onClick(View v) {
                final String[] projection = null;
                final String selection = null;
                final String[] selectionArgs = null;
                final String sortOrder = android.provider.CallLog.Calls.DATE + " DESC";
                Cursor cursor = null;
                try {
                    cursor = getContentResolver().query(
                            Uri.parse("content://call_log/calls"), projection,
                            selection, selectionArgs, sortOrder);
                    while (cursor.moveToNext()) {
                        String callLogID = cursor.getString(cursor
                                .getColumnIndex(android.provider.CallLog.Calls._ID));
                        String callNumber = cursor.getString(cursor
                                .getColumnIndex(android.provider.CallLog.Calls.NUMBER));
                        String callDate = cursor.getString(cursor
                                .getColumnIndex(android.provider.CallLog.Calls.DATE));
                        String callType = cursor.getString(cursor
                                .getColumnIndex(android.provider.CallLog.Calls.TYPE));
                        String isCallNew = cursor.getString(cursor
                                .getColumnIndex(android.provider.CallLog.Calls.NEW));
                        if (Integer.parseInt(callType) == (CallLog.Calls.MISSED_TYPE)
                                && Integer.parseInt(isCallNew) > 0) {
                            Toast.makeText(getApplication(),
                                    "Missed Call Found: " + callNumber,
                                    Toast.LENGTH_SHORT).show();
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                finally {
                    cursor.close();
                }
            } 

权限列表中添加的权限为:

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!