TV box boot self-boot wifi hotspot function code, it seems that the router can save...

Source: Internet
Author: User

Currently, it is faster to watch videos over a wired connection than to go through a vro and use wireless connection as a hotspot. However, after setting a hotspot in a wireless connection, you have to turn on the hotspot again after shutdown or restarting, Which is troublesome, it is more convenient to add a self-starting hot spot on startup. Other devices can access the Internet through the box even if the network speed is fast and the video is not card.


Development Tools

Android ADT


Implementation Method

1. Enable hotspot

2. boot



Code

1. Enable hotspot

WifiManager wifiManager; wifiManager = (WifiManager) getSystemService (Context. WIFI_SERVICE); Method method = wifiManager. getClass (). getMethod ("getWifiApState"); int state = (Integer) method. invoke (wifiManager); if (state = 13 | state = 12) // has been opened or is being opened {} else {Toast. makeText (MainActivity. this, "AndroidAP is being enabled... ", 1 ). show (); wifiManager. setWifiEnabled (false); WifiConfiguration apConfig = new WifiConfiguration (); apConfig. SSID = "AndroidAP"; apConfig. allowedKeyManagement. set (4); apConfig. preSharedKey = "5e8918f37260"; method = wifiManager. getClass (). getMethod ("setWifiApEnabled", WifiConfiguration. class, Boolean. TYPE); boolean open = (Boolean) method. invoke (wifiManager, apConfig, true );}


Add permissions to AndroidManifest. xml

<Uses-permissionandroid: name = "android. permission. CHANGE_WIFI_STATE"> </uses-permission>

<Uses-permissionandroid: name = "android. permission. ACCESS_WIFI_STATE"> </uses-permission>

 


2. boot

Used

<Actionandroid: name = "android. intent. action. BOOT_COMPLETED"/>

<Uses-permission android: name = "android. permission. RECEIVE_BOOT_COMPLETED"> </uses-permission>

I tried it on my TV box and found that sometimes the system will not run automatically when it is turned on.

Change your mind

Use

<Categoryandroid: name = "android. intent. category. HOME"/>

Replace the desktop that comes with the TV box


Enable the AP hotspot and then automatically run the desktop in the box

    ComponentName componet = new ComponentName("com.duokan.duokantv","com.duokan.duokantv.MainActivity");        Intent i = new Intent();        i.setComponent(componet);        startActivity(i);






Usage

1. cable networks connected to TV boxes

2. Configure the box for normal Internet access

3. install your own program






Source: http://blog.csdn.net/xiaoxiao108
About the author: cainiao. If you have any questions or suggestions, please kindly advise me!
You are welcome to repost the statement, but this statement must be retained without the author's consent, and the original article connection is clearly provided on the article page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.