I’m trying to make a class that will handle some router functionality such as retrieving the Mac address of the router you are connected to. I would like a method that retrives this to be able to be called in more than one class. This is the router class:
public class Router extends Service
{
static Router thisclass = new Router();
WifiManager wifiMan = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInf = wifiMan.getConnectionInfo();
public String BSSID() {
return wifiInf.getBSSID();
}
static String bssid() {
return thisclass.BSSID();
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
}
Then in the main class I’d like to use this string as such:
public class AppActivity extends Activity
{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView macAddress;
macAddress = (TextView) findViewById(R.id.textView1);
//Router r = new Router();
macAddress.setText("BSSID: " + Router.bssid());
}
}
The app crashes every time and I can’t get why. I also have no idea how to catch errors, I tried try catch statements but could print to logcat. You may at this point know I’m not too hot at programming. One last thing is my ManiFest and thanks for reading
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.infoturtle.ringbyrouter"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<activity android:name=".AppActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="Router"></service>
</application>
</manifest>
The main problem is that you are having Router extend Service while you aren’t actually implementing a service. Try this instead: