1

これは私の最初の質問です:

データベースおよび Web サービス プロバイダーからフィードされる近接アラートを構成しようとしています。しかし、テスト用の単純な近接アラートの構成に問題があります。なんとかアラートを作成できましたが、決して発生しません。今のところエミュレーターで試しているだけで、アラートをトリガーするために追加のコードが必要かどうかわかりません。

エミュレーターでアラートをトリガーするためにネットワークプロバイダーを使用できるように、GPSプロバイダーを無効にすることをどこかで読みました。

私のコードは次のようになります。

近接意図宣言

private String proximityIntentAction = new String("gpsdelivery.gpship.getLocation.GPS_PROXIMITY_ALERT");    

アラートのパラメータが設定される onStart() 内

IntentFilter intentFilter = new IntentFilter(proximityIntentAction);
registerReceiver(new ProximityAlert(), intentFilter);
setProximityAlert(45.150344, 9.999815, -1);        

アラートが作成される近接アラート機能

private void setProximityAlert(double lat, double lon, int requestCode)
{
    // 100 meter radius
    float radius = 100f;
    // Expiration is 10 Minutes
    long expiration = 600000;
    LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    Intent intent = new Intent(proximityIntentAction);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    locManager.addProximityAlert(lat, lon, radius, expiration, pendingIntent);

}

最後に、ブロードキャスト レシーバーを使用した近接アラート クラス

public class ProximityAlert extends BroadcastReceiver
    {
        @Override
        public void onReceive(Context context, Intent intent) 
        {
            Log.v("SomeTag","Proximity alert received");

        }

    }       

何が足りないのか、何が間違っているのか教えてください。事前に感謝します。ソースコードをいただければ幸いです。

4

1 に答える 1

0

まあ、私はあなたsetProximityAlert(45.150344, 9.999815, -1);が間違っていると信じています。具体的には、あなたの-1。に必要な情報が含まれていませんlocManager.addProximityAlert(lat, lon, radius, expiration, pendingIntent);

于 2015-07-21T15:01:28.447 に答える