gpt4 book ai didi

Android:无法检测拨出号码

转载 作者:太空狗 更新时间:2023-10-29 13:38:22 25 4
gpt4 key购买 nike

我无法检测到什么是去电号码,当我尝试从设备拨出电话时,它总是给我空指针异常。我想检测拨出的电话号码。请指教,我尝试搜索解决方案,但无法使其工作。此行出现空指针异常 -> Log.i("OutgoingCallReceiver",phonenumber);

12-07 16:10:50.576: ERROR/AndroidRuntime(3145): Caused by: java.lang.NullPointerException: println needs a message
12-07 16:10:50.576: ERROR/AndroidRuntime(3145): at android.util.Log.println_native(Native Method)
12-07 16:10:50.576: ERROR/AndroidRuntime(3145): at android.util.Log.i(Log.java:143)
12-07 16:10:50.576: ERROR/AndroidRuntime(3145): at com.cwc.OutgoingCallReceiver.onReceive(OutgoingCallReceiver.java:27)
12-07 16:10:50.576: ERROR/AndroidRuntime(3145): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
12-07 16:10:50.576: ERROR/AndroidRuntime(3145): ... 10 more

这是我的类文件

public class OutgoingCallReceiver extends BroadcastReceiver {


// private static final String INTENT_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER";

@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();

if(null == bundle)
return;


String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

Log.i("OutgoingCallReceiver",phonenumber);
Log.i("OutgoingCallReceiver",bundle.toString());

String info = "Detect Calls sample application\nOutgoing number: " + phonenumber;

Toast.makeText(context, info, Toast.LENGTH_LONG).show();
}
}

我在 list 文件中有以下条目

    <receiver android:name=".OutgoingCallReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>

</application>

<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.READ_CONTACTS" />

最佳答案

已解决,我缺少“android.permission.PROCESS_OUTGOING_CALLS”用户权限。现在可以使用了,这是我更新后的 list 文件。

关于Android:无法检测拨出号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8422927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com