Android 上无法接收短信(进程错误)

发布于 2024-12-12 01:39:06 字数 3281 浏览 0 评论 0原文

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

CatLog

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 的一个文件。

清单:

<?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);
    }
}

我从设备中清理了所有相关应用程序,这并没有帮助,卸载它,重新启动设备等等。

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

谢谢

I have tried many (if not all...) Receive SMS examples, but it always failed before even onReceive() is called.

The CatLog:

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

When implemented alongside another BroadcastReceiver android.intent.action.PHONE_STATE, the later is being called and was working perfectly well while the SMS failed.

To simplify it I just created the hello example and updates to the manifest and one file for the SMS BroadcastReceiver.

The manifest:

<?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>

The BroadcastReceiver

    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: No changes to the generated code

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);
    }
}

It did not help that I cleaned up all related apps from the device, uninstalled it, rebooted the device, etc, etc.

Any advice or a tip will be greatly appreciated!

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随心而道 2024-12-19 01:39:07

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

You need to make the Receiver as static if you are registering it in the AndroidManifest file.
and if the receiver is not static then you need to register through code. please do above things it will show some positive result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文