2

私は、ユーザーの現在の経度と緯度とともに、地図上のユーザーの位置を表示するAndroidアプリケーションを作成しています。また、逆ジオコーディングを使用してAndroidデバイスの住所を表示しています。今度は、ユーザーが特定の場所の近くにいると、電話が自動的にサイレントモードに切り替わる機能を追加する予定です。このために、電話がすでにサイレントモードになっているかどうかを確認する機能を作成しました。次に、特定の場所に近づくと電話をサイレントモードにする別の電話を作成します。

特定の場所に近づくと電話を静かにするために私が作った方法は

public void changeToSilent(Location location){

    if(distanceTo(xxxx)<100)
    {
        if(mPhoneIsSilent==true){
        }
        else
        {
            mPhoneIsSilent = true;
            mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        }
    }
}

今、私はこのメソッドを別の関数で呼び出しています。それは...です。

public void onLocationChanged(Location location){Log.d(TAG、 "onLocationChanged with location" + location.toString()); Stringtext = String.format( "Lat:\ t%f \ nLong:\ t%f \ nAlt:\ t%f \ nBearing:\ t%f"、location.getLatitude()、location.getLongitude()、location。 getAltitude()、location.getBearing()); this.locationText.setText(text);

    changeToSilent(location);

    try {
      List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 10); 
      for (Address address : addresses) {
        this.locationText.append("\n" + address.getAddressLine(0));
      }

      int latitude = (int)(location.getLatitude() * 1000000);
      int longitude = (int)(location.getLongitude() * 1000000);

      GeoPoint point = new GeoPoint(latitude,longitude);
      mapController.animateTo(point); 

    } catch (IOException e) {
      Log.e("LocateMe", "Could not get Geocoder data", e);

    }
  }

ここで、oncreateメソッドで上記の関数を呼び出しています。ここで、電話が無音になる場所の緯度と経度がわかっているとします。私が知りたいのは、changetosilentメソッドでxxxxの代わりに何を書く必要があるかということです。

4

1 に答える 1

1

AudioManagerを使用して、システムの音量レベルを変更できます。

ここに例があります:

AudioManager am =  (AudioManager) getSystemService(AUDIO_SERVICE); 
//am.setStreamVolume(AudioManager.STREAM_MUSIC,6,0); //<-- use this one to set the volume
am.setRingerMode(AudioManager.RINGER_MODE_SILENT); //<-- to put on mute.

編集:Locationオブジェクトを取得し、loc.distanceBetween()を使用します;

于 2012-06-12T13:19:13.020 に答える