问题描述
SDK:安卓5.0.1
SDK: Android 5.0.1.
Android编译:LRX22C
Android build: LRX22C.
设备:5的Nexus
Device : Nexus 5.
问题:奇巧(4.4.4)及以下的API
Problem:KITKAT(4.4.4) and below API's
1)startUsingNetworkFeature(INT NETWORKTYPE,字符串功能)这种方法去precated。德precated有利于清洁requestNetwork的(NetworkRequest,ConnectivityManager.NetworkCallback)。
1)startUsingNetworkFeature(int networkType, String feature)This method is deprecated. Deprecated in favor of the cleaner requestNetwork(NetworkRequest, ConnectivityManager.NetworkCallback).
2)requestRouteToHost(INT NETWORKTYPE,INT hostAddress)这种方法去precated。德precated赞成requestNetwork(NetworkRequest,ConnectivityManager.NetworkCallback),setProcessDefaultNetwork(网络),并在getSocketFactory的()。
2)requestRouteToHost(int networkType, int hostAddress)This method is deprecated. Deprecated in favor of the requestNetwork(NetworkRequest, ConnectivityManager.NetworkCallback), setProcessDefaultNetwork(Network) and getSocketFactory().
被用来发送请求了移动数据网络时,WIFI和移动数据上。
were used to send request over Mobile Data Network when WIFI and mobile data were on.
开始的Android L时API的是德precated,不再工作。
Starting Android L the API's is deprecated and no longer work.
新的API /班NetworkRequest.Builder,NetworkRequest,ConnectivityManager.NetworkCallback,requestNetwork,registerNetworkCallback被使用。这里详细的API使用
<一href="http://pbz.kt.agh.edu.pl/~krusek/l-developer-$p$pview/reference/android/net/ConnectivityManager.html">Android大号的API
New API's/Classes NetworkRequest.Builder,NetworkRequest,ConnectivityManager.NetworkCallback,requestNetwork,registerNetworkCallback were used.Detail Here on API usage
Android L API's
code:
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkRequest.Builder builder = new NetworkRequest.Builder();
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED);
builder.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
NetworkRequest networkRequest = builder.build();
connectivityManager.requestNetwork(networkRequest, networkCallback);
connectivityManager.registerNetworkCallback(networkRequest, networkCallback);
工作方案:
在onAvailable回调唯一的移动数据接收。
Only mobile data on onAvailable callback is received.
不工作方案:移动和无线上并连接,onAvailable回调不会从system.Hence收到无法设置setProcessDefaultNetworkConnectivityManager.setProcessDefaultNetwork(preferedNetwork);
Not working Scenario:Both Mobile and Wifi is on and connected,onAvailable callback is not received from system.Hence not able to set setProcessDefaultNetworkConnectivityManager.setProcessDefaultNetwork(preferedNetwork);
经常:始终
期望的输出:获得移动网络avaliabe回调时,WiFi是在
Expected output: Get mobile network avaliabe callback when wifi is on.
我缺少的东西在这里或固件存在一些问题吗?
Am i missing something here or the firmware has some issues here?
亚行日志:
09-18 18:50:42.617: I/art(1339): Heap transition to ProcessStateJankImperceptible took 64.332086ms saved at least 225KB
09-18 18:50:43.060: I/auditd(16947): type=1400 audit(0.0:899): avc: denied { getattr } for comm="ls" path="/persist" dev="mmcblk0p16" ino=2 scontext=u:r:shell:s0 tcontext=u:object_r:persist_file:s0 tclass=dir
09-18 18:50:43.422: I/ActivityManager(769): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.networktest/.MainActivity (has extras)} from pid 1149 on display 0
09-18 18:50:43.423: I/am_create_task(769): [0,20]
09-18 18:50:43.423: I/am_create_activity(769): [0,145055245,20,com.example.networktest/.MainActivity,android.intent.action.MAIN,NULL,NULL,270532608]
09-18 18:50:43.424: I/wm_task_created(769): [20,1]
09-18 18:50:43.424: I/wm_task_moved(769): [20,1,2]
09-18 18:50:43.424: I/am_pause_activity(769): [0,613529891,com.google.android.googlequicksearchbox/com.google.android.launcher.GEL]
09-18 18:50:43.442: I/am_destroy_service(769): [0,453570950,2161]
09-18 18:50:43.444: D/audio_hw_primary(200): select_devices: out_snd_device(2: speaker) in_snd_device(0: )
09-18 18:50:43.447: I/am_on_paused_called(1149): [0,com.google.android.launcher.GEL]
09-18 18:50:43.492: I/am_proc_start(769): [0,16964,10091,com.example.networktest,activity,com.example.networktest/.MainActivity]
09-18 18:50:43.492: I/ActivityManager(769): Start proc com.example.networktest for activity com.example.networktest/.MainActivity: pid=16964 uid=10091 gids={50091, 3003}
09-18 18:50:43.497: I/am_create_service(769): [0,565414612,.LightweightIndexService,10009,1339]
09-18 18:50:43.501: I/art(16964): Late-enabling -Xcheck:jni
09-18 18:50:43.522: I/am_proc_bound(769): [0,16964,com.example.networktest]
09-18 18:50:43.524: I/am_restart_activity(769): [0,145055245,20,com.example.networktest/.MainActivity]
09-18 18:50:43.526: I/art(16964): Profiler disabled. To enable setprop dalvik.vm.profiler 1
09-18 18:50:43.533: I/am_create_service(769): [0,28763261,.LightweightIndexService$LightweightWorkerService,10009,1339]
09-18 18:50:43.536: I/am_destroy_service(769): [0,28763261,1339]
09-18 18:50:43.575: D/ConnectivityService(769): requestNetwork for NetworkRequest [ id=18, legacyType=-1, [ Transports: CELLULAR Capabilities: NOT_RESTRICTED] ]
09-18 18:50:43.575: D/ConnectivityService(769): handleRegisterNetworkRequest checking NetworkAgentInfo [WIFI ()]
09-18 18:50:43.575: D/ConnectivityService(769): sending new NetworkRequest to factories
09-18 18:50:43.575: D/WIFI(769): got request NetworkRequest [ id=18, legacyType=-1, [ Transports: CELLULAR Capabilities: NOT_RESTRICTED] ] with score 0
09-18 18:50:43.575: D/WIFI(769): my score=60, my filter=[ Transports: WIFI Capabilities: INTERNET&NOT_RESTRICTED LinkUpBandwidth>=1048576Kbps LinkDnBandwidth>=1048576Kbps]
09-18 18:50:43.575: D/Ethernet(769): got request NetworkRequest [ id=18, legacyType=-1, [ Transports: CELLULAR Capabilities: NOT_RESTRICTED] ] with score 0
09-18 18:50:43.575: D/Ethernet(769): my score=-1, my filter=[ Transports: ETHERNET Capabilities: INTERNET&NOT_RESTRICTED LinkUpBandwidth>=100000Kbps LinkDnBandwidth>=100000Kbps]
09-18 18:50:43.575: D/TelephonyNetworkFactory(1113): got request NetworkRequest [ id=18, legacyType=-1, [ Transports: CELLULAR Capabilities: NOT_RESTRICTED] ] with score 0
09-18 18:50:43.575: D/TelephonyNetworkFactory(1113): my score=50, my filter=[ Transports: CELLULAR Capabilities: MMS&SUPL&DUN&FOTA&IMS&CBS&IA&RCS&XCAP&EIMS&INTERNET&NOT_RESTRICTED]
09-18 18:50:43.576: D/TelephonyNetworkFactory(1113): Cellular needs Network for NetworkRequest [ id=18, legacyType=-1, [ Transports: CELLULAR Capabilities: NOT_RESTRICTED] ]
09-18 18:50:43.576: D/ConnectivityService(769): listenForNetwork for NetworkRequest [ id=19, legacyType=-1, [ Transports: CELLULAR Capabilities: NOT_RESTRICTED] ]
09-18 18:50:43.577: D/ConnectivityService(769): handleRegisterNetworkRequest checking NetworkAgentInfo [WIFI ()]
09-18 18:50:43.841: I/am_create_service(769): [0,510459843,.EventLoggerService,10022,2161]
09-18 18:50:43.855: I/am_create_service(769): [0,271933548,.GetToken,10009,1339]
09-18 18:50:43.899: I/am_create_service(769): [0,609002555,.GoogleAccountDataService,10009,1339]
09-18 18:50:43.902: W/GLSUser(1339): GoogleAccountDataService.getToken()
09-18 18:50:43.910: I/am_destroy_service(769): [0,609002555,1339]
09-18 18:50:43.914: I/am_destroy_service(769): [0,271933548,1339]
09-18 18:50:43.996: I/sf_frame_dur(197): [com.google.android.googlequicksearchbox/com.google.android.launcher.GEL,89,0,2,0,1,2,1]
09-18 18:50:44.299: I/am_destroy_service(769): [0,510459843,2161]
09-18 18:50:44.760: I/art(16309): Heap transition to ProcessStateJankImperceptible took 6.712188ms saved at least 830KB
09-18 18:50:48.070: I/auditd(17031): type=1400 audit(0.0:900): avc: denied { getattr } for comm="ls" path="/persist" dev="mmcblk0p16" ino=2 scontext=u:r:shell:s0 tcontext=u:object_r:persist_file:s0 tclass=dir
09-18 18:50:48.579: I/am_on_resume_called(16964): [0,com.example.networktest.MainActivity]
09-18 18:50:48.587: D/CanvasContext(16964): Render dirty regions requested: true
09-18 18:50:48.592: I/am_destroy_service(769): [0,565414612,1339]
09-18 18:50:48.597: I/art(2161): Heap transition to ProcessStateJankImperceptible took 109.715785ms saved at least 2MB
09-18 18:50:48.626: W/Adreno-GSL(16964): <ioctl_kgsl_device_getproperty:663>: mmap failed: errno 22 Invalid argument
09-18 18:50:48.626: I/Adreno-EGL(16964): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I10246dbd022c719c705be805d5642cc8fdfbd2a2Date: 03/07/14
09-18 18:50:48.626: I/CanvasContext(16964): Initialized EGL, version 1.4
09-18 18:50:48.644: I/art(1149): Heap transition to ProcessStateJankImperceptible took 75.768178ms saved at least 2MB
09-18 18:50:48.644: D/OpenGLRenderer(16964): Enabling debug mode 0
09-18 18:50:48.650: I/art(1252): Heap transition to ProcessStateJankImperceptible took 92.615158ms saved at least 384KB
09-18 18:50:48.688: I/am_activity_launch_time(769): [0,145055245,com.example.networktest/.MainActivity,5230,5230]
09-18 18:50:48.688: I/ActivityManager(769): Displayed com.example.networktest/.MainActivity: +5s230ms
09-18 18:50:48.904: I/sf_frame_dur(197): [Starting com.example.networktest,1,0,0,0,0,0,0]
编辑:的 谷歌错误提出2 是什么无可奉告输入了这种变化的从谷歌是什么意思?
Google bug raised 1 Google bug raised 2 What does "No comment was entered for this change" mean from google?
感谢
Nithin
推荐答案
好了this.Trick终于找到了解决办法就是使用能力作为NET_CAPABILITY_INTERNET.Which是一样的startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,FEATURE_ENABLE_HIPRI);
Well finally found solution for this.Trick was to use capability as NET_CAPABILITY_INTERNET.Which is same as "startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, FEATURE_ENABLE_HIPRI);"
<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/5.0.2_r1/android/net/ConnectivityManager.java#ConnectivityManager.networkCapabilitiesForFeature%28int%2Cjava.lang.String%29"相对=nofollow>看到这里固件设计
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
builder.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
在此,我能够得到onAvailable回调的系统,后来我把我的过程中默认的网络移动数据。
After this i am able to get onAvailable callback from system and later i set my process default network as mobile data.
因此,所有的请求都要通过移动数据,即使WiFi是on.WOW!
Hence all the request goes over Mobile data even if wifi is on.WOW!
请注意:这是不工作的preVIEW大号最初发布
Note: This was not working in initial releases of Preview L.
编辑19-10-2015: setProcessDefaultNetwork现在depcreated使用bindProcessToNetwork
Edit 19-10-2015: setProcessDefaultNetwork is now depcreated use bindProcessToNetwork
这篇关于发送申请过手机数据时WIFI为ON。(安卓L)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!