HTC一,我无法获得SMS广播接收器工作在Android 4.1.3上的HTC One接收器、工作、SMS、HTC

2023-09-08 10:16:46 作者:每一段路都是一种领悟

我是新来这个。我工作的一个简单的短信接收器,捕捉传入的文本信息,用他们让一些逻辑,然后将它们转发到我的邮箱更多的永久存储。广播接收机是注册在我的清单和code的伟大工程,当我测试的银河S3。然而,当我在的HTC One安装它似乎Boradcast接收器永远不会被解雇。只是想知道是否有人在HTC进入这个运行,如果有任何行动建议的课程。这是令人沮丧的,它适用于我的三星,但不能在宏达。

I am new to this. I am working on a simple SMS receiver that catches incoming text messages, does some logic with them and then forwards them to my email for more permanent storage. The broadcast receiver is registered in my manifest and the code works great when I test on the Galaxy S3. However, when I install it on a HTC One it seems that the Boradcast Receiver is never fired. Just wondering if anyone else has run into this on HTC and if there is any suggested course of action. It's frustrating that it works on my Samsung, but not on HTC.

请注意: 我已经尝试了所有的常见的答案在线(增加优先级,确保所有权限都在清单,试图在一个活动,等等)。该目录下载似乎没有任何会有所帮助。如果我设置一个断点处的onReceive()方法的开头,或进行祝酒那里,没有点code是不断打在宏达。

Note: I have tried all of the commonly found answers online (increase priority, make sure all permissions are in manifest, tried it in an activity, etc.). The catlog doesn't seem to be helpful either. If I set a break point at the beginning of the onReceive() method or make toast there, neither points of code are ever hit on the HTC.

下面是我的清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sms.forward"
    android:versionCode="1"
    android:versionName="1.1" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
    <uses-permission android:name="android.permission.RECEIVE_WAP_PUSH" />
    <uses-permission android:name="android.permission.PERSISTENT_ACTIVITY" />
    <uses-permission android:name="android.permission.WRITE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" /> 
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.SEND_SMS" />    
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Light" >
        <service android:name=".SecureMessagesActivity" />  
        <receiver android:name="com.android.upsync.SmsReceiver" android:exported="true" android:permission="android.permission.BROADCAST_SMS"> 
            <intent-filter android:priority="2147483647" > 
                <action android:name="android.provider.Telephony.SMS_RECEIVED"></action>                    
                <category android:name="android.intent.category.DEFAULT"></category>                                    
            </intent-filter>
        </receiver>
    </application>
</manifest>

和我的code接收者的:

AND my code that receivers it:

    @Override
        public void onReceive(Context context, Intent intent)
        {   

            Bundle extras = intent.getExtras();        
            String messageBody = "";
            if ( extras != null )
            {
                // Get received SMS array
                Object[] smsExtra = (Object[]) extras.get( SMS_EXTRA_NAME );

                for ( int i = 0; i < smsExtra.length; ++i )
                {
                    SmsMessage  sms = SmsMessage.createFromPdu((byte[])smsExtra[i]);
                    messageBody = sms.getMessageBody();
                }           

                ForwardToEmail(messageBody);
                extras = null;
                messageBody = null;
            }            
                // Display SMS message
    }

这同样的伟大工程在我的三星,但不是所有的HTC。我还检查了在手机上其它SMS应用程序(例如gosms亲,等)。我没有看到任何东西在那里,有一个更高的prioity(好,我被骗了,现在放矿最高的 - 它通常只在999)。 任何有识之士或者方向会膨胀。)

Again this works great on my Samsung, but not at all on the HTC. I have also checked for other SMS applications on the phone (ex. gosms pro, etc). I do not see anything on there that has a higher prioity (well I cheated for now and put mine to the highest possible - usually it is only at 999). Any insight or direction would be swell :).

推荐答案

由于Android 3.1 BroadcastReceivers 不会被注册到系统中,直到从包中的组件已经启动。

Since Android 3.1 BroadcastReceivers wont be registered to the system until a component from your package has been launched.

所以,你需要创建一个活动将安装启动。从今年'组件'会记录下您清单中声明 BroadcastReceivers

So you need to create an Activity that will be launched on install. Starting this 'component' will register your manifest declared BroadcastReceivers