startUsingNetworkFeature and requestRouteToHost Depreciated in 6.0 alternative to this

我是研究僧i 提交于 2019-12-24 08:23:12

问题


Ready device for sending mms works fine in Kitkat but Pro KitKat version startUsingNetworkFeature is depreciated.

final int result = mConnMgr.startUsingNetworkFeature(
                    ConnectivityManager.TYPE_MOBILE, "enableMMS");
            final ProgressDialog dialog =
                    ProgressDialog.show(mContext, "", getString(R.string.compose_thread_dailog_converting_multi));

            if (result != 0) {
                IntentFilter filter = new IntentFilter();
                filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
                receiver = new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {

                        String action = intent.getAction();
                        Log.i("recived", "action");
                        if (!action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {

                            return;
                        }

                        NetworkInfo mNetworkInfo = (NetworkInfo) intent
                                .getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);

                        if ((mNetworkInfo == null)
                                || (mNetworkInfo.getType() != ConnectivityManager.TYPE_MOBILE_MMS)) {

                            return;
                        }

                        if (!mNetworkInfo.isConnected()) {

                            return;
                        } else {
                            Log.i("recived", "OK mms features");
                            context.unregisterReceiver(receiver);
                            dialog.dismiss();
                            sendNormalMms();


                        }
                    }
                };

                context.registerReceiver(receiver, filter);
            } else {
                // sendData(recipient, SentMMS);

                Log.i("recived", "OK mms features");
                // context.unregisterReceiver(receiver);
                dialog.dismiss();
                sendNormalMms();
            }
        }

How can i achieve this feature in 6.0 i tried this. i got the mobile device mms feature on but how can i use this funtion requestRouteToHost

              NetworkRequest.Builder builder = new NetworkRequest.Builder();
//        builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
            builder.addCapability(NetworkCapabilities.NET_CAPABILITY_MMS);
            builder.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);

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

                @Override
                public void onAvailable(Network network) {
                    super.onAvailable(network);
                    dialog.dismiss();
                    sendNormalMms();
                }
            });

requestRouteToHost implementation for 6.0 is needed ?


回答1:


I got the issue below is working fine i just forget to turn on mobile data.

            NetworkRequest.Builder builder = new NetworkRequest.Builder();
            builder.addCapability(NetworkCapabilities.NET_CAPABILITY_MMS);
            builder.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);

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

                @Override
                public void onAvailable(Network network) {
                    super.onAvailable(network);
                    dialog.dismiss();
                    sendNormalMms();
                }
            });


来源:https://stackoverflow.com/questions/36327120/startusingnetworkfeature-and-requestroutetohost-depreciated-in-6-0-alternative-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!