gpt4 book ai didi

java - Android 未检测到使用短信监听器发送的短信

转载 作者:行者123 更新时间:2023-12-02 05:46:53 26 4
gpt4 key购买 nike

我有以下代码

        <receiver android:name=".SMSListener">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<action android:name="android.provider.Telephony.SMS_SENT"/>
</intent-filter>
</receiver>




public class SMSListener extends BroadcastReceiver
{
private SharedPreferences customSharedPreference;

@Override
public void onReceive(Context context, Intent intent)
{
customSharedPreference = context.getSharedPreferences("UserSharedPrefs", Activity.MODE_PRIVATE);
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED"))
{
Bundle bundle = intent.getExtras(); //---get the SMS message passed in---
SmsMessage[] msgs = null;
if (bundle != null)
{
//---retrieve the SMS message received---
try{
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for(int i=0; i<msgs.length; i++)
{
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
}

Editor editor = customSharedPreference.edit();
editor.putString("lastSmsReceived", String.valueOf(System.currentTimeMillis()));
editor.commit();

}catch(Exception e){
// Log.d("Exception caught",e.getMessage());
}
}
}
else if(intent.getAction().equals("android.provider.Telephony.SMS_SENT"))
{
Editor editor = customSharedPreference.edit();
editor.putString("lastSmsSent", String.valueOf(System.currentTimeMillis()));
editor.commit();
Log.d("SMS Sent", "SMS Sent");
}
}
}

有权限

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

它检测到短信已读,但未检测到短信已发送。我还缺少什么

最佳答案

没有这样的操作android.provider.Telephony.SMS_SENT。 Android 不会广播发送的消息。

这里描述了一种替代解决方案: Android Broadcast Receiver for Sent SMS messages?

关于java - Android 未检测到使用短信监听器发送的短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23980582/

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