Can't get MAC address - Android Studio

Currently I can get it to work if I use:
private static String address = "00:00:00:25:02:80";
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
But I want to be able to use:
Intent intent = getIntent();
newAddress = intent.getStringExtra(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(newAddress);
So I've seen this code in other examples but It doesn't work on mine?
I have also tried other methods.
String newAddress = mBluetoothAdapter.getAddress();
This also doesn't work.
So can anybody help me with this I want to get the MAC address on it's own to connected device without declaring it.

Hello,
Check here.
Have you inserted the permission in the manifest? (android.permission.BLUETOOTH)
What does mBluetoothAdapter.getAddress() return for you?
Check also here for the remote device's MAC.

Related

[Q] How to enable WifiAP / tethering programmatically from within app on SGS I9000?

I try to activate WifiAP (wifi tethering) via my application code. Since there is no direct API for it, it needs to be done via reflection.
Using the approach as mentioned on StackOverflow.com.
It works fine on Nexus One, HTC Desire, Huawei Ideos (all running 2.2.x), but it doesn't run on the SGS with 2.2.1.
Checking the android.net.wifi.WifiManager class via reflection, I see that Samsung has obviously modified the class and it has 57 instead of 37 methods.
Unfortunately the modified WifiManager class is not open sourced by Samsung and the error messages don't give any details or stack trace.
I am looking for somebody who can enable WifiAP activation programmatically on the SGS, eventually by modifying the underlying system, since I'm myself am an application developer, not working on system level. Also considering contract work!
There are two things I am trying:
1) activate WifiAP directly via reflection:
Code:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
Method[] wmMethods = wifi.getClass().getDeclaredMethods();
Log.d(TAG, "enableMobileAP methods " + wmMethods.length);
for(Method method: wmMethods){
Log.d(TAG, "enableMobileAP method.getName() " + method.getName());
if(method.getName().equals("setWifiApEnabled")) {
WifiConfiguration netConfig = new WifiConfiguration();
netConfig.SSID = "MyWifiAP";
netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
try {
Log.d(TAG, "enableMobileAP try: ");
method.invoke(wifi, netConfig, enabled);
if (netConfig.wepKeys!=null && netConfig.wepKeys.length>=1)
Log.d(TAG, "enableMobileAP key : " + netConfig.wepKeys[0]);
Log.d(TAG, "enableMobileAP enabled: ");
mIsWifiEnabled = enabled;
} catch (Exception e) {
Log.e(TAG, "enableMobileAP failed: ", e);
}
}
}
Attached are the logfiles I am getting on Nexus One (success) and SGS (failure).
The noticable part in the SGS log are maybe these lines:
Code:
D/WifiService( 2818): setWifiApEnabled: allowWifiAp: true
E/WifiService( 2818): setWifiApEnabledState 2
E/SoftapController( 2681): Softap already stopped
E/WifiService( 2818): Exception in stopAccessPoint()
E/WifiService( 2818): setWifiApEnabledState 4
D/WifiAp (23523): enableMobileAP key : null
2) another thing I try - since the modified SGS WifiManager (only that one) has a method named 'showApDialog' without any parameter taken, I try to call that method, but this also just gives an 'Error' in the log without further explanation.)
Code:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
Method[] wmMethods = wifi.getClass().getDeclaredMethods();
Log.d(TAG, "enableMobileAP methods " + wmMethods.length);
for(Method method: wmMethods){
Log.d(TAG, "enableMobileAP method.getName() " + method.getName());
if(method.getName().equals("showApDialog")) {
WifiConfiguration netConfig = new WifiConfiguration();
try {
method.invoke(wifi);
} catch (Exception e) {
Log.e("Main", "Can't open ap dialog.", e);
}
}
}
I have been able to enable an existing configuration by passing null as the WifiConfiguration parameter to the setWifiApEnabled method.
I had the same problems as you when I tried to use this function to create a new configuration. I also failed when I tried to pass the existing configuration as a parameter, after invoking getWifiApConfiguration.
I noticed in the Android source code that there is a similar function called setWifiApConfiguration, but calling wifiManager.getClass().getMethod("setWifiApConfiguration") throws NoSuchMethodException when I run it on my SGS.
I also wondered if I can use addNetwork to create a new configuration, but suspect it is only for connecting to APs, rather than creating one.
As I only wanted to toggle the existing configuration, which I have now achieved, I stopped investigating at this point.
Hope that helps,
Good luck...
Yes, I've also got it to work meanwhile but didn't update this thread. You're right, the problem were the configuration, which had to be left empty. Cheers
thank you for sharing this, it really made my day
it seems that (on Android 2.3.4) it only works if you first disable the WiFi (Nexus One).

[Q] Android Studio app says "Error In Network Connection"

I have created a login and register system, when ever I try to login, register, change password or reset password the app just says "Error In Network Connection".
I am using strong internet connection, could you please advise as I have tried to on WI-FI and 4G, however it still says the same error. I am using WAMP server to connect to myphpadmin database. Please could you help and advise. I have used the internet method as well as using the doinbackground method.
Emulator , Use Device
If you use emulator. You will get this type of problem.
Use below code to check the online condition for mobile.
public boolean isNetworkOnline() {
boolean status=false;
try{
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getNetworkInfo(0);
if (netInfo != null && netInfo.getState()==NetworkInfo.State.CONNECTED) {
status= true;
}else {
netInfo = cm.getNetworkInfo(1);
if(netInfo!=null && netInfo.getState()==NetworkInfo.State.CONNECTED)
status= true;
}
}catch(Exception e){
e.printStackTrace();
return false;
}
return status;
}

How do I use a global variable in a JavaScriptlet?

Okay, I'm trying to make parse a json file with a JavaScriplet.
I'm going through and pulling out data based on if a specific data set of the json matches a specific word in an array.
For example,
var arr = parsed data
For i = 0 to end
If arr.data.wall.color = "Red" var wallname = arr.data.wall.name
So if I do it like that, it works great. But I want to be able to put a variable in there. If I do this, it works:
var colorname = "Red"
var arr = parsed data
For i = 0 to end
If arr.data.wall.color = colorname var wallname = arr.data.wall.name
Obviously a local variable. But I want to use a Global variable... one I've already set in a different task. So in task 1 I set ColorName = "Red"
And then in task 2:
var arr = parsed data
For i = 0 to end
If arr.data.wall.color = ColorName var wallname = arr.data.wall.name
...which doesn't work. I read else where that you need to use global() to access global variables in Scriptlets, but trying that doesn't work:
If arr.data.wall.color = global(ColorName) var wallname = arr.data.wall.name
Nor does adding the percent sign anywhere seem to work. Any ideas what I'm doing wrong?
I'm fairly certain the format is: global('VarName')
So if you were doing a JSON read from data returned in the global %HTTPD variable: JSON.parse(global('HTTPD')).current_observation.icon
Try using the apostrophe's like: global('ColorName')

MySQL -- Problems running table script

Running Raspian jessie. Working on getting a MySQL database setup to create a time clock solution for a school project. I've got users set up and database created but i'm having trouble using the source command to run a .sql script to create 3 tables.
I'm following a tutorial on instructables, and this sql script file was provided. I can't post the link because I'm new to the forum.
I'm trying to use themysql> \. /attendance/mysql.sql and it says error
This is the contents of the mysql.sql
CREATE TABLE IF NOT EXISTS `cards` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`userId` int(10) unsigned NOT NULL,
`tagId` bigint(18) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
CREATE TABLE IF NOT EXISTS `readings` (
`id` bigint(11) unsigned NOT NULL AUTO_INCREMENT,
`tagId` bigint(18) unsigned NOT NULL,
`time` bigint(14) unsigned NOT NULL,
`action` int(2) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
CREATE TABLE IF NOT EXISTS `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_czech_ci NOT NULL,
`surname` varchar(255) COLLATE utf8_czech_ci NOT NULL,
`active` enum('0','1') COLLATE utf8_czech_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
Any input is much appreciated.

get eta using google maps api and travel mode=transit

Hello,
I implemented what is described HERE without problems, but now i would like to get the ETA using public transport routes. I changed what it seemed the most natural
Code:
travelmode=transit
instead of
Code:
travelmode=driving
(according to described in maps api documentation), but i still get travel time equal to driving mode.
Any ideas of what to do?
Regards,
Ok, after looking at google maps api documentation and analyzing the json output of the request, i got a solution.
First, replace in path "travelmode" for "mode", that is this:
Code:
/maps/api/directions/json?origin=%start&destination=%destination&[B]travelmode=driving[/B]&departure_time=now&key=%api
for this:
Code:
/maps/api/directions/json?origin=%start&destination=%destination&[B]mode=driving[/B]&departure_time=now&key=%api
And replace second and third line in the javascriplet:
Code:
var routetraffic = routeSplit.routes[0].legs[0].duration_in_traffic.text;
for this:
Code:
if (global('mapsTravelMode')=='driving'){
var routetraffic = routeSplit.routes[0].legs[0].duration_in_traffic.text;
var routename = routeSplit.routes[0].summary;
} else if (global('mapsTravelMode')=='transit') {
var routetraffic = routeSplit.routes[0].legs[0].duration.text;
var routename = 'going in public transportation';
}
Where %mapsTravelMode store the travel mode, in my case i use 'transit' or 'driving' that i set up manually.
If someone can get the first item in route that is not walking (i.e. the first transport to take), it would be great.
first bus obtained
hello,
to get the first non walking transportation, replace line:
Code:
var routename = 'going in public transportation';
with
Code:
var steps = t.routes[0].legs[0].steps;
for (var i = 0; i<steps.length; i++){
if (steps[i].travel_mode=='TRANSIT'){
break;
}
}
var routename = steps[i].transit_details.line.agencies[0].name;
var routename = routename + ' ' + steps[i].transit_details.line.short_name;
Shortname for bus notworking in javascriplet
Does any one have a download like for this task with the javascriplet changes I can't seem to get the shortname for the busses to work at all all I get is duration time

Categories

Resources