requestRouteToHost(int networkType,int hostAddress)在6.0中不起作用

时间:2016-03-31 11:03:32

标签: android android-studio android-networking connectivity android-mms

requestRouteToHost(int networkType,int hostAddress)

在API级别21中,此方法已弃用。已弃用以支持

requestNetwork(NetworkRequest,NetworkCallback)

bindProcessToNetwork(网络)  和 getSocketFactory()

API。在 M 及更高版本中,此方法不受支持,如果调用则会抛出UnsupportedOperationException。 Reference of Android Docs

Android官方网站没有任何实现作为 requestRouteToHost(int networkType,int hostAddress)的替代

我谷歌找到了这个

       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

                  ConnectivityManager connMgr = (ConnectivityManager) this
                        .getSystemService(Context.CONNECTIVITY_SERVICE);

                    NetworkRequest.Builder builder = new NetworkRequest.Builder();

                    //what Capability i have to add for 
                    **requestRouteToHost(int networkType, int hostAddress)** implementation.
                    builder.addCapability(NetworkCapabilities.NET_CAPABILITY_MMS);
                    builder.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);

                    NetworkRequest networkRequest = builder.build();
                    connMgr.requestNetwork(networkRequest, new ConnectivityManager.NetworkCallback() {

                        @Override
                        public void onAvailable(Network network) {
                            super.onAvailable(network);
                            //  sendNormalMms();
                            try {
                                int y = Integer.parseInt(apns.get(0).MMSPort);
                                HttpUtils.httpConnection(mContext, 4444L,
                                        apns.get(0).MMSCenterUrl, bytesToSend,
                                        HttpUtils.HTTP_POST_METHOD,
                                        !TextUtils.isEmpty(apns.get(0).MMSProxy),
                                        apns.get(0).MMSProxy, y);

                            } catch (Exception e) {
                            }
                        }
                    });

问题:连接尚未准备好发送彩信 curser没有进入OnAvalabile();

这是准备好发送彩信的权利吗?

1 个答案:

答案 0 :(得分:0)

找到问题:

移动数据已被删除,这就是国家尚未准备好发送彩信的原因。