1

私は現在、 を使用しbroadcastreceiverて着信テキスト メッセージをチェックするアプリに取り組んでいますが、突然動作しなくなったように見えます。少なくとも私にとっては、構文的に正しいように見える小さなテスト アプリケーションを作成しましたが、機能していません。

テスト プロジェクトのコードは次のとおりです。

マニフェスト:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.AGApplications.test"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".test"
                  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=".MsgMon"> 
            <intent-filter> 
                <action android:name=
                    "android.provider.Telephony.SMS_RECEIVED" /> 
            </intent-filter> 
        </receiver>

    </application>

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

    <uses-sdk android:minSdkVersion="8" />
</manifest> 

BroadcastReceiver:

package com.AGApplications.test;

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

public class MsgMon extends BroadcastReceiver{

   @Override
   //Called when new message is received
   public void onReceive(Context context, Intent intent) {
      Log.d("PHONE", "Message Received");
   }
}

そして主な活動:

package com.AGApplications.test;

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

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

私が言うことができる限り、私は何も悪いことをしていませんが、明らかに私は間違っています!

4

2 に答える 2

1

だから私は問題を発見しました。「PHONE」をデバッグタグとして使用することはできません。理由がわからないので聞かないでください。複数の異なるタグを使用した後、登録されなかったのは「PHONE」だけでした。

私のバグはどこかにあるようで、私は再びトレイルに熱中しています! ご協力ありがとうございました!

于 2010-09-01T07:10:33.370 に答える
0

私にとってはすべて問題ないようです。同じ例を実行しました

ここに私のコードがあります:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.infostretch.broadcastex"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">


    <receiver android:name="broadcastex" android:label="@string/app_name"><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_PHONE_STATE"></uses-permission>
</manifest> 


public class broadcastex extends BroadcastReceiver {
    /** Called when the activity is first created. */
    private static final String TAG = "smsfwd";
    private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";

public void onReceive(Context context, Intent intent) {

    Log.i(TAG, "Intent recieved: " + intent.getAction());

            Log.i(TAG, "Message recieved: " + messages[0].getMessageBody());
            if (messages.length > -1) {
                Log.i(TAG, "Message recieved: " + messages[0].getMessageBody());

            }
        }

このコードはAndroid 2.1で機能しています。試してみてください。すべてがあなたと同じだと思います

于 2010-08-31T04:31:44.527 に答える