Android: Force data to be sent over radio vs WiFi

前端 未结 5 1643
轮回少年
轮回少年 2020-12-02 21:36

Is it possible to force an Android application to use only the mobile radio connection (3g/4g/etc), disallowing the use of WiFi?

I think I want to use a HIPRI conne

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 22:18

    I don't believe you can "force" the connection path without explicitly turning off the Wi-Fi radio temporarily (not recommended). However, you could try setting the network preference during the period you want this to occur:

    ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    //Prefer mobile over wifi
    cm.setNetworkPreference(ConnectivityManager.TYPE_MOBILE);
    
    //Do your work
    
    //Remove your preference
    cm.setNetworkPreference(ConnectivityManager.DEFAULT_NETWORK_PREFERENCE);
    

    Hope that Helps!

提交回复
热议问题