1

動的登録の代わりに、受信者を静的に登録したいと考えています。 動的登録の場合、うまく機能します。これを使用していました:

..
static private IntentFilter GPSActionFilter;
..
GPSActionFilter = new IntentFilter("GGPS Service");
context.registerReceiver(GPSActionReceiver, GPSActionFilter);
..
static private BroadcastReceiver GPSActionReceiver = new BroadcastReceiver(){  
    public void onReceive(Context context, Intent intent) {  ..}

静的登録の場合、デバッガーは onReceive 関数にヒットしません。私はこれを使用しています:

AndoridManifest で:

<receiver android:name="LocationListener$GPSActionReceiver" >   
    <intent-filter>
        <action android:name="LocationListener.ACTION_GPS_SERVICE" />
    </intent-filter>
</receiver>

コード内:

public class LocationListener extends BroadcastReceiver
{
    public static IntentFilter GPSActionFilter;
    public static final String ACTION_GPS_SERVICE = "com.example.LocationListener.GPSActionFilter";
    public static BroadcastReceiver GPSActionReceiver;
    public void onReceive(final Context context, final Intent intent)
    {..}
}
4

2 に答える 2

1

マニフェストでインテント フィルター アクションを宣言する場合、android:name は文字列リテラルである必要があり、クラスから文字列にアクセスすることはできません。また、インテント アクションの前に完全修飾パッケージ名を追加することをお勧めします。

public static final String GPS_SERVICE = "com.example.LocationListener.ACTION_GPS_SERVICE"

次に変更

<action android:name="LocationListener.GPS_SERVICE" />

<action android:name="com.example.LocationListener.ACTION_GPS_SERVICE" />
于 2013-05-22T22:20:50.630 に答える
1

private BroadcastReceiverまず、 Android はそのインスタンスを作成できる必要があるため、マニフェストに を含めることはできません。これを公開してください。

第 2 に、静的内部クラスの名前の構文は でありLocationListener$GPSActionReceiver、 ではありませんLocationListener.GPSActionReceiver

于 2013-05-22T22:16:22.337 に答える