2011-10-27 14 views
2

私は(すべてではない...)はSMS例を受け取るが、それは常に(でもonReceive前に失敗した)多くのを試してみましたが呼び出されます。 は、Android上でSMSを受信できませんでした(プロセスが悪い)

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のマニフェストと1つのファイルを更新しました。

マニフェスト:

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

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

ハローアクティビティー:生成されたコード

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を確認する必要があり

おかげ

+0

私はこれと似たようなことをしています! http://stackoverflow.com/questions/14452808/sending-and-receiving-mms-in-android – toobsco42

答えて

3

。 レシーバが静的でない場合は、コードを介して登録する必要があります。それはいくつかの肯定的な結果を示す上記のことをしてください。

+0

あなたの返信ありがとう、私は静的を追加してonReceive()の署名を変更することはできません、あなたは例を助けることができます? – user1015767

+0

あなたのコードは動作しています、ありがとう! – user1015767

+0

おかげです.. ansを受け入れて質問を閉じる –

関連する問題