当前位置: 编程技术>移动开发
本页文章导读:
▪任务管理器查看在运行的程序和服务 任务管理器查看正在运行的程序和服务
添加权限
<uses-permission
android:name="android.permission.GET_TASKS"></uses-permission>
private ListView myList;
private ActivityManager mActivityManager;
private But.........
▪ 模糊查询 条件中包孕% 模糊查询 条件中包含%
RULE_NAME like '%'||replace('a%b%c','%','\%')||'%' ESCAPE'\'
......
▪ WifiManager打开封锁Wifi以及搜索Wifi WifiManager打开关闭Wifi以及搜索Wifi
Wifi的五种状态
WifiManager.WIFI_STATE_ENABLED//已打开
WifiManager.WIFI_STATE_DISABLING//正在关闭
WifiManager.WIFI_STATE_ENABLING//正在打开
WifiManager.WIFI_STATE_DISABLED//已关.........
[1]任务管理器查看在运行的程序和服务
来源: 互联网 发布时间: 2014-02-18
任务管理器查看正在运行的程序和服务
添加权限
<uses-permission android:name="android.permission.GET_TASKS"></uses-permission>
private ListView myList; private ActivityManager mActivityManager; private Button button1; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.running_task); myList = (ListView) findViewById(R.id.listView1); button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { try { /* ActivityManager对象守系统取得ACTIVITY_SERVICE */ mActivityManager = (ActivityManager) RunningTask.this .getSystemService(ACTIVITY_SERVICE); ArrayList<String> arylistTask = new ArrayList<String>(); int intGetTastCounter = 30; /* 以getRunningTasks方法取并正在运行中的程序TaskInfo */ List<ActivityManager.RunningTaskInfo> mRunningTasks = mActivityManager .getRunningTasks(intGetTastCounter); // List<ActivityManager.RunningServiceInfo> mRunningTasks = // mActivityManager.getRunningServices(intGetTastCounter); int i = 1; /* 以循环及baseActivity方式取得名称与ID */ for (ActivityManager.RunningTaskInfo amTask : mRunningTasks) // for (ActivityManager.RunningServiceInfo amTask : // mRunningTasks) { arylistTask.add("" + (i++) + ": " + amTask.baseActivity.getClassName() + "(ID=" + amTask.id + ")"); // arylistTask.add("" + (i++) + ": "+ amTask.process + // "(ID=" + amTask.pid +")"); } ArrayAdapter<String> aryAdapter1 = new ArrayAdapter<String>( RunningTask.this, R.layout.list_item2, arylistTask); if (aryAdapter1.getCount() == 0) { /* 当没有任何运行的操作,则提示信息 */ Toast.makeText(RunningTask.this, "当前没有进行的任务", Toast.LENGTH_SHORT); // getResources().getText(R.string.str_err_no_running_service).toString(), } else { /* 发现后台运行程序,以ListView Widget条在出现 */ myList.setAdapter(aryAdapter1); } } catch (SecurityException e) { /* 当无GET_TASKS权限时(SecurityException例?)提示信息 */ Toast.makeText(RunningTask.this, "无GET_TASKS权限", Toast.LENGTH_SHORT); } } }); }
[2] 模糊查询 条件中包孕%
来源: 互联网 发布时间: 2014-02-18
模糊查询 条件中包含%
RULE_NAME like '%'||replace('a%b%c','%','\%')||'%' ESCAPE'\'
[3] WifiManager打开封锁Wifi以及搜索Wifi
来源: 互联网 发布时间: 2014-02-18
WifiManager打开关闭Wifi以及搜索Wifi
Wifi的五种状态
WifiManager.WIFI_STATE_ENABLED//已打开 WifiManager.WIFI_STATE_DISABLING//正在关闭 WifiManager.WIFI_STATE_ENABLING//正在打开 WifiManager.WIFI_STATE_DISABLED//已关闭 WifiManager.WIFI_STATE_UNKNOWN//未知
一、打开关闭Wifi
添加权限
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses-permission> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
private ToggleButton toggleButton1; private WifiManager mWiFiManager01; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.wifi); toggleButton1 = (ToggleButton)findViewById(R.id.toggleButton1); /* 以getSystemService取得WIFI_SERVICE */ mWiFiManager01 = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); if(mWiFiManager01.getWifiState() == WifiManager.WIFI_STATE_ENABLED){ toggleButton1.setChecked(true); toggleButton1.setEnabled(true); } else if(mWiFiManager01.getWifiState() == WifiManager.WIFI_STATE_DISABLED){ toggleButton1.setChecked(false); toggleButton1.setEnabled(true); } else{ toggleButton1.setChecked(false); toggleButton1.setEnabled(false); } toggleButton1.setOnCheckedChangeListener(new ToggleButton.OnCheckedChangeListener(){ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked == true){ mWiFiManager01.setWifiEnabled(true); } else{ mWiFiManager01.setWifiEnabled(false); } } }); }
二、搜索wifi
private Button button1; private WifiManager mWiFiManager01; private SimpleAdapter listItemAdapter; // ListView的适配器 private ArrayList<HashMap<String, Object>> listItem; // ListView的数据源,这里是一个HashMap的列表 private ListView myList; // ListView控件 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.wifi_connect); button1 = (Button) findViewById(R.id.button1); mWiFiManager01 = (WifiManager) this .getSystemService(Context.WIFI_SERVICE); mWiFiManager01.startScan(); listItem = new ArrayList<HashMap<String, Object>>(); listItemAdapter = new SimpleAdapter(this, listItem, R.layout.list_item, new String[] { "title", "text" }, new int[] { R.id.ItemTitle, R.id.ItemText }); myList = (ListView) findViewById(R.id.list); myList.setAdapter(listItemAdapter); button1.setOnClickListener(new OnClickListener() { public void onClick(View v) { List<WifiConfiguration> wifiConf = mWiFiManager01 .getConfiguredNetworks(); if ((!mWiFiManager01.isWifiEnabled()) && (mWiFiManager01.getWifiState() != WifiManager.WIFI_STATE_ENABLING)) { mWiFiManager01.setWifiEnabled(true); } if (wifiConf.size() > 0) { int netWorkId = wifiConf.get(0).networkId; mWiFiManager01.enableNetwork(netWorkId, true); int index = 0; for (WifiConfiguration singleWifiConf : wifiConf) { addItem((index + 1) + " SSID." + singleWifiConf.SSID, "NetWorkID:" + singleWifiConf.networkId); index = index + 1; } } } }); } private void addItem(String title, String str) { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("title", title); map.put("text", str); listItem.add(map); listItemAdapter.notifyDataSetChanged(); }
最新技术文章: