J
J
John2018-06-13 15:46:01
Android
John, 2018-06-13 15:46:01

Why does it work fine on an android emulator but not on a real phone?

In Visual Studio 2017 in C# I make an application with Socket.IO.Client and run it in the emulator (Android 6.0 and 8.0) - everything works like clockwork.
I archive and install on the phone (Android 6.0) - Socket.IO.Client does not work.
Could you help me, tell me why?
MainActivity.cs

using Android.App;
using Android.Widget;
using Android.OS;
using Android.Support.V7.App;
using SocketIO.Client;
using System.Threading;

namespace App6
{
    [Activity(Label = "Программулина", Theme = "@style/AppTheme", MainLauncher = true, Icon ="@mipmap/exit")]
    public class MainActivity : AppCompatActivity
    {
        private Socket socket;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            TextView info = FindViewById<TextView>(Resource.Id.textView1);
            info.Text = "Проверочка";
            //ДО СЮДА ВЫПОЛНЯЕТСЯ

            socket = IO.Socket("http://192.168.0.100:3333");
            socket.Connect();

            socket.On(Socket.EventConnect, (data) => {
                Print("Коннект", info);
                socket.Emit("add user", "Xamarin Android");
            });

            socket.On("message",(data)=>
            {
                Print(data[0].ToString(), info);
            });
        }
        private void Print (string text, TextView info)
        {
            RunOnUiThread(() => { info.Text = text; });
        }
    }
}

THE PROBLEM IS SOLVED by adding the manifest:
<uses-permission android:name="android.permission.INTERNET" />

And why does it not ask permission to use the network during installation? It says "No special permissions required"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2018-06-13
@GavriKos

Debugger / logs in the teeth and watch.
There are a lot of options - from the lack of IP to the lack of permissions to access the application in the network.

J
John, 2018-06-13
@ioangrozniy

Launched in the debugger, the phone asked for permission to install the application, I allowed it. The application is up and running.
Then I don't understand why the same application archived in apk and installed through the explorer does not work?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question