I have an app for android created with kotlin.
In general, it works fine. But one user reports he can not login and error is like no internet connection.
However, he says connection is fine. He can open api endpoint with the browser on same device .
What can be the reason for this?
The app has manifest record for network permissions. For other users it works fine
As you don't have given much information, I can give you some points to check:
Network permission in manifest file (that is already done).
Run time permission for Android 6.0 and above.
check if you done something like this code.
try{
//network code
}
catch(Exception e){
DialogBOXSHOW("Network error");
}
because Exception here can catch any type of error even NullPointerException
Related
I am developing one document upload app, using react native.
Documents get uploaded if the network is good, but suddenly the app crashes if the network goes down.
For instance - If I am uploading the documents on 4G network then i receive success from API but if the network speed suddenly goes down to 2G network i.e. 20KB/S then I get "NETWORK REQUEST FAILED / NETWORK ERROR" and the app crashes.
I have handled the error using catch block, but still the app crashes, what should I do to avoid this crashing even if the network is not available or if the speed goes down ?
Below is my code -
try{
var form = FormData();
form.append("user_id",this.state.userId);
form.append('file', {
uri: this.state.path,
type: 'image/jpg',
name: 'image.jpg',
});
axios({
method:"POST",
url:"http://xxxxx/xxxx",
timeout:50000,
data:form
})
.then(response => console.log(response))
.catch(error=>console.log(error));
}
catch(error){
console.log(error);
ToastAndroid.show("Internal error, please try again");
}
Note - I have used react-native-image-picker, as the document can be captured using camera OR it could be uploaded from the existing file present in the device.
Also have added all permissions in Manifest file for internet access.
Please help
Thats an Exception. I guess you need to catch the Exception
BadNetwork or Timeout You need to Catch it and App should not Crash just make sure
In the Catch You need to Show the Dialog box which says Can't connect to server.
OR You need to check if you have a Network connection then only Let the user send the Request show Non-cancelable Dialogbox
Hope that helps .
The error message is:
Network error. Please try again later.
Any idea why it's possibly not loading on my phone. Everything seems to be updated and good.
Assuming your device has a network connection, I would assume it's because you don't have the android.permission.INTERNET permission declared in your manifest.
I am trying to open a socket in the android source code. Specifically, right now, I am in the DisplayDevice.cpp file, but the location of the socket code may change. Right now after I do:
int fd = socket(AF_INET, SOCK_STREAM, 0);
fd gets returned as -1, and when i check the error message it is listed as Permission Denied. I have looked around a lot for this, most answers involve adding the internet permission to the AndroidManifest file. This will not work for me as the code I am adding is inside of the android source code.
I was wondering if there is a way to bypass the permission denied. Or if there is a better way to do this/ a different type of socket to use(right now I am using sockets from
Thank you.
It is quite natural that you get Permission Denied error. This is simply because you don't have correct permission :). Check out android permission model!
Imagine a scenario like a normal user in an operating system and you write a program which tries to open a socket like yours. You would most probably face the same problem, depending on where the named socket is to be created.
As you are trying to create the socket in DisplayDevice.cpp (compiling android from the source), you may be interested in compiling the source as a superuser. Here is a solution posted by m-ric (I have never tested it).
Some useful pointers/references in similar direction and which I found useful during research on this enthralling topic are:
https://android.stackexchange.com/questions/18857/how-to-build-compile-su-from-source
execv command => http://code.google.com/p/superuser/source/browse/trunk/su/su.c?r=2#169
https://github.com/ChainsDD/su-binary
http://e2e.ti.com/support/omap/f/849/p/178679/648158.aspx#648158
A video from Google I/O 2011 http://www.youtube.com/watch?v=5yorhsSPFG4
I'm developing a simple app for my school which will show you the newest updates from the website, but checking the internet connection seems a little problem in AIR.
I'll be more specific:
I'm using Adobe Flash CS6 to develop the app (Using AIR for android)
The app contains a menu, and the "internet frame", of which the code doesn't really work.
I've tried a couple of things already: URLMonitor(like is available = true), URLLoader(and cathing the IOError if it occurs when there's no internet connection) and something like HTMLLoader (long time ago :P, no success)
The URLLoader works "fine", but I also need to know if the webpage just isn't available (404) when there IS an active internet connection, but in either those cases it will just throw the same "stream error" , so I can distinguish them. That's why it doesn't suit my needs.
The URLMonitor also works "fine", but here comes to problem:
When testing the app on the emulator, it can without a problem detect that there is no internet connection. BUT, when exporting to .apk and running on my android device, it won't succeed in detecting the internet connectivity.
Here's my code:
var monitor:URLMonitor = new URLMonitor(new URLRequest("http://www.google.nl"));
monitor.addEventListener(StatusEvent.STATUS, netConnectivity);
monitor.start();
function netConnectivity(e:StatusEvent):void
{
if(e.target.available)
{
//checking the content
output_txt.text += "\ninternet available";
loader = new URLLoader(new URLRequest(webURL));
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorLoader);
loader.addEventListener(Event.COMPLETE, onCompleteLoader);
}
else
{
//
//
// NO INTERNET CONNECTION AVAILABLE!
//
//
output_txt.text += "\nno internet available";
popupnoconnection_mc.alpha = 100;
popupnoconnection_mc.play();
popupnoconnection_mc.addEventListener(MouseEvent.MOUSE_DOWN, BackToMenu);
}
monitor.stop();
}
As you can see, it adds an EventListener to the URLMonitor, starts the checking, and the function checks the availability of the internet connection. WORKS ON THE EMULATOR, NOT PROPERLY ON MY DEVICE.
What's even more interesting:
What DOES work on my device, is when the internet IS connected. It will just show the text in my output field, but it won't when there is no internet connection!
Also, when lauching the app with an internet connection set up, then entering this frame, then going back to the main menu, then turning the internet off, and then entering this frame again, this code suddently works great!
So it has got to do something with the creation of the URLMonitor, and checking the connection at the same frame I guess, but I need a little hand here!
I think this can't be too difficult!
Thank you so much in advance! (sorry for typos)
You can use NetworkInfo to detect whether there is an internet connection - it works on Android.
got a strange problem here.
I have a function which reads the NetworkInterfaces and gets me the WiFi-Interface name.
This worked properly 2 weeks ago with the only permission "android.permission.ACCESS_NETWORK_STATE".
This week i mainly tested with 3G and did some minor changes to the overall code and today i noticed 'NetworkInterface.getNetworkInterfaces()' doesnt work anymore, giving me a "permission denied" exception. Few secs later my dear friend google tells me i need INTERNET permission...
-> I never ever used INTERNET permission in this project ???
So what could be wrong? Any way to get the NetworkInterfaces without using the internet permissions? It works again if i add it but idont really want to use it just for that.
Enumeration<NetworkInterface> interfaces = null;
try {
interfaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e) {
e.printStackTrace();
}