2

My instant app crash when i run script “WifiManager.isWifiEnable”

 Caused by: java.lang.SecurityException: Method class android.net.wifi.IWifiManager$Stub$Proxy.getWifiEnabledState[] not available to instant apps
                                                 at android.os.Parcel.readException(Parcel.java:1620)
                                                 at android.os.Parcel.readException(Parcel.java:1573)
                                                 at com.google.android.instantapps.supervisor.ipc.base.MethodInvocationProxy.readReply(MethodInvocationProxy.java:238)
                                                 at com.google.android.instantapps.supervisor.ipc.base.MethodInvocationProxy.invoke(MethodInvocationProxy.java:472)
                                                 at java.lang.reflect.Proxy.invoke(Proxy.java:393)
                                                 at $Proxy15.getWifiEnabledState(Unknown Source)
                                                 at android.net.wifi.WifiManager.getWifiState(WifiManager.java:1459)
                                                 at android.net.wifi.WifiManager.isWifiEnabled(WifiManager.java:1471)
Onik
  • 19,396
  • 14
  • 68
  • 91

2 Answers2

1

That's expected since Instant Apps are sandboxed and don't have access to the device's full capabilities (no read/write for example). You'll have to work around this depending on whether or not you're an Instant App. Here's the full list of available permissions:

  • BILLING
  • ACCESS_COARSE_LOCATION
  • ACCESS_FINE_LOCATION
  • ACCESS_NETWORK_STATE
  • CAMERA
  • INSTANT_APP_FOREGROUND_SERVICE only in Android 8.0.
  • INTERNET
  • READ_PHONE_NUMBERS. This permission is available only in Android 8.0 (API level 26).
  • RECORD_AUDIO
  • VIBRATE

PS: ADB did a really cool episode where they discussed how Instant Apps work (and the sandboxing).

Also see: https://github.com/googlesamples/android-instant-apps/issues/12

SUPERCILEX
  • 3,929
  • 4
  • 32
  • 61
  • Thank you,.So instant app really don't support aidl? – Wang Yixiong Dec 28 '17 at 02:42
  • Instant apps don't support certain permissions to protect the user, but AIDL can be used for any interprocess communication. Are you just trying to see if there's an internet connection? If so, I would take a look at this answer: https://stackoverflow.com/a/4239019/4548500. – SUPERCILEX Dec 28 '17 at 06:16
1

WifiManager This class provides the primary API for managing all aspects of Wi-Fi connectivity.

It defines the names of various Intent actions that are broadcast upon any sort of change in Wi-Fi state. Instances of this class must be obtained using Context.getSystemService(Class) with the argument WifiManager.class or Context.getSystemService(String) with the argument Context.WIFI_SERVICE.


setWifiEnabled require CHANGE_WIFI_STATE

This is the API to use when performing Wi-Fi specific operations. To perform operations that pertain to network connectivity at an abstract level, use ConnectivityManager.

private boolean isNetworkAvailable() {
    ConnectivityManager connectivityManager 
          = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}


You will need:

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

We can use only API methods that limited With Instant permissions

  • BILLING
  • ACCESS_COARSE_LOCATION
  • ACCESS_FINE_LOCATION
  • ACCESS_NETWORK_STATE
  • CAMERA
  • INSTANT_APP_FOREGROUND_SERVICE only in Android 8.0.
  • INTERNET READ_PHONE_NUMBERS. This permission is available only in Android 8.0 (API level 26).
  • RECORD_AUDIO VIBRATE
Prags
  • 2,457
  • 2
  • 21
  • 38