我正在尝试显示来自通话记录的号码。我的应用程序中有一个按钮,用于将用户重定向到电话的日志活动,当用户选择联系人时,它将显示在主要活动的文本视图中。我已经在清单中添加了对调用日志读取的权限,但是我收到了这个错误:
08-17 16:54:17.113: E/AndroidRuntime(18121): FATAL EXCEPTION: main
08-17 16:54:17.113: E/AndroidRuntime(18121): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.PICK dat=content://call_log/calls }
08-17 16:54:17.113: E/AndroidRuntime(18121): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
08-17 16:54:17.113: E/AndroidRuntime(18121): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1423)
08-17 16:54:17.113: E/AndroidRuntime(18121): at android.app.Activity.startActivityForResult(Activity.java:3388)
08-17 16:54:17.113: E/AndroidRuntime(18121): at android.app.Activity.startActivityForResult(Activity.java:3349)
08-17 16:54:17.113: E/AndroidRuntime(18121): at com.example.callogdemo.MainActivity$1.onClick(MainActivity.java:32)
08-17 16:54:17.113: E/AndroidRuntime(18121): at android.view.View.performClick(View.java:4211)
08-17 16:54:17.113: E/AndroidRuntime(18121): at android.view.View$PerformClick.run(View.java:17446)
08-17 16:54:17.113: E/AndroidRuntime(18121): at android.os.Handler.handleCallback(Handler.java:725)
08-17 16:54:17.113: E/AndroidRuntime(18121): at android.os.Handler.dispatchMessage(Handler.java:92)
08-17 16:54:17.113: E/AndroidRuntime(18121): at android.os.Looper.loop(Looper.java:153)
08-17 16:54:17.113: E/AndroidRuntime(18121): at android.app.ActivityThread.main(ActivityThread.java:5297)
08-17 16:54:17.113: E/AndroidRuntime(18121): at java.lang.reflect.Method.invokeNative(Native Method)
08-17 16:54:17.113: E/AndroidRuntime(18121): at java.lang.reflect.Method.invoke(Method.java:511)
08-17 16:54:17.113: E/AndroidRuntime(18121): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
代码:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setData(android.provider.CallLog.Calls.CONTENT_URI);
startActivityForResult(intent, 0);
}
});
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
String[] callLogFields = { android.provider.CallLog.Calls._ID,
android.provider.CallLog.Calls.NUMBER,
android.provider.CallLog.Calls.CACHED_NAME };
String phoneNumber="Not Selected Yet" ;
Cursor c = managedQuery(intent.getData(), callLogFields, null, null, null);
if(c!=null && c.moveToFirst())
{
phoneNumber=c.getString(c.getColumnIndex(android.provider.CallLog.Calls.NUMBER));
}
c.close();
textview.setText(phoneNumber);
}
答案 0 :(得分:1)
这是因为你根本不能 Android没有提供ACTION_PICK呼叫日志的方法 但您可以使用此解决方法在应用上显示列表。
String[] strFields = { android.provider.CallLog.Calls._ID, android.provider.CallLog.Calls.NUMBER,
android.provider.CallLog.Calls.CACHED_NAME, };
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
final Cursor cursorCall = getActivity().getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI, strFields, null, null,
strOrder);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Select recent contact");
android.content.DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int item) {
cursorCall.moveToPosition(item);
Toast.makeText(getActivity(), cursorCall.getString(cursorCall.getColumnIndex(android.provider.CallLog.Calls.NUMBER)),
Toast.LENGTH_LONG).show();
cursorCall.close();
return;
}
};
builder.setCursor(cursorCall, listener, android.provider.CallLog.Calls.CACHED_NAME);
builder.create().show();
这需要以下许可:
<uses-permission android:name="android.permission.READ_CALL_LOG" />