当前位置:网站首页>Systemservice (system service)
Systemservice (system service)
2022-07-27 19:52:00 【Ashurol】
android The system gives us a lot of services , For our development and use , for example , Check network usage , Equipment power ,SD Card installation or removal , Some application information, etc .
Simple acquisition android A few simple services
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
}
public void doClick(View v)
{
switch(v.getId())
{
case R.id.getvoice:
AudioManager mAudioManager= (AudioManager) MainActivity.this.getSystemService(AUDIO_SERVICE);
int max = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_SYSTEM);// Get the maximum volume of the system
int current = mAudioManager.getStreamVolume(AudioManager.STREAM_RING);// Get the current volume
Toast.makeText(MainActivity.this, " The maximum volume of the system is :"+max+", Current volume is :"+current, Toast.LENGTH_SHORT).show();
break;
case R.id.enableOrDisable_WIFI:
WifiManager wifiManager = (WifiManager) MainActivity.this.getSystemService(WIFI_SERVICE);
if (wifiManager.isWifiEnabled()) {
// Decide whether to open , Turn it off if you turn it on
wifiManager.setWifiEnabled(false);
Toast.makeText(MainActivity.this, "WIFI It's closed ", Toast.LENGTH_SHORT).show();
}else {
// Decide whether to open , Turn it on if you close it
wifiManager.setWifiEnabled(true);
Toast.makeText(MainActivity.this, "WIFI Already open ", Toast.LENGTH_SHORT).show();
}
break;
case R.id.getPackagename:
ActivityManager activityManager = (ActivityManager) MainActivity.this.getSystemService(ACTIVITY_SERVICE);
String packageName = activityManager.getRunningTasks(1).get(0).topActivity.getPackageName();// obtain Activity The package name
Toast.makeText(MainActivity.this, " Currently running Activity Package name :"+packageName, Toast.LENGTH_SHORT).show();
break;
case R.id.network:
if (isNetWorkConnected(MainActivity.this)==true) {
Toast.makeText(MainActivity.this, " The network has been turned on ", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(MainActivity.this, " Network not connected ", Toast.LENGTH_SHORT).show();
}
break;
}
}
private boolean isNetWorkConnected(Context context) {
// TODO Auto-generated method stub
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo mNetWorkInfo = mConnectivityManager
.getActiveNetworkInfo();
if (mNetWorkInfo != null) {
return mNetWorkInfo.isAvailable();
}
}
return false;
}
}
Make the layout by yourself according to the pictures , Don't post it here


}
边栏推荐
- 应用程序池已被禁用
- Surpass Huawei? Ericsson has won more than 75 5g commercial contracts
- ToggleButton(按钮开关)
- 查看宝塔PHP扩展目录
- What's new in helix QAC 2022.2, the ace code static testing tool (1)
- JVM概述和内存管理(未完待续)
- 反超华为?爱立信已拿下超过75份5G商用合同
- [daily accumulation - 07] CUDA multi version switching
- 【深度学习目标检测系列 - 01】目标检测是什么
- 【深度学习基础知识 - 49】Kmeans
猜你喜欢

Virtualbox:ssh connection

Flink introduction and operation architecture

SharePreference(存储)

下放三星3J1传感器:代码暗示Pixel 7人脸识别安全性将大增

Map和Set

JS find all nodes sibling childNodes children

Chinese character search Pinyin wechat applet project source code

Combinatorics -- permutation and combination

JS event listening mouse keyboard form page onclick onkeydown onchange

ToggleButton(按钮开关)
随机推荐
王牌代码静态测试工具Helix QAC 2022.2中的新增功能(2)
[deep learning target detection series - 01] what is target detection
【深度学习基础知识 - 49】Kmeans
JS 寻找所有节点sibling childNodes children
A low code development platform that brings high-value user experience
记一次无准备的实习面试
Optimization of fixed number of cycles in embedded C language
Incluxdb series (III) detailed explanation of incluxdb configuration file
链表~~~
Introduction to several wireless protocols
四大组件之ContentProvider
Embedded C language loop deployment
pytorch乘法以及广播机制
【深度学习基础知识 - 43】优势比的概念
BroadcastReceiver(广播)
坚持软硬一体化,一恒科发力智能化教育机器人市场
SharePreference(存储)
[daily accumulation - 07] CUDA multi version switching
Come to sword finger offer 03. Repeated numbers in the array
JS 事件监听 鼠标 键盘 表单 页面 onclick onkeydown onChange