1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
package com.example.smarttwo;
import android.os.Bundle;
import android.net.wifi.*;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener
{
private Button test;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.test = (Button)this.findViewById(R.id.button1);
this.test.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void onClick(View v)
{
double testy;
testy = getSignalToMeter();
Toast.makeText(this, "Vous vous situez à:" + String.valueOf(testy) + "du point d'accès", Toast.LENGTH_SHORT).show();
}
public double getSignalToMeter()
{
WifiManager wifiManager = (WifiManager)this.getSystemService(Context.WIFI_SERVICE);
double linkSpeed = wifiManager.getConnectionInfo().getRssi();
//**? return LinkSpeed ?**\\
double exp = (27.55 - (20 * Math.log10(2400)) + (linkSpeed)) / 20.0;
//** 2400 = Access point's frequency, 2.4GHz **\\
return Math.pow(10.0, exp);
} |
Partager