I am using the device_info_plus plugin like this:
Future<void> getHardwareID() async {
final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
if (Platform.isAndroid) {
final AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
hwid = androidInfo.androidId;
} else if (Platform.isIOS) {
final IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
hwid = iosInfo.identifierForVendor;
}
}
The issue is that when I use the same phone with different versions of the app - so if I upload a new bundle for testing for instance - then androidInfo.androidId will be something different. I suppose this is what they mean with the description
The Android hardware device ID that is unique between the device +
user and app signing.
Eventhough I think with app signing they mean the keystore file and properties which do not change so I am not sure if this is the reason
Apple seems to work fine since iosInfo.identifierForVendor just returns the
Unique UUID value identifying the current device
This is a problem since I would like to keep track of users in a database without them having to register with an account. (How) Is this possible?
There is an id property described like this:
Either a changelist number, or a label like M4-rc20
But that does not sound like what I am looking for
How can I get an ID from an android device that does not change if the app version changes?
I have developed a React Native app for Android device to connect with a HW board and one of the functionality is to communicate with HW board with Serial I/F Adapter from Mobile .
I have tried out multiple npm packages and none of them I could get to work.
Here is my sample code
import SerialPortAPI from 'react-native-serial-port-api';
const path = await SerialPortAPI.devicePaths(paths => {
console.log("List paths", paths)
})
const connectDevice = async (cfg) => {
const { baudRate, serialPortName, stopBits } = cfg
serialPort = await SerialPortAPI.open(serialPortName, { baudRate, stopBits});
const sub = serialPort.onReceived(buff => {
const str = buff.toString('hex').toUpperCase()
console.log(str);
})
await serialPort.send('A7B7');
}
It is NOT listing the device List connected and also not able to open/write/read.
Other packages I tried are:
react-native-usbserial
react-native-serialport
react-native-usb-serialport
react-native-serial-port-api
I any pointers and working sample will be of great help.
Regards
Raghu VT
Are you connecting the phone to your pc or it should work as host? I think that is key point to understand.
My phone is Host and I started with Android code.
Would recommend to use Android to test if possible.
You want to pay attention to the port type used.
If you use a USB AB connector you need to use an otg cable or adapter.
if case of type C , this will be detected automatically.
Hope could provide some hints
How can I set my device name for bluetooth in Flutter?
In Java, there is one plugin BluetoothAdapter which could be used to set the bluetootg device name, but in Flutter, I did not find a way to do this.
thanks
Try FlutterBlue which is a bluetooth plugin for Flutter. You should able to do that via that plugin. Here is an example of reading/writing a characteristic from that page just in case if link goes poof:
// Reads all characteristics
var characteristics = service.characteristics;
for(BluetoothCharacteristic c in characteristics) {
List<int> value = await c.read();
print(value);
}
// Writes to a characteristic
await c.write([0x12, 0x34])
I have a Nativescript-Vue project built with vue init nativescript-vue/vue-cli-template using the axios library.
If I run the following snippet in a browser environment, it works fine, that is, times out as expected with such a short timeout setting:
const apiClient = axios.create({
timeout: 1,
})
apiClient.request({
url: 'https://jsonplaceholder.typicode.com/todos/1',
}).then(response => {
console.log('this.apiClient.defaults.timeout', apiClient.defaults.timeout)
console.log(response.config)
console.log(response.data)
}).catch(e => {
console.log(e)
})
However, when I run the code in a NativeScript-Vue project on Android, the request completes as if there were no timeout setting present at all. Even though you can see from the console.logs that the value for timeout is 1.
If I make a similar request with NativeScript's "http/http-request" module, the timeout setting is respected as expected.
[Update:]
Turned out that Manoj's workaround below alone wasn't sufficient for our requirements because only connect timeout is set for the HttpURLConnection in org.nativescript.widgets.Async's HttpRequestTask. Setting read timeout provided the desired result, that is, causing the timeout to expire when no data is received within the timeout period. So, I suggested considering setting read timeout in addition to connect timeout:
// apply timeout
if (options.timeout > 0)
{
connection.setConnectTimeout(options.timeout);
connection.setReadTimeout(options.timeout);
}
I guess it's not implemented in the XHR wrapper (as of v6.2.0) but only in the original http request class. Try adding the code below in your app.js.
import { XMLHttpRequest } from 'tns-core-modules/xhr';
import * as types from "tns-core-modules/utils/types";
XMLHttpRequest.prototype.originalSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function (data) {
if (types.isDefined(this._options) && types.isNumber(this.timeout)) {
this._options.timeout = this.timeout;
}
this.originalSend(data);
};
You might want to submit a issue at Github.
I'm using sencha-touch 2.0 and phonegap 2.0.0 in my app to retrieve user's location.
When runing on my locahost, everything works just fine. However, when loading the .apk to my android 15 api's device (using eclipse and the adt plugin), every call to getCurrentLocation or watchPosition never returns...
here is my code:
geoOn: function(){
var geoReady = navigator.geolocation || undefined;
var onSuccess = function(position){
Top5.app.alert('Geolocation success '+String(position.coords.latitude) + ' ' + String(position.coords.longitude),'Geolocation');
var scope = Ext.getCmp('nestedList');
scope.updateDistance(position.coords);
};
var onFailure = function(error){Top5.app.alert('Geolocation failed: '+String(error.code) + ' '+String(error.message),'Geolocation');};
if (geoReady) {
this.watchId = navigator.geolocation.watchPosition(onSuccess ,onFailure,{timeout:6000,maximumAge: 3000,enableHighAccuracy: true});
}
else{
Ext.device.Geolocation.watchPosition({
frequency: 3000, // Update every 3 seconds
callback: function(position) {
this.updateDistance(position.coords);
},
failure: function() {
console.log('Geolocation Failure!');
},
scope:this
});
}
},
geoGet: function(){
var geoReady = navigator.geolocation || undefined;
if (geoReady) {
var onSuccess = function(position){
Top5.app.alert('Geolocation successful!!!');
var scope = Ext.getCmp('nestedList');
scope.updateDistance(position.coords);
};
var onFailure = function(error){Top5.app.alert('Geolocation failed: '+String(error.code) + ' '+String(error.message),'Geolocation');};
navigator.geolocation.getCurrentPosition(onSuccess,onFailure);
}
else{}
},
geoOff:function(){
var geoReady = navigator.geolocation || undefined;
if (geoReady) {
navigator.geolocation.clearWatch(this.watchId);
this.watchId = null;
}
else{
Ext.device.Geolocation.clearWatch();
}
},
updateDistance:function(coords){
Top5.app.alert('updateDist','');
var scope = Ext.getCmp('nestedList');
var lat = coords.latitude,lon = coords.longitude;
var store = scope.getStore();
var i,record;
for(i = 0; i < store.data.all.length; i++)
{
record = store.data.all[i];
if(record.data.locationX){
record.set('distance',Top5.app.getDistance(record.data.locationX,record.data.locationY,lat,lon).toFixed(3));
}
}
}
UPDATE: So I walked out of my building and it worked... I need to go outside more often.
However, when I'm disabling the gps, I thought geoLocation will find my location using wifi connection - but it failes (I'm setting enableHighAccuracy: false). Why is that?
UPDATE: Let me rephrase my question:
Does navigator.geolocation.watchPosition suppose to work both with GPS signal and wifi/g3 signals? How can I detect user location using internet connection only? currently, my code is working only with GPS, and when that option disabled or signal is blocked, geolocation isn't working.
I know that maybe it is too late, but today i struggled with the same issue! The solution turned out to be very simple!
SOLUTION: Reboot the device.
That's all.
The problem is, that you never know when i user will get this kind of bug, so if your application relies heavily on geolocation i recommend you set a timeout in location options navigator.geolocation.getCurrentPosition(geoSuccess, geoError, {timeout: 15000}) and alert user about the problem and possible solution.
P.S.
Keep in mind, that Geolocation can timeout for example if mobile data is turned off too, so reboot won't always fix it. On iPhone it uses cellular data to get your position, but on Android, it looks like the phone does not have access to cellular data unless 3G is turned on
It could sound stupid, but, did you activate the "Use Networks" option?
Go to Settings -> Location and security -> Use networks; and active it. I have passed all the afternoon watching the problem and it was that.
I restarted and restarted. I reset my phone to factory settings.
But nothing worked.
Until I set enablHighAccuracy from true to false.
And... Tada.... it works.
So :
var options;
options = {
maximumAge: 30000,
timeout: 5000,
enableHighAccuracy: false
};
This used to work fine using PhoneGap 2.6.0. I needed to make this change since I'm now using Phonegap 3.3 - tested on a Wiko Cink+ phone.
Try removing the Phonegap plugin geolocation plugin from your project. You won't need to make any changes to your JavaScript code as your device will fall back on the standard HTML5 navigator.geolocation functionality which has the same method signature.
Assuming you're using PhoneGap 3.3, you just need to run:
cordova plugin rm org.apache.cordova.geolocation
If you are running on an emulator, it may be because the device does not have a geolocation set. Try setting the location by running the following, assuming your android emulator is on port 5554:
telnet localhost 5554
geo fix -0.001 51.5
Restart your phone or Go to google map and check if gps is working over there.
I got it working.
I had this happen to a working app after updating PhoneGap to version 3.6.3 from 3.5. After trying many other suggestions Arthur's answer worked. 15 seconds seemed too long to me so I used {timeout: 2000}. I'm guessing the new version is slower as my code worked fine before the update on the same devices. Thought I'd post as well as upvote him as everything I found in Google was about initial setup and mostly irrelevant to my situation.
You just need to add enableHighAccuracy: true, maximumAge: 60000 and then reboot your device.
From my trial and error analysis, its most likely:
1. The version of android you're using. On Lollipop and lower you may need to go to the phones location settings and enable high accuracy settings (using gps, wlan and mobile networks to get location). I had to do this on a kitkat phone.
2. As others have mentioned, you can try changing the settings of getCurrentPosition by either enabling/disabling highaccuracy and adding a timeout.
3.If you're using ngCordova, make sure you installed it right and the location functions are actually being called. Use console to verify
Try This Solution:
window.setInterval(checkPosition, 5000);
function checkPosition() {
function onSuccess(position) {
document.getElementById('result1').innerHTML = position.coords.latitude;
document.getElementById('result2').innerHTML = position.coords.longitude;
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
I've managed to work it out.... However , I have no idea what actually solved it. All I've done is to change one of my model's structure. Can anyone see the connection to geolocation?