0

選択したマーカーの位置に基づいて近接アラームを設定しようとしています。その座標は外部ファイルに保存され、配列に読み込まれ、座標が描画されます。

    googleMap.setOnInfoWindowClickListener(
            new OnInfoWindowClickListener(){
     public void onInfoWindowClick(Marker marker) {



         LatLng clickedMarkerLatLng = marker.getPosition();
                double lat =  clickedMarkerLatLng.latitude;
                double long1 =  clickedMarkerLatLng.longitude;

            Log.e("hello", "Output=" + lat + long1);


     LocationManager lm;
    // double lat=0;
 //  double long1=0;    //Defining Latitude & Longitude
     float radius=3000;


    lm=(LocationManager) getSystemService(LOCATION_SERVICE);
    Intent i= new Intent("com.example.sleepertrain5.proximityalert");           //Custom Action
    PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), -1, i, 0);
    lm.addProximityAlert(lat, long1, radius, -1, pi);
    Toast.makeText(getBaseContext(), 
            "Info Window clicked@" + lat + "dddjdj" + long1, 
            Toast.LENGTH_SHORT).show();



    class ProximityReceiver extends android.content.BroadcastReceiver {

     @Override
     public void onReceive(Context arg0, Intent arg1) {
      // TODO Auto-generated method stub
      // The reciever gets the Context & the Intent that fired the broadcast as arg0 & agr1 

      String k=LocationManager.KEY_PROXIMITY_ENTERING;
     // Key for determining whether user is leaving or entering 

      boolean state=arg1.getBooleanExtra(k, false);
      //Gives whether the user is entering or leaving in boolean form

      if(state){
       // Call the Notification Service or anything else that you would like to do here
       Toast.makeText(arg0, "Welcome to my Area", 600).show();
      }else{
       //Other custom Notification 
       Toast.makeText(arg0, "Thank you for visiting my Area,come back again !!", 600).show();

      }

    }

    }
            }

});
}

選択したマーカーの座標はロケーション マネージャーに渡されますが、近接アラームは機能しません。明らかに現時点では、トーストを表示するだけですが、それも行っていません。ログによると、Proximity レシーバー クラスが呼び出されることはありませんが、その理由がわかりません。さまざまなサイズの半径で試しましたが、まだ機能しません。アイデアや助けはありますか?

4

1 に答える 1

1

BroadcastReceiver を、PendingIntent に使用した Intents アクションに登録する必要があります。次の行を追加して、AndroidManifest.xml でこれを行うことができます。

<receiver android:name="MyScheduleReceiver" >
    <intent-filter>
        <action android:name="com.example.sleepertrain5.proximityalert" />
    </intent-filter>
</receiver>
于 2013-09-12T12:09:24.090 に答える