Search code examples
androidwifisu

Enable wifi from application


I am trying to enable wifi from application. I have tried the following:

Runtime.getRuntime().exec(new String[] {"su", "-c", "svc wifi enable"});

And I see that wifi is enabled but I can't find any wifi stations. The strange thing is that I do find wifi station if I just will do the same from shell just before starting application:

 $ svc enable wifi

I don't understand what's the difference between these two scenarios, and how to make it work from application.

I also tried to call script from application which only calls the same command, But I got the same results.


Solution

  • Try this way...

    Runtime.getRuntime().exec(new String[]{"/system/bin/su","-c","svc wifi enable"});