hypery2k / cordova-hotspot-plugin

A Cordova plugin for managing HotSpot networks on Android
MIT License
37 stars 49 forks source link

Hotspot creation failed due to permission error #28

Closed cajay01 closed 8 years ago

cajay01 commented 8 years ago

I am trying with new updated plugin it fix hotspot creation issue on lolipop but when I implement it with Galaxy S6 marshmallow it gives following error. What to do to fix this issue over marshmallow?

04-19 14:24:29.511 32116-32199/? E/WifiHotSpots﹕ Unknown error during saving wifi config. java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at com.mady.wifi.api.WifiHotSpots.setHotSpot(WifiHotSpots.java:505) at de.martinreinhardt.cordova.plugins.hotspot.HotSpotPlugin.createHotspot(HotSpotPlugin.java:611) at de.martinreinhardt.cordova.plugins.hotspot.HotSpotPlugin$4.run(HotSpotPlugin.java:123) at de.martinreinhardt.cordova.plugins.hotspot.HotSpotPlugin$29.run(HotSpotPlugin.java:855) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818) Caused by: java.lang.SecurityException: com.ionicframework.reliancesmarthome307271 was not granted this permission: android.permission.WRITE_SETTINGS. at android.os.Parcel.readException(Parcel.java:1620) at android.os.Parcel.readException(Parcel.java:1573) at android.net.wifi.IWifiManager$Stub$Proxy.setWifiApEnabled(IWifiManager.java:1964) at android.net.wifi.WifiManager.setWifiApEnabled(WifiManager.java:2192)             at java.lang.reflect.Method.invoke(Native Method)             at com.mady.wifi.api.WifiHotSpots.setHotSpot(WifiHotSpots.java:505)             at de.martinreinhardt.cordova.plugins.hotspot.HotSpotPlugin.createHotspot(HotSpotPlugin.java:611)             at de.martinreinhardt.cordova.plugins.hotspot.HotSpotPlugin$4.run(HotSpotPlugin.java:123)             at de.martinreinhardt.cordova.plugins.hotspot.HotSpotPlugin$29.run(HotSpotPlugin.java:855)             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)             at java.lang.Thread.run(Thread.java:818) 04-19 14:24:29.511 32116-32116/? I/chromium﹕ [INFO:CONSOLE(37)] "Hotspot creation failed", source: file:///android_asset/www/js/wfListCtrl.js (37)

webmaster-imaginet commented 8 years ago

I found that some of the plugin methods not working under android ver 6.x with the latest cordova version like 5.1.1 At the moment I use cordova 4.1.1 because that reason.

Joefi commented 8 years ago

I have the same problem ,have you find solution?

hypery2k commented 8 years ago

please check if you have the right permissions: https://github.com/hypery2k/cordova-hotspot-plugin/wiki/Android-Configuration

Joefi commented 8 years ago

Thanks for your answer. This is my code ,and I try it again after adding the permission , but it still not working (android 5.0). I try it on another phone(android 4.3), and it work;

public class WifiAp { private Context context; private WifiManager wifiManager; private String wifiSSID = "windy"; private Method method; private WifiConfiguration config; public WifiAp(Context context) { this.context = context; wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); } public void openWifiAp() { if(wifiManager.isWifiEnabled()) wifiManager.setWifiEnabled(false); config = new WifiConfiguration(); config.SSID = wifiSSID; try { method = wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,Boolean.TYPE); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block Log.d("TAG", e.toString()); e.printStackTrace(); } Log.d("TAG", "Now"); try { method.invoke(wifiManager, config,true); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block Log.d("TAG", e.toString()); e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block Log.d("TAG", e.toString()); e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block Log.d("TAG", e.toString()); e.printStackTrace(); } }

public void closeWifiAp() { try { method = wifiManager.getClass().getMethod("isWifiApEnabled"); Boolean enable = (Boolean) method.invoke(wifiManager); if(enable) { method =wifiManager.getClass().getMethod("setWifiApEnabled",WifiConfiguration.class,Boolean.TYPE); method.invoke(wifiManager, config,false); }

} catch(NoSuchMethodException e) {

} catch (IllegalArgumentException e) { // TODO Auto-generated catch block Log.d("TAG", e.toString()); e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block Log.d("TAG", e.toString()); e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block Log.d("TAG", e.toString()); e.printStackTrace(); }

}

hypery2k commented 8 years ago

why did you use Java? this plugin is for cordova hybrid apps? You're above error indicate permission errors and then you have to allow this in your cordova app. The permission model has changed on Android 5. I tested the plugin with Android 4 and Android 5 and it's working, so it's a configuration issue.

Joefi commented 8 years ago

sorry, I dont't understand your mean, I am just doing an Android application about turning on wifi hotspot, not cordova hybrid app.

cajay01 commented 8 years ago

Hey I checked the manifest file permissions are ok.It works on kitkat and Lolipop but not on marshmallow.So is there any specific code change that we need to do at plugin level?

hypery2k commented 8 years ago

If you don't use it as a Cordova plugin I'm not sure how you invoke my plugin and that's why I cannot help you with that

It's a Cordova plugin. If you don't use it as one...