startUsingNetworkFeature和requestRouteToHost在6.0替代版本中折旧

时间:2016-03-31 07:41:36

标签: android network-programming httprequest mms

用于发送mms的就绪设备在Kitkat中运行良好,但Pro KitKat版本 startUsingNetworkFeature 已弃用。

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

如何在6.0中实现此功能我试过这个。 我有移动设备mms功能,但我怎样才能使用这个功能 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 6.0的实现?

1 个答案:

答案 0 :(得分:1)

我在下面的问题工作正常,我忘了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();
                }
            });