tethering https://www.e-learn.cn/tag/tethering zh-hans How to get Tethering and Mobile Hotspot data usage in Android using NetworkStatusManager or TrafficStat https://www.e-learn.cn/topic/4025622 <span>How to get Tethering and Mobile Hotspot data usage in Android using NetworkStatusManager or TrafficStat</span> <span><span lang="" about="/user/157" typeof="schema:Person" property="schema:name" datatype="">梦想的初衷</span></span> <span>2021-01-28 09:14:54</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I have an Android application which displaying data usage per app by NetworkStatusManager, but I can't get data usage for Tethering and Mobile Hotspot. How should I do this?</p> <br /><h3>回答1:</h3><br /><p>You need to query by UID and pass in the tethering UID: <code>android.app.usage.NetworkStats.Bucket.UID_TETHERING</code> like so:</p> <pre><code>networkStatsManager.queryDetailsForUid(ConnectivityManager.TYPE_MOBILE, subscriberId, startDate, endDate, android.app.usage.NetworkStats.Bucket.UID_TETHERING); </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/48005563/how-to-get-tethering-and-mobile-hotspot-data-usage-in-android-using-networkstatu</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/android" hreflang="zh-hans">android</a></div> <div class="field--item"><a href="/tag/tethering" hreflang="zh-hans">tethering</a></div> <div class="field--item"><a href="/tag/android-trafficstats" hreflang="zh-hans">android-trafficstats</a></div> <div class="field--item"><a href="/tag/networkstatsmanager" hreflang="zh-hans">networkstatsmanager</a></div> <div class="field--item"><a href="/tag/android-data-usage" hreflang="zh-hans">android-data-usage</a></div> </div> </div> Thu, 28 Jan 2021 01:14:54 +0000 梦想的初衷 4025622 at https://www.e-learn.cn How to check internet access (INCLUDING tethering!) on Android? https://www.e-learn.cn/topic/3141784 <span>How to check internet access (INCLUDING tethering!) on Android?</span> <span><span lang="" about="/user/235" typeof="schema:Person" property="schema:name" datatype="">你。</span></span> <span>2020-01-07 02:33:30</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I am looking for a piece of code that would check network connectivity, of an Android device, including tethering, not only the wireless channels. </p> <p>I have spent hours online looking for such a thing, but without any result! All the functions I found out manage only wireless net tests. Nothing with tethering. So is it at least possible? Do you have some corresponding?</p> <br /><h3>回答1:</h3><br /><p>this checks if Tethering is enabled. Cut from a class I changed to get adbWireless working over a tethered connection:</p> <pre><code> // check if tethering is on try { Method[] wmMethods = mWifiManager.getClass().getDeclaredMethods(); for(Method method: wmMethods) if("isWifiApEnabled".equals(method.getName())) return (Boolean) method.invoke(mWifiManager); return false; } catch (Exception x) {return false;} </code></pre> <p>And you also need android.permission.ACCESS_WIFI_STATE</p> <br /><br /><br /><h3>回答2:</h3><br /><p>Check this out:</p> <pre><code> public static boolean isOnline(Context context) { boolean isOnline = false; try { final ConnectivityManager conMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo(); if(activeNetwork != null &amp;&amp; activeNetwork.isConnected() &amp;&amp; activeNetwork.isAvailable()) { isOnline = true; } else { isOnline = false; } } catch(Exception e) { Log.e(Config.LOG_TAG, e.toString()); isOnline = false; } return isOnline; } </code></pre> <p>Also add such permission into AndroidManifest.xml:</p> <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt; </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/13474205/how-to-check-internet-access-including-tethering-on-android</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/android" hreflang="zh-hans">android</a></div> <div class="field--item"><a href="/tag/networking" hreflang="zh-hans">networking</a></div> <div class="field--item"><a href="/tag/connection" hreflang="zh-hans">connection</a></div> <div class="field--item"><a href="/tag/tethering" hreflang="zh-hans">tethering</a></div> </div> </div> Mon, 06 Jan 2020 18:33:30 +0000 你。 3141784 at https://www.e-learn.cn Reverse tethering Android https://www.e-learn.cn/topic/3104087 <span>Reverse tethering Android</span> <span><span lang="" about="/user/236" typeof="schema:Person" property="schema:name" datatype="">南楼画角</span></span> <span>2020-01-05 03:59:05</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I've tried to use different <code>reverse thetering</code> instructions for <code>Android</code> but no one had helped me. </p> <p>I've got connection for several second (30 sec) and then connection dissappeared.</p> <p>In connection manager I've seen <code>wired unmanaged</code> connection for my phone</p> <p>I'm using <code>Linux</code></p> <p>How can I fix problem with dissapearing reversed internet.</p> <p>Is it problem with Linux configuration?</p> <br /><h3>回答1:</h3><br /><p>If you use HTC mobile, the android need an (windows) driver to active "Internet Transmission", if not driver here, you will lost connection after a few seconds. </p> <p>but we can hack this without need root mobile. use this perl which connect the 6000 port of mobile. this script can enable "Internet Transmission", and you can see an icon show on panel. </p> <pre><code> ● cat bin/htcsock.pl #!/usr/bin/perl use IO::Socket::INET; #6000/tcp open X11 do{ open IN,"/proc/net/arp"; @arp=&lt;IN&gt;; close IN; @d=grep ! /00:00:00:00:00:00/,grep /0x2.*usb0/,@arp; } until($d[0]); $_=$d[0]; s/\ .*//; chomp; print "sock:\t$_\n"; my $sock = IO::Socket::INET-&gt;new(PeerAddr =&gt; $_ , PeerPort =&gt; 6000, Type=&gt;SOCK_STREAM, Proto=&gt;"tcp") or die "socket connect fail. $@\n"; print $sock "\x00\x02\x00\x00"; receivesock(); print $sock "\x00\x03\x00\x00"; receivesock(); print $sock "\x00\x05\x00\x00"; close $sock; sub receivesock{ local $/=\4; print "Receive: --"; print unpack "H*",&lt;$sock&gt;; print "--\n"; } </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><p>As an alternate method (which does the same as the Perl script shown here, but without the need of Perl), you can use what's suggested here, which I'll transcribe below (with some modifications I made):</p> <p>First, install bind9, since it'll avoid problems with DNS forwarding.</p> <pre><code>sudo apt-get install bind9 </code></pre> <p>Add a POSTROUTING rule to iptables:</p> <pre><code>sudo iptables -A POSTROUTING -t nat -j MASQUERADE </code></pre> <p>Allow packet forwarding:</p> <pre><code>echo 1 | sudo tee -a /proc/sys/net/ipv4/ip_forward </code></pre> <p>Now plug in your phone and select 'internet pass through'.</p> <p>Wait for the device to appear in <code>ifconfig</code>.</p> <p>Check it is also in <code>arp</code>.</p> <p>I found I had to unplug the device then plug it in again for it to appear in <code>arp</code>, things don't work properly if <code>arp</code> doesn't show the device.</p> <p>The device will then sit waiting for HTC Sync to send it a message, so you have to mock HTC Syncs message:</p> <pre><code>#change this line to be more specific if you have more than one usb network device phone_usb_device="usb" get_ip () { arp -n | grep $phone_usb_device | awk '{print $1}' } #TODO: This needs a timeout and loop needs cleaning up, but works fine and borrowed from another post. echo "waiting for IP on computer usb" while [[ `get_ip` &lt; 192 ]];do sleep 2; done phoneip=`get_ip` echo "IP adress is $phoneip " echo -n -e "\x00\x02\x00\x00" | nc -q 2 $phoneip 6000 &gt; /dev/null </code></pre> <p>The latter part could be turned into a D-Bus script.</p> <p>If you just want to test the Internet Pass Through feature, you can use the very last line only, for all the phone needs is that binary sequence on port 6000.</p> <p>Hope that helps.</p> <br /><br /><br /><h3>回答3:</h3><br /><p>Reverse tethering for android</p> <p>Here is steps for reverse tethering click here It required root you're device.</p> <p>It works for me.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/18401704/reverse-tethering-android</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/android" hreflang="zh-hans">android</a></div> <div class="field--item"><a href="/tag/tethering" hreflang="zh-hans">tethering</a></div> </div> </div> Sat, 04 Jan 2020 19:59:05 +0000 南楼画角 3104087 at https://www.e-learn.cn Enable USB Tethering Android Programmatically without user Interaction https://www.e-learn.cn/topic/3071658 <span>Enable USB Tethering Android Programmatically without user Interaction</span> <span><span lang="" about="/user/9" typeof="schema:Person" property="schema:name" datatype="">爷,独闯天下</span></span> <span>2020-01-03 03:37:07</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I am developing an application that requires USB Tethering. </p> <p>I am using the following code to do so</p> <pre><code>Intent tetherSettings = new Intent(); tetherSettings.setClassName("com.android.settings", "com.android.settings.TetherSettings"); startActivity(tetherSettings); </code></pre> <p>But this code is opening the Tethering Setting so the user can Enable the USB tethering by clicking on it. Is it possible to enable the tethering without any user interaction?</p> <br /><h3>回答1:</h3><br /><p>No, Android is very security-aware and will not enable this setting without user interaction.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/14340084/enable-usb-tethering-android-programmatically-without-user-interaction</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/android" hreflang="zh-hans">android</a></div> <div class="field--item"><a href="/tag/tethering" hreflang="zh-hans">tethering</a></div> </div> </div> Thu, 02 Jan 2020 19:37:07 +0000 爷,独闯天下 3071658 at https://www.e-learn.cn Disable wifi tethering on android https://www.e-learn.cn/topic/2791982 <span>Disable wifi tethering on android</span> <span><span lang="" about="/user/159" typeof="schema:Person" property="schema:name" datatype="">余生颓废</span></span> <span>2019-12-23 04:42:11</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I've found on stackoverflow the code that activates wifi-tethering programmatically on android... but how can I disable programmatically wifi tethering? Is available something like <code>setWifiApDisable</code>?</p> <br /><h3>回答1:</h3><br /><p>This should disable the wifi tethering. </p> <pre><code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setWifiTetheringEnabled(false); } private void setWifiTetheringEnabled(boolean enable) { WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); Method[] methods = wifiManager.getClass().getDeclaredMethods(); for (Method method : methods) { if (method.getName().equals("setWifiApEnabled")) { try { method.invoke(wifiManager, null, enable); } catch (Exception ex) { } break; } } } </code></pre> <p>Changing <code>setWifiTetheringEnabled(false);</code> to <code>setWifiTetheringEnabled(true);</code> will enable the wifi tethering.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/22841317/disable-wifi-tethering-on-android</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/android" hreflang="zh-hans">android</a></div> <div class="field--item"><a href="/tag/tethering" hreflang="zh-hans">tethering</a></div> </div> </div> Sun, 22 Dec 2019 20:42:11 +0000 余生颓废 2791982 at https://www.e-learn.cn Is there a way to check whether tethering is active? https://www.e-learn.cn/topic/2618275 <span>Is there a way to check whether tethering is active?</span> <span><span lang="" about="/user/67" typeof="schema:Person" property="schema:name" datatype="">孤人</span></span> <span>2019-12-18 16:55:16</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>can I check programmaticall wheter the android device has tethering activated?</p> <p>I just watched the WifiManager class. All vatraibles from the WifiInfo show the same values as iff the WIFI is turned off on the device.</p> <p>Thnaks, best regards</p> <br /><h3>回答1:</h3><br /><p>Try using reflection, like so: </p> <pre><code>WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); Method[] wmMethods = wifi.getClass().getDeclaredMethods(); for(Method method: wmMethods){ if(method.getName().equals("isWifiApEnabled")) { try { method.invoke(wifi); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } </code></pre> <p>(It returns a <code>Boolean</code>)</p> <hr /><p>As Dennis suggested it is better to use this : </p> <pre><code> final Method method = manager.getClass().getDeclaredMethod("isWifiApEnabled"); method.setAccessible(true); //in the case of visibility change in future APIs return (Boolean) method.invoke(manager); </code></pre> <p>(manager is the <code>WiFiManager</code>)</p> <br /><br /><br /><h3>回答2:</h3><br /><p>First, you need to get WifiManager:</p> <pre><code>Context context = ... final WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); </code></pre> <p>Then:</p> <pre><code>public static boolean isSharingWiFi(final WifiManager manager) { try { final Method method = manager.getClass().getDeclaredMethod("isWifiApEnabled"); method.setAccessible(true); //in the case of visibility change in future APIs return (Boolean) method.invoke(manager); } catch (final Throwable ignored) { } return false; } </code></pre> <p>Also you need to request a permission in AndroidManifest.xml:</p> <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/&gt; </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/8007361/is-there-a-way-to-check-whether-tethering-is-active</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/android" hreflang="zh-hans">android</a></div> <div class="field--item"><a href="/tag/wifi" hreflang="zh-hans">wifi</a></div> <div class="field--item"><a href="/tag/tethering" hreflang="zh-hans">tethering</a></div> </div> </div> Wed, 18 Dec 2019 08:55:16 +0000 孤人 2618275 at https://www.e-learn.cn Changing Android hotspot settings https://www.e-learn.cn/topic/2607087 <span>Changing Android hotspot settings</span> <span><span lang="" about="/user/198" typeof="schema:Person" property="schema:name" datatype="">别来无恙</span></span> <span>2019-12-18 12:02:24</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>With the release of API level 26, my app's core functionality broke, this being, changing the users' hotspot setting within the application. To get and set this configuration I am using the following functions from the <code>WifiManager</code> hidden api: <code>getWifiApConfiguration</code> and <code>setWifiApConfiguration</code>.</p> <pre><code>Method getWifiApConfiguration = wifiManager.getClass().getMethod("getWifiApConfiguration"); getWifiApConfiguration.invoke(wifiManager); </code></pre> <p>This is working with devices prior to Android O, but in this version I get the following error:</p> <blockquote> <p>App not allowed to read or update stored WiFi Ap config (uid = 10168)</p> </blockquote> <p>The permissions I have declared in the manifest are:</p> <pre><code>&lt;uses-permission android:name="android.permission.WRITE_SETTINGS"/&gt; &lt;uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt; &lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/&gt; &lt;uses-permission android:name="android.permission.INTERNET"/&gt; &lt;uses-permission android:name="android.permission.READ_PHONE_STATE"/&gt; &lt;uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt; &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt; &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/&gt; &lt;uses-permission android:name="android.permission.NETWORK_STACK"/&gt; &lt;uses-permission android:name="android.permission.TETHER_PRIVILEGED" /&gt; </code></pre> <p>How can I do this with the latest APIs?</p> <br /><h3>回答1:</h3><br /><p>As of Android Oreo (26), a new permission check was added to the service implementation of the getWifiApConfiguration() method:</p> <p><em>Snippet from WifiServiceImpl.java</em> </p> <pre><code>/** * see {@link WifiManager#getWifiApConfiguration()} * @return soft access point configuration * @throws SecurityException if the caller does not have permission to retrieve the softap * config */ @Override public WifiConfiguration getWifiApConfiguration() { enforceAccessPermission(); int uid = Binder.getCallingUid(); // only allow Settings UI to get the saved SoftApConfig if (!mWifiPermissionsUtil.checkConfigOverridePermission(uid)) { // random apps should not be allowed to read the user specified config throw new SecurityException("App not allowed to read or update stored WiFi Ap config " + "(uid = " + uid + ")"); } mLog.trace("getWifiApConfiguration uid=%").c(uid).flush(); return mWifiStateMachine.syncGetWifiApConfiguration(); } </code></pre> <p>Digging into the code you will quickly find out that to successfully invoke this method your application must hold the <em>android.permission.OVERRIDE_WIFI_CONFIG</em> permission that is a system level protected permission:</p> <p>Snippet from framework AndroidManifest.xml</p> <pre><code>&lt;!-- @SystemApi @hide Allows an application to modify any wifi configuration, even if created by another application. Once reconfigured the original creator cannot make any further modifications. &lt;p&gt;Not for use by third-party applications. --&gt; &lt;permission android:name="android.permission.OVERRIDE_WIFI_CONFIG" android:protectionLevel="signature|privileged" /&gt; </code></pre> <p>This means that your application needs to be signed by the platform key or be privileged to use this API.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/46392277/changing-android-hotspot-settings</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/android" hreflang="zh-hans">android</a></div> <div class="field--item"><a href="/tag/android-wifi" hreflang="zh-hans">android-wifi</a></div> <div class="field--item"><a href="/tag/android-networking" hreflang="zh-hans">android-networking</a></div> <div class="field--item"><a href="/tag/tethering" hreflang="zh-hans">tethering</a></div> </div> </div> Wed, 18 Dec 2019 04:02:24 +0000 别来无恙 2607087 at https://www.e-learn.cn Enable bluetooth tethering android programmatically https://www.e-learn.cn/topic/2582369 <span>Enable bluetooth tethering android programmatically</span> <span><span lang="" about="/user/17" typeof="schema:Person" property="schema:name" datatype="">…衆ロ難τιáo~</span></span> <span>2019-12-18 04:18:09</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I am trying to make an application like "Bluetooth auto tethering" on play store. I read on the forum that Android is very security-aware and will not enable this setting without user interaction.</p> <p>I need some explanations about how enable bluetooth tethering.</p> <p>Thank you</p> <br /><h3>回答1:</h3><br /><p>I don't know if this is still an issue or not, but I found that using the <code>connect</code> method in the reflection call works. Working off of the code that pmont used from the link in Lorelorelore's answer:</p> <pre><code>BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); Class&lt;?&gt; classBluetoothPan = null; Constructor&lt;?&gt; BTPanCtor = null; Object BTSrvInstance = null; Method mBTPanConnect; try { classBluetoothPan = Class.forName("android.bluetooth.BluetoothPan"); mBTPanConnect = classBluetoothPan.getDeclaredMethod("connect", BluetoothDevice.class); BTPanCtor = classBluetoothPan.getDeclaredConstructor(Context.class, BluetoothProfile.ServiceListener.class); BTPanCtor.setAccessible(true); BTSrvInstance = BTPanCtor.newInstance(myContext, new BTPanServiceListener(myContext)); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } Set&lt;BluetoothDevice&gt; pairedDevices = mBluetoothAdapter.getBondedDevices(); // If there are paired devices if (pairedDevices.size() &gt; 0) { // Loop through paired devices for (BluetoothDevice device : pairedDevices) { try{ mBTPanConnect.invoke(BTSrvInstance, device); } catch (Exception e) { e.printStackTrace(); } } } </code></pre> <p>Of course, this assumes that the bluetooth is enabled, and you only have one paired device. But enabling bluetooth is pretty straightforward using standard (not reflection) calls, and you can just check for the paired device that you want to connect to in the <code>for</code> loop. Also, don't forget the <code>BTPanServiceListener</code> class from the other answer as well.</p> <p>Hope this helps.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>The solution above required some modification in order to work for me. Specifically, the code to enable tethering needs to be in the OnServiceConnected() method. Also I have the following permissions set in the manifest:</p> <pre><code>&lt;uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/&gt; &lt;uses-permission android:name="android.permission.BLUETOOTH" /&gt; &lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /&gt; &lt;uses-permission android:name="android.permission.WRITE_SETTINGS" /&gt; </code></pre> <p>Here is my solution:</p> <pre><code>public class BluetoothTethering extends ActionBarActivity { Object instance = null; Method setTetheringOn = null; Method isTetheringOn = null; Object mutex = new Object(); protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bluetooth_tethering); String sClassName = "android.bluetooth.BluetoothPan"; try { Class&lt;?&gt; classBluetoothPan = Class.forName(sClassName); Constructor&lt;?&gt; ctor = classBluetoothPan.getDeclaredConstructor(Context.class, BluetoothProfile.ServiceListener.class); ctor.setAccessible(true); // Set Tethering ON Class[] paramSet = new Class[1]; paramSet[0] = boolean.class; synchronized (mutex) { setTetheringOn = classBluetoothPan.getDeclaredMethod("setBluetoothTethering", paramSet); isTetheringOn = classBluetoothPan.getDeclaredMethod("isTetheringOn", null); instance = ctor.newInstance(getApplicationContext(), new BTPanServiceListener(getApplicationContext())); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } public class BTPanServiceListener implements BluetoothProfile.ServiceListener { private final Context context; public BTPanServiceListener(final Context context) { this.context = context; } @Override public void onServiceConnected(final int profile, final BluetoothProfile proxy) { //Some code must be here or the compiler will optimize away this callback. try { synchronized (mutex) { setTetheringOn.invoke(instance, true); if ((Boolean)isTetheringOn.invoke(instance, null)) { Toast.makeText(getApplicationContext(), "BT Tethering is on", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(), "BT Tethering is off", Toast.LENGTH_LONG).show(); } } } catch (InvocationTargetException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } @Override public void onServiceDisconnected(final int profile) { } } } </code></pre> <br /><br /><br /><h3>回答3:</h3><br /><p>The below code works perfectly for me </p> <pre><code>String sClassName = "android.bluetooth.BluetoothPan"; try { Class&lt;?&gt; classBluetoothPan = Class.forName(sClassName); Constructor&lt;?&gt; ctor = classBluetoothPan.getDeclaredConstructor(Context.class, BluetoothProfile.ServiceListener.class); ctor.setAccessible(true); Object instance = ctor.newInstance(getApplicationContext(), new BTPanServiceListener(getApplicationContext())); // Set Tethering ON Class[] paramSet = new Class[1]; paramSet[0] = boolean.class; Method setTetheringOn = classBluetoothPan.getDeclaredMethod("setBluetoothTethering", paramSet); setTetheringOn.invoke(instance,true); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } public class BTPanServiceListener implements BluetoothProfile.ServiceListener { private final Context context; public BTPanServiceListener(final Context context) { this.context = context; } @Override public void onServiceConnected(final int profile, final BluetoothProfile proxy) { //Some code must be here or the compiler will optimize away this callback. Log.e("MyApp", "BTPan proxy connected"); } @Override public void onServiceDisconnected(final int profile) { } } </code></pre> <br /><br /><br /><h3>回答4:</h3><br /><p>Here you find a similar question: Bluetooth question</p> <p>Just replace "isTetheringOn" with "setBluetoothTethering" in the reflection call and pass in a boolean parameter. It should work.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/22864670/enable-bluetooth-tethering-android-programmatically</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/android" hreflang="zh-hans">android</a></div> <div class="field--item"><a href="/tag/bluetooth" hreflang="zh-hans">bluetooth</a></div> <div class="field--item"><a href="/tag/tethering" hreflang="zh-hans">tethering</a></div> <div class="field--item"><a href="/tag/tether" hreflang="zh-hans">tether</a></div> </div> </div> Tue, 17 Dec 2019 20:18:09 +0000 …衆ロ難τιáo~ 2582369 at https://www.e-learn.cn detect hotspot enabling in iOS with private api's https://www.e-learn.cn/topic/2545059 <span>detect hotspot enabling in iOS with private api&#039;s</span> <span><span lang="" about="/user/141" typeof="schema:Person" property="schema:name" datatype="">左心房为你撑大大i</span></span> <span>2019-12-17 10:58:20</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>ok so i want to detect weather the user has enabled hotspot/tethering or not in a iOS device. I can use private api's knowing it wont make it to the app store. </p> <p>i was trying to go through private api's list/ runtime headers but there are too many to decide which might be helpful.</p> <p>or if i could get to know where <strong><em>UIApplicationWillChangeStatusBarFrameNotification</em></strong> gets fired from in private api's(probably called for active call and activated hotspot etc)</p> <p>i tried this detect personal hotspot and also used <strong><em>CaptiveNetwork</em></strong> but it only returns the connected wi-fi ssid and not the created hotspot.</p> <p>any knowledge shared will be extremely helpful</p> <p><strong><em>Update: @creker</em></strong></p> <p>With the above code the compiler shows the error " SCDynamicStoreCreate is unavailable: not available on iOS. So i went into SCDynamicStore.h and changed the following</p> <pre><code> SCDynamicStoreRef SCDynamicStoreCreate ( CFAllocatorRef allocator, CFStringRef name, SCDynamicStoreCallBack callout, SCDynamicStoreContext *context ) __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA); </code></pre> <p><strong><em>to</em></strong> </p> <pre><code> SCDynamicStoreRef SCDynamicStoreCreate ( CFAllocatorRef allocator, CFStringRef name, SCDynamicStoreCallBack callout, SCDynamicStoreContext *context ) __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_6_0); </code></pre> <p>now i am able to get the dictionary with the states 1022 and 1023. Just wanted to confirm by changing the file like this(not done before) will i have any problem in archiving build(or any other problem) other then the fact that we know this code won't make it to the app store</p> <br /><h3>回答1:</h3><br /><h2>Without Private APIs</h2> <p>You can detect active personal hotspot by enumerating network interfaces using C APIs. When hotpost is active and someone is connected to it there will be interface with <code>bridge</code> prefix. On my iPhone 5 it's <code>bridge100</code>. If hotspot is disabled or no one is connected to it that interfaces will not even be in the list. </p> <p>C APIs will even return you IP address and subnet mask in that network.</p> <p>That's what I'm using in my applications to detect active hotspot. </p> <p>To get SSID you need <code>[[UIDevice currentDevice] name]</code> - personal hotspot SSID always matches device name.</p> <h2>With Private APIs</h2> <p>You can obtain all the information about personal hotspot using this code:</p> <pre><code>SCDynamicStoreRef sc = SCDynamicStoreCreate(NULL, CFSTR("com.apple.wirelessmodemsettings.MISManager"), NULL, NULL); NSDictionary* info = (__bridge_transfer NSDictionary*)SCDynamicStoreCopyValue(sc, CFSTR("com.apple.MobileInternetSharing")); CFRelease(sc); </code></pre> <p><code>info</code> dictionary will look something like this when hotspot is active and has connections:</p> <pre><code>{ Errnum = 0; ExternalInterfaces = ( "pdp_ip0" ); Hosts = { Current = 1; Max = 5; MoreAllowed = 1; Type = { AirPort = 0; Bluetooth = 0; Ethernet = 0; "USB-Ethernet" = 1; }; }; InternalInterfaces = ( bridge100 ); Reason = 0; State = 1023; Version = 2; } </code></pre> <p>When hotspot is active but there are no connections:</p> <pre><code>{ Errnum = 0; ExternalInterfaces = ( ); Hosts = { Current = 0; Max = 5; MoreAllowed = 1; Type = { AirPort = 0; Bluetooth = 0; Ethernet = 0; "USB-Ethernet" = 0; }; }; InternalInterfaces = ( ); Reason = 0; State = 1023; Version = 2; } </code></pre> <p>When hotspot is not active:</p> <pre><code>{ Errnum = 45; ExternalInterfaces = ( ); Hosts = { Current = 0; Max = 5; MoreAllowed = 1; Type = { AirPort = 0; Bluetooth = 0; Ethernet = 0; "USB-Ethernet" = 0; }; }; InternalInterfaces = ( ); Reason = 0; State = 1022; Version = 2; } </code></pre> <p><code>State</code> key will be equal to <code>1023</code> when hotspot is active regardless of active connections. I don't know whether that value contains bit-flags or not. iOS is actually checking if value is equal to <code>1023</code>.</p> <p>SCDynamicStore APIs are from public <code>SystemConfiguration</code> framework but marked as not available on iOS platform. That means all the headers are there, you just need to copy definitions without <code>__OSX_AVAILABLE_STARTING</code> macro. </p> <p>You can even observe changes to that setting - you can specify a key which value you want to observe. Read Apple documentation for implementation details.</p> <h2>UPDATE</h2> <blockquote> <p>So i went into SCDynamicStore.h and changed the following</p> </blockquote> <p>I wouldn't do that. It shouldn't cause any problems but for me changing SDK headers is not a good solution. I suggest the following. Don't include the framework headers. Make your own header where you copy all the methods you need with <code>__OSX_AVAILABLE_STARTING</code> changed or removed.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/31220371/detect-hotspot-enabling-in-ios-with-private-apis</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/ios" hreflang="zh-hans">ios</a></div> <div class="field--item"><a href="/tag/iphone-privateapi" hreflang="zh-hans">iphone-privateapi</a></div> <div class="field--item"><a href="/tag/tethering" hreflang="zh-hans">tethering</a></div> <div class="field--item"><a href="/tag/personal-hotspot" hreflang="zh-hans">personal-hotspot</a></div> </div> </div> Tue, 17 Dec 2019 02:58:20 +0000 左心房为你撑大大i 2545059 at https://www.e-learn.cn Delphi apps won't tether on Windows 10 https://www.e-learn.cn/topic/2171011 <span>Delphi apps won&#039;t tether on Windows 10</span> <span><span lang="" about="/user/83" typeof="schema:Person" property="schema:name" datatype="">蓝咒</span></span> <span>2019-12-11 02:21:45</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>How do I get Windows 10 or its firewall to allow my Delphi 10.2 tethering app to get access to the internet?</p> <p>When either the desktop or the mobile app is run on Windows 10, there is no request for permission from the firewall and tethering fails.</p> <p>In contrast, the Delphi mobile Photowall tethering example runs fine on Android and iPad, tethering with the matching desktop application on Windows 7 and MacOS. On Windows 7 and Macintosh, the firewall asks for permission when the app is run.</p> <br /><h3>回答1:</h3><br /><p>The Windows 10 machine in question automatically installed McAfee internet. I uninstalled McAfee and the Delphi tethering apps immediately triggered Firewall exception request and then worked properly.</p> <p>Even though I added the Delphi tethering apps to the Windows firewall exception list, McAfee apparently still blocked the apps. The Delphi apps never raised an error when blocked. </p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/47166086/delphi-apps-wont-tether-on-windows-10</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/delphi" hreflang="zh-hans">Delphi</a></div> <div class="field--item"><a href="/tag/tethering" hreflang="zh-hans">tethering</a></div> </div> </div> Tue, 10 Dec 2019 18:21:45 +0000 蓝咒 2171011 at https://www.e-learn.cn