重要提示: 请勿将账号共享给其他人使用,违者账号将被封禁!
查看《购买须知》>>>
当前位置: 首页 > 大学网课 > 大学网课
网友您好, 请在下方输入框内输入要搜索的题目:
搜题

题目

[主观题]

【简答题】编程实现功能:删去一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。 例如,若一维数组中的数据是:

答案
手机中每个应用程序消耗了多少手机流量,那么这些功能Android中是如何实现的呢?按照惯例,先来谈谈原理级别的东西。Android系统中封装了一套流量数据API,这些API可以很好的管理Android系统流量使用情况。可以基于这些Android API来实现管理手机流量的功能。这些API很好的封装在了android.net包下的TrafficStats中,主要的方法有:
TrafficStats.getMobileRxBytes();//2g/3g接收的流量
TrafficStats.getMobileRxPackets();//2g/3g接收的包信息
TrafficStats.getMobileTxBytes();//2g/3g上传的流量
TrafficStats.getMobileTxPackets();//2g/3g上传的包信息
TrafficStats.getTotalRxBytes();//手机总共接收的流量
TrafficStats.getTotalTxBytes();//手机总共上传的流量
TrafficStats.getUidRxBytes(uid); //得到某个应用程程序接收的流量
TrafficStats.getUidTxBytes(uid); //得到某个应用程程序接收的流量
基于这些方法实现一个Android手机流量管理的程序示例。
Android编程实现简单流量管理功能:
packagecn.itcast.mobilesafe.ui;
importjava.util.List;
importandroid.app.Activity;
importandroid.content.Intent;
importandroid.content.pm.PackageManager;
importandroid.content.pm.ResolveInfo;
importandroid.graphics.drawable.Drawable;
importandroid.net.TrafficStats;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroid.widget.BaseAdapter;
importandroid.widget.ImageView;
importandroid.widget.ListView;
importandroid.widget.TextView;
importcn.itcast.mobilesafe.R;
importcn.itcast.mobilesafe.util.TextForMater;
public classTrafficManagerActivity extends Activity {
private TextView _3gTotal;
private TextView wifiTotal;
private ListView content;
private String mobileTraffic;
private String wifiTraffic;
private PackageManager pm;
private TrafficAdapter adapter;
@Override
protected void onCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
pm = getPackageManager();
setContentView(R.layout.traffic_manager);
_3gTotal = (TextView)this.findViewById(R.id._3gTotal);
wifiTotal = (TextView)this.findViewById(R.id.wifiTotal);
content = (ListView)this.findViewById(R.id.content);
setTotalData();
adapter = new TrafficAdapter();
content.addHeaderView(View.inflate(this,R.layout.traffic_title, null));
content.setAdapter(adapter);
}
private void setTotalData() {
long mobileRx =TrafficStats.getMobileRxBytes();
long mobileTx = TrafficStats.getMobileTxBytes();
long totalRx =TrafficStats.getTotalRxBytes();
long totalTx =TrafficStats.getTotalTxBytes();
long wifiRx = totalRx - mobileRx;
long wifiTx = totalTx - mobileTx;
mobileTraffic =TextForMater.getDataSize(mobileRx + mobileTx);
_3gTotal.setText(mobileTraffic);
wifiTraffic =TextForMater.getDataSize(wifiTx + wifiRx);
wifiTotal.setText(wifiTraffic);
}
private class TrafficAdapter extendsBaseAdapter{
List<ResolveInfo> resolveInfos ;
public TrafficAdapter() {
super();
Intent intent = new Intent();
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
resolveInfos =pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
}
@Override
public int getCount() {
return resolveInfos.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, ViewconvertView, ViewGroup parent) {
View view ;
if(null == convertView){
view =View.inflate(getApplicationContext(), R.layout.traffic_item, null);
}else{
view = convertView;
}
ViewHolder holder = new ViewHolder();
holder.iv_traffic_icon = (ImageView)view.findViewById(R.id.iv_traffic_icon);
holder.tv_traffic_name = (TextView)view.findViewById(R.id.tv_traffic_name);
holder.tv_traffic_tx = (TextView)view.findViewById(R.id.tv_traffic_tx);
holder.tv_traffic_rx = (TextView)view.findViewById(R.id.tv_traffic_rx);
ResolveInfo info =resolveInfos.get(position);
String appName =info.loadLabel(pm).toString();
holder.tv_traffic_name.setText(appName);
Drawable icon = info.loadIcon(pm);
holder.iv_traffic_icon.setImageDrawable(icon);
int uid = info.activityInfo.applicationInfo.uid;
holder.tv_traffic_rx.setText(TextForMater.getDataSize(TrafficStats.getUidRxBytes(uid)));
holder.tv_traffic_tx.setText(TextForMater.getDataSize(TrafficStats.getUidTxBytes(uid)));
return view;
}
}
static class ViewHolder{
ImageView iv_traffic_icon;
TextView tv_traffic_name;
TextView tv_traffic_tx;
TextView tv_traffic_rx;
}
}
traffic_manager.xml
<?xmlversion="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2G/3G总流量" />
<TextView
android:id="@+id/_3gTotal"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Wifi总流量" />
<TextView
android:id="@+id/wifiTotal"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</TableRow>
</TableLayout>
<SlidingDrawer
android:id="@+id/ll_sd_traffic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:content="@+id/content"
android:handle="@+id/handle"
android:orientation="vertical">
<ImageView
android:id="@id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/notification" />
<ListView
android:id="@id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</SlidingDrawer>
</LinearLayout>
traffic_manager_item.xml
<?xmlversion="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_traffic_icon"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/tv_traffic_name"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="名称" />
<TextView
android:id="@+id/tv_traffic_tx"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="上传" />
<TextView
android:id="@+id/tv_traffic_rx"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="下载" />
</LinearLayout>
traffic_title.xml
<?xmlversion="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="图标" />
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="名称" />
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="上传" />
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="下载" />
</LinearLayout>
更多“【简答题】编程实现功能:删去一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。 例如,若一维数组中的数据是:”相关的问题

第1题

用于删除数组中所有重复的值,返回一个由唯一值组成的数组的函数为

A.in_array()

B.Array_unique()

C.array_keys()

D.array_values()

点击查看答案

第2题

用于删除数组中所有重复的值,返回一个由唯一值组成的数组的函数为

A.in_array()

B.Array_unique()

C.array_keys()

D.array_values()

点击查看答案

第3题

编写一个函数,可以统计一维数组或二维数组元素之和。在主程序中,定义一个一维整型数组,调用函数计算元素之和;再定义一个二维整型数组,调用函数计算元素之和。
点击查看答案

第4题

编程题: 定义一个含N个整数的一维数组。实现:该数组中的前面各数顺序向后移m个位置,最后m个数变成最前面的m个数。宏定义N,其值为小于30的任意值。键盘输入一维数组的N个整数和正整数m。(程序中只能定义和使用一个数组,m<N)
点击查看答案

第5题

编程题: 定义一个含N个整数的一维数组。实现:该数组中的前面各数顺序向后移m个位置,最后m个数变成最前面的m个数。宏定义N,其值为小于30的任意值。键盘输入一维数组的N个整数和正整数m。(程序中只能定义和使用一个数组,m<N)
点击查看答案

第6题

中国剩余定理(孙子定理)是求解同余数组的方法之一,《孙子算经》中的问题:今有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二,问物几何?其答案可以是_________。

A.32

B.23

C.58

D.128

点击查看答案

第7题

实现模拟窗体菜单功能,实现对一维二维数组基本操作进行测试,具体菜单功能如下: 当输入11、12、13,分别执行一维数组数据录入;执行一维数组的每个元素增加10,并提示操作成功;显示一维数组的所有元素; 当输入21、22、23,分别执行二维数组数据录入;执行二维数组的每个元素增加5,并提示操作成功;显示二维数组的所有元素; 当输入quit,则退出
点击查看答案

第8题

中国剩余定理(孙子定理)是求解同余数组的方法之一,《孙子算经》中的问题:今有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二,问物几何?其答案可以是_________。

A.32

B.23

C.58

D.128

点击查看答案

第9题

二维数组可以看成一个一维数组,这个一维数组中存放的是各个一维数组的首地址
点击查看答案
赏学吧APP
TOP
重置密码
账号:
旧密码:
新密码:
确认密码:
确认修改
购买搜题卡查看答案
购买前请仔细阅读《购买须知》
请选择支付方式
微信支付
支付宝支付
点击支付即表示你同意并接受《服务协议》《购买须知》
立即支付
搜题卡使用说明

1. 搜题次数扣减规则:

功能 扣减规则
基础费
(查看答案)
加收费
(AI功能)
文字搜题、查看答案 1/每题 0/每次
语音搜题、查看答案 1/每题 2/每次
单题拍照识别、查看答案 1/每题 2/每次
整页拍照识别、查看答案 1/每题 5/每次

备注:网站、APP、小程序均支持文字搜题、查看答案;语音搜题、单题拍照识别、整页拍照识别仅APP、小程序支持。

2. 使用语音搜索、拍照搜索等AI功能需安装APP(或打开微信小程序)。

3. 搜题卡过期将作废,不支持退款,请在有效期内使用完毕。

请使用微信扫码支付(元)
订单号:
遇到问题请联系在线客服
请不要关闭本页面,支付完成后请点击【支付完成】按钮
遇到问题请联系在线客服
恭喜您,购买搜题卡成功 系统为您生成的账号密码如下:
重要提示: 请勿将账号共享给其他人使用,违者账号将被封禁。
发送账号到微信 保存账号查看答案
怕账号密码记不住?建议关注微信公众号绑定微信,开通微信扫码登录功能
警告:系统检测到您的账号存在安全风险

为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!

- 微信扫码关注赏学吧 -
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反赏学吧购买须知被冻结。您可在“赏学吧”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
- 微信扫码关注赏学吧 -
请用微信扫码测试
温馨提示
每个试题只能免费做一次,如需多次做题,请购买搜题卡
立即购买
稍后再说
赏学吧