Results 1 to 1 of 1

Thread: Enabling Android Hotspot programmatically

  1. #1
    Join Date
    Dec 2017
    Location
    Nigeria
    Posts
    3
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default Enabling Android Hotspot programmatically

    Hi, everyone, I am developing a mobile application using QML and C++ and I would like android phones to connect via hotspot.
    I've looked at Qt Android Extras, QJniObject and the rest expecially the notifier example which i have run myself.
    How do i write the java code for the creation of hotspot and connection something like Xender or Shareit applications.
    Thanks, I am new to Qt programming.

    I got this code from StackOverflow, how can i integrate it into my project?

    import android.content.*;
    import android.net.wifi.*;
    import java.lang.reflect.*;

    public class ApManager {

    //check whether wifi hotspot on or off
    public static boolean isApOn(Context context) {
    WifiManager wifimanager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
    try {
    Method method = wifimanager.getClass().getDeclaredMethod("isWifiAp Enabled");
    method.setAccessible(true);
    return (Boolean) method.invoke(wifimanager);
    }
    catch (Throwable ignored) {}
    return false;
    }

    // toggle wifi hotspot on or off
    public static boolean configApState(Context context) {
    WifiManager wifimanager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
    WifiConfiguration wificonfiguration = null;
    try {
    // if WiFi is on, turn it off
    if(isApOn(context)) {
    wifimanager.setWifiEnabled(false);
    }
    Method method = wifimanager.getClass().getMethod("setWifiApEnabled ", WifiConfiguration.class, boolean.class);
    method.invoke(wifimanager, wificonfiguration, !isApOn(context));
    return true;
    }
    catch (Exception e) {
    e.printStackTrace();
    }
    return false;
    }
    } // end of class
    Last edited by A.Josh; 9th March 2018 at 13:16. Reason: updated contents

Similar Threads

  1. Replies: 4
    Last Post: 10th July 2014, 16:22
  2. Enabling MakeFiles Through .pro files of Qt
    By zgulser in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2012, 00:47
  3. QWebKit enabling cache
    By Talei in forum Newbie
    Replies: 1
    Last Post: 26th April 2011, 18:06
  4. Enabling Infrared in Qt 4.6.2
    By S P in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 8th July 2010, 12:02
  5. QItemDelegate and enabling buttons
    By T4ng10r in forum Qt Programming
    Replies: 0
    Last Post: 8th April 2009, 16:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.