gpt4 book ai didi

android - Android 接收短信失败(进程有问题)

转载 作者:搜寻专家 更新时间:2023-11-01 09:11:35 26 4
gpt4 key购买 nike

我已经尝试了很多(如果不是全部......)接收短信示例,但它总是在调用 onReceive() 之前就失败了。

目录:

10-26 20:05:30.990: INFO/System.out(2714): INFO: Received message
10-26 20:05:30.998: INFO/System.out(2714): INFO: Message body: Lmjgk
10-26 20:05:31.021: WARN/ActivityManager(1317): Unable to launch app org.apache.sms/10166 for broadcast Intent { act=android.provider.Telephony.SMS_RECEIVED (has extras) }: process is bad
10-26 20:05:31.021: WARN/ActivityManager(1317): finishReceiver called but none active

当与另一个 BroadcastReceiver android.intent.action.PHONE_STATE 一起实现时,后者被调用并且在 SMS 失败时运行良好。

为了简化它,我刚刚创建了 hello 示例并更新了 SMS BroadcastReceiver 的 list 和一个文件。

list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.byp.sms" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.byp.sms.SMSReceiver">
<intent-filter>
<action android:name="android.provider.telephony.SMS_RECEIVED"></action>
</intent-filter>
</receiver>
</application>

<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.READ_SMS" />
</manifest>

广播接收器

    package com.byp.sms;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class SMSReceiver extends BroadcastReceiver {

private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";

@Override
public void onReceive(Context context, Intent intent) {
Log.d("SMSReceiver", "onReceive"); // <<=== It does not even get here....
if (intent != null && intent.getAction() != null
&& ACTION.compareToIgnoreCase(intent.getAction()) == 0) {
Object[] pduArray = (Object[]) intent.getExtras().get("pdus");
Log.d("SMSReceiver", "SMSReceived " + pduArray.toString());
}
Log.d("SMSReceiver", "onReceive...Done");
}
}

Hello Activity:生成的代码没有变化

package com.byp.sms;

import android.app.Activity;
import android.os.Bundle;

public class HelloActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

我从设备上清除所有相关应用程序、卸载它、重新启动设备等等都没有帮助。

任何建议或提示将不胜感激!

谢谢

最佳答案

如果要在 AndroidManifest 文件中注册 Receiver,则需要将其设为静态。如果接收器不是静态的,那么您需要通过代码注册。请做上面的事情,它会显示一些积极的结果。

关于android - Android 接收短信失败(进程有问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7911656/

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