startUsingNetworkFeature and requestRouteToHost De

2019-07-25 03:33发布

问题:

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();
                }
            });