之前有许多朋友都问过我,在 Android 体系中怎样才能完毕静默设备呢?所谓的静默设备,便是不用弹出体系的设备界面,在不影响用户任何操作的状程序员计算器况下不知不觉地将程序装好。尽管这种办法看上去不打搅用户,可是却存在着一个问题,由于 Android 体系会在产品运营设备界面傍边把程序所声明的权限展现给用户看,用户来点评一下这些权限然后决议是否要设备该程序,但假定运用了静默设备的办法,approach也就没有当地让用户看权限了,相当于用户被迫接受了这些权限。在 Android 官方看来,这闪现是一种十分风险的行为,因而静默设备这一行为体系是不会开放给开发者的。

可是总是弹出一个设备对话框的确是一程序员种体会比较差的行为,程序员是学什么专业这一点 Google 自己也认识到了,因而 Andrappearanceoid 体系对自家的 Google Play 商铺开放了静默设备权限,也便是说全部从 Google Pgooglelay 上下载的运用都能够不用弹出设备对话框了。这一点充分阐明晰具有权限的重要性,自家的体系想怎么改就怎么改。学习 Google 的做法,许多国内的手机厂商也采用了类似的处理办法,比如说小米手机在小米商铺中下载运用也是不需求弹出设备对话框的,由于小米能够在 MIUI 中对 Android 体系宫颈癌进行各种定制。因而,假定咱们只是做一个一般产品设计专业的运用,其实不太需求考虑程序员那么心爱静默设备这个功用,由于咱们只需求将运用上架到相应的商铺傍边,程序员需要什么学历就会主动具有静默设备的功用。

可是假定咱们想要做的也是一个类似于商铺的途径呢?比如说像 360 手机辅佐,它广泛设备于各种各样的手机上,但都是作为一个一般的运用存在的,而没有 Googleandroid体系 或小米这样的特别权限,那 360 手机辅佐应该怎google样做到更好的设备体会呢?为此 360 手机辅佐供给了两种计划, 秒装(需 ROOT 权限)和智能设备,如下图示:

Android静默装置完成计划,仿360手机帮手秒装和智能装置功用

因而,今日咱们就模仿一下 360 手机辅佐的完毕办法,来给咱们供给一套静默设产品生命周期备的处理计划。

一、秒装

所谓的秒装其实便是需求 ROOT 权限的静默设备,龚俊其实静默设备的原理很app装置下载简略,便是调用 A产品生命周期ndroid 体系的 pm install 指令就能够了,但关键的问题就在于,pm 指令体系是不颁发咱们权限调用的,因而只能在具有 ROOT 权限的手机上去央求权限才行。

下面咱们开始动手,新建一个 Ins宫崎骏tallTest 项目,然后创建一个 SilentInstall 类作为静默设备android什么意思功用的完毕类,代码如下所示:

/**
* 静默设备的完毕类,调用install(approve)办法实施具体的静默设备逻辑。
* 原文地址:http:Android//blog.csdn.net/guolin_blog/article/details/47803149
* @author guolin
* @since 2015/12/7
*/
public clasandroid手机s SiGolentInsta宫颈癌前期症状ll {
/**
* 实施具体的静默android的drawable类设备逻Go辑,需求手机ROOT。
* @param apkPath
*          要设备的apk文程序员客栈件的途程序员一分钟毛遂自荐径
* @return 设备成功回来true,设备失利宫颈癌疫苗回来false。
*/
public boolean install(String apkPath) {
boolean result = false;
DataOutputStream dataOutputStream = null;
BufferedReader errorStream = null;
try {
// 央求su权限
Process process = Runtime.getRuntime().exec("su");
dataOutputStream = new DataOutputStream(process.getOutputStream(工商银行));
// 实施pm instal程序员是做什么的l程序员是做什么的指令
String command = "pm install -r " + apkPath + "n";
dataOutputStream.write(commanapproved.getBytes(Charset.forName("utf-8")));
dataOutputStream.flush();
dataOut产品介绍putStream.writeBytes("exitn");
dataOGoutputStream.flush();
process.waitFor();
erro宫崎骏rStream = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String msg = "";
String line;
// 读取指令的实施效果
wh产品生命周期ile ((line = errorStream.readLine()) != null) {
msg += line;
}
Log.d("TAG", "iandroid什么意思nstall msg is " + msg);
// 假定实施效果中包含Failure字样就以为是设备失利,程序员是做什么的不然就以为设备成功
if (!msg.contains("Failure")) {
result = true;
}
} catch (Exception e) {
Log.e("TAG", e.getMAPPessage(), e);
} figooglenally {
try {
if (dataOutputStream != null) {
dataOutputStream.close();
}
if (errorStream != null) {
errorStream.close();
}
} catch (IO程序员一分钟毛遂自荐Exception e) {
Log.e("TAG", e.getMessage(), e);
}
}
return result;
}
}

能够看到,Si程序员lentInstallappointment 类中只需androidstudio装置教程一个 install() 办法,全部静默设备的逻辑都在这个办法中了,那么咱们具体来看一下这个办法。首要在第 21 行调用了 Runtime.get产品设计Runtime().exec(“su”) 办法,在这儿先央求 ROOT 权限,不然的话后面的操作都将失利。然后在第 24 行开始拼装静默设备指令,指令的格局便是 pm install -r &lt产品设计;apk 途径 >,-r 参数标明假定要设备的 apk 现已存在了就掩盖设备的意思,apk 途径是作为办法参数传入的。接下来的几行便是实施上述指令的进程,留神设备这个进程是同步的,因而咱们在下面调用了 process.waitFor() 办法,即设备要多久,咱们就要在这儿等多久。等候完毕之后阐明设备进程结宫崎骏束了,接下来咱们要去读取设备的效果并进行解appstore析,解析的逻辑也很简略,假定设备效果中包含 Failure 字样就阐明设备失利,反之则阐明设备成功。

整个办法仍是十分简略易懂的,下面咱们就来建立调用这个办法的环境。修改 activi程序员需要什么学历ty_main.xml 中的代码,如下所示:

<?xml version="1.0" encoding="utf-8appstore"?>
<LinearLayout xmlns:android="http://schemas.产品介绍android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"产品批号是生产日期吗
android:layout_height="mat程序员需要什么学历ch_parent"
android:orientation="vertic程序员一分钟毛遂自荐al"
android:paddingBottoappearancem="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_ma工商银行rgin"
tools:context="com.example.installtest.MainActivity"&程序员gt;
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
androi工商银行d:lay程序员计算器out_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onChooseApkFile"
a程序员是学什么专业ndroiapplicationd:text="挑选设备包" />
&appearancelt;TextView
and程序员是学什么专业roid:id="@+id/apkPathText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="cen宫颈癌疫苗ter_vertical"
/>
</LinearLayout>
<View
android:layout_width="match_parenandroidstudio装置教程t"
android:layout_he狗狗币ight="1dp"
andro产品运营id:background="@android:color/darker_gray" />
<Button
android:layout_width="wrap_content"
androi程序员计算器d:layout_height=APP"wrap_content"龚俊
android:onClick="onSilent产品定位Install"
android:text="秒装" />
&android平板电脑价格lt;View
android:layout_width="match_parent"
android:layout_height="1dp"
andrappearoid:background="@android:color/darker_gray" />
<Button
android:layout_程序员装逼代码width="wrap_content宫颈癌"
android:layout_height="wrap_content"
android:onClick="onForwardToAc工商银行c产品运营essibility"
android:text="翻开智能设备服务" />
<Button
android:layout_width=宫颈癌"wrap_cappointmentontent"
android:layout_height="wrap_content"
android:onClick="onSmartInstall"
android:text="智能设备" />
</LinearLayout>

这儿咱们先将程序的主界面确定好,主界面上具有四个按钮,第一个按钮用于挑选 apk 文工商银行件的,第二个按钮用于开始秒装,第三个按钮用于翻开智能设备服务,第四个按钮用于开始智能设备,这儿咱们暂时只能用到前两个按程序员一分钟毛遂自荐钮。那么调用 SilentInstall 的 install() 办法需求传入 apk 路

径,因而咱们需求先把文件挑选器的功用完毕好,新建 activity_file_explorer.xml 和 list_item.xml 作为文件挑选器的布局文件,代码分别如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
androi宫颈癌前期症状d:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list_view"
androi程序员是学什么专业d:appearancelayout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/a工商银行pk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
andrappointmentoid:orientation="程序员薪酬一般多少horizontal">
<ImageView android:id="@+id/img"
android:layout_width="32dp"
android:layout_ma产品介绍rgin="4dp"
android:layo程序员薪酬一般多少ut_gravity="center_vertical"
android:layout_height="32dp"/>
<TextView anandroid下载droid:id=产品司理"@+id/nam产品批号是生产日期吗e"
android:textSize="18sp产品介绍"
android:textStyle="bold"
android:layout_width="match_parent"
android:gravity="center_verticalandroid什么意思"
and程序员roid:layout_height="50dp"/>
</LinearLayout>

然后新建 FileExplorerActivity 作为文件挑选器的 Activity,代程序员是做什么的码如下:

public class FileExplorerActivi宫颈癌ty extends AppCompatActivity implements AdapterView.OnItemClickListener {
ListView listView;
SimpleAdapter adapter;
String rootPath = En产品生命周期vironment.getExternalStorageDirectory().getPath();
String currentPath = rootPath;
Liandroid手机st<Map<String, Object>> list = new ArrayList<>();
@Override
public vo狗狗币id onCreate(Bundle savedInstanceState) {
super.onCrea产品te(savedInstanceState);
setContentView(R.layout.activity_file_explorer);
listView = (ListView) findV枸杞iewById(R.id.list_view);
adapter = new SimpleAdapter(tapproachhis, list, R.layout.程序员计算器list_item,
new产品生命周期 String[]{"name", "img"}, new int[]{R.程序员一分钟毛遂自荐id.name, R.id.img}app装置下载);
listV程序员计算器iew.setAdapter(adapandroid下载ter);
listView.setOnItemC产品战略lickListener(this);
refreshListItems(currandroid是什么手机牌子entPath);
}
private vo公积金id refreshListItems(String paandroid下载t产品生命周期h) {
setTitle(path);
File[] files =产品司理 new File(path).listFiles();
list.clear();
if产品运营 (files != null) {
for (File file : files) {
Map<String, Object> map = new HashMap<>();
if (file.isDirectory(android平板电脑价格)) {
map.put("img", R.drawable.directory);
} else {
map.put("img", R.drawable.fi狗狗币le_doc);
}
map.put("name", file.getName());
map.puapp装置下载t("cur程序员一分钟毛遂自荐rentPath", file.getPath());
list.add(map);
}
}
adapter.notifyDataSetChanged();
}
@OverriAPPde程序员装逼代码
public void onItemClick(AdapterV产品定位iew<?> parent, View v, int position, l产品定位ong iandroid体系d) {
currentPath = (String) list.get(position).get("currentPath");
File file = new File(currentPath);
if (file.程序员isDirectory())
refreshListItems(cAPPurrentPath);
else {
Intent intent = new Intent();
intent.putExtra("apk_path", file.getPath());
setResult(RESULT_OK, intent);
finish();
}
}
@Override
public void o程序员计算器nBackPressed() {
if (rootPath.equals(currentPath)) {
super.onBackPressed();
} else {
File file = new File(currentPath);
currentPath = file.getParandroid平板电脑价格entappreciateFile().g产品质量法etPath();
refreshListItems(currentPath);
}
}
}

这部分代码由于和咱们本篇文件的宗旨没什么联系,首要是为了便利approve demo 展现Android的,因而我就apple不进行阐明晰。

接下来修改 MainActivity 中的代码,如下所示:

/**
* 仿360手机辅佐秒装和智能设备功用的主Activity。
* 原文地址:http://blog.csdn.net/guolin_blog/article/details/47803149
* @author guolin
* @since 2015/12/7
*/
public class MainActivity exte工商银行nds AppCom程序员客栈patActivity {
TextView apkPathText;
String apkPath;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
apkPathTe枸杞xt = (TextView) findView龚俊ById(R.id.apkPathText);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, I工商银行ntent data) {
if (requestCode == 0 &am公积金p;& resultCode == RESULT_OK) {
apkPath = data.getStringExtra("apk_产品设计path");
apkPat宫颈癌疫苗hText.setText(apkPath);
}
}
public void onChooseApkFile(View view) {
Intent intent = new Intent(this, FileExplorerActivity.class);
startActivityForResult(intent, 0);
}
public void onSilentInstall(View view) {
if (!APPisRoot()) {
Toast.AndroidmakeText(this, "没有ROOT权限,不能运用秒装",android什么意思 ToastAndroid.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(apkPath)) {
Toast.makeText(this, "请挑选设备包!", Toast.LENGTH_SHORT).shapplicationow();
return;
}
final Button button = (Button) view;
butandroidstudio装置教程ton.setText("设appearance备中");
new Thread(newandroid开发 Runnable() {
@Override
pu工商银行blic void run() {
SilentappearanceInstall installHelper = new SilentInstall();
final boolean resul产品生命周期t = installHelperandroid的drawable类.install(apkPath);
runOnUiThread(new Runnable() {
@Overridandroidstudio装置教程e
public void run() {
if (result) {
Toast.makeText(MainActivity.this, "设备成功!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "设备失利!", Toast.LENGTH_SHORTandroid是什么手机牌子).show();
}
button.setText("秒装");
}
});
}
}).start();
}
public void onForwardToAccessibility(View view) {
}
public void onSmartInstall(View view) {
}
/**
* 判别手机是否具有Root权限。
* @return 有root权宫崎骏限回来true,不然回来approachfalse。
*/
public boolean isRoot() {
boolean bool = false;
try {
bool = new File("产品批号是生产日期吗/system/bin/su").exists() || new File("appstore/system/appointmentxbin/su").exists程序员装逼代码();
} catappstorech (Exception e) {
e.printStackTrace();android什么意思
}
return bool;
}
}

能够看到,在 Mainandroid开发Activity 中,咱们对四个按钮点击作业的回调办法都进行了定义,当点击挑选设备包appointment按钮时就会调用 onChooseAp产品质量法kFile() 办法,当点击秒装按钮时就会调用 onS产品ilentInstall() 办法。在 onChooseApkFile() 办法办法中,我产品质量法们经过 Intent 翻开了 FileExplorerActivity,然后在 onAct程序员那么心爱ivityResult() 方android是什么手机牌子法傍边读取挑选的 apk 文件途径。在 onSilentInstall() 方产品设计专业法傍边,先判别设备是否 ROOT,假定没有 ROOT 就直接 return,然后判别设备包是否已挑选,假定没有也直接 return。接下来咱们翻开了一个线程APP来调用 SilentInstall.install() 办法,由于设appear备进程会比较耗时,假定不开线程的话主线程就会被卡住,不论设备成功仍是失利,毕竟都会运用 Toast 来进行提示。

代码就这么多,毕竟咱们来配狗狗币备一下 AndroidManifest.xml 文件:

<?xml version="1.0" e枸杞ncoding="utf-8"?>
&ltapplication;man宫颈癌前期症状ifest xmlns:anappearancedroid="http://schemas.android.com/apk/res/android"
package="com.example.installtest">
<uses-permission android:name="a程序员客栈ndroid.permission.READ_EXTERNAL_产品批号是生产日期吗STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmaGop/ic_launcher"
android:label="@string/app_name"
and程序员需要什么学历roid:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".FileExplorerActivity"/>
</application>
<宫颈癌疫苗/manifest>

并没有产品生命周期什么特其他当宫崎骏地,由于挑选 apk 文件需求读取 SD 卡,因而在 AndroidManifest.xml 文件中要记住声明读 SD 卡权限。

其他还有一点需求留神,在 Android 6.0 体系中,读写 SD 卡权限被列为了风险权限,appreciate因而假定将程序的 targetSdkVersion 指定成了 23 则需求做专门的 6.appear0 适配,这儿简略起见,我把 targetSdkV公积金ersion 指定成了 22,由于 6.0 的适配作业也不在文章的阐明规划之内。

现在产品设计专业运转程序,就能够来试一试秒装功用了,切记手机一定要 ROOT,效果如下图所示:

Android静默装置完成计划,仿360手机帮手秒装和智能装置功用

能够看到,这儿咱们挑选的网易新闻设备包已成功设备到手机上了,而且没有弹出approve体系的设备界面,由此证明秒装功用现已成功完毕了。

二、智能设备

那么关于 ROOT 过的手机,秒装功用的确能够防止弹出体系设宫颈癌前期症状备界面,在不影响用户操作的情况下完毕静默设备,可是关于绝大部分没有 ROOT 的手机,这个功用是不可用的。那么咱们应该怎么办呢?为此 360 手机辅佐供给了一种折中计划,便是凭仗 An产品定位droid 供给的无妨碍服务来完毕智能设备。所谓的智能设备其实并不是真实意approach义上的静默设备,因程序员怎么学为它仍是要弹出体系设备界面的,只不过产品介绍能够在设备界面傍边开释用户的操作,由智能设备功用来模仿用户点击,设备完毕之后主动关闭界面。这个功用是需求用户手动翻开的,而且只支撑 Androi程序员是学什么专业d 4.1 之后的手机,如下图所示:

Android静默装置完成计划,仿360手机帮手秒装和智能装置功用

好的,那么接下来咱们就模仿一下 360 手机辅佐,来完毕类似的智能设备功用。

智能设备功用的完毕原理要凭仗 Android 供给的无妨碍服务,关于无妨碍服务的具体阐明可Android参看官方文档:developer.android.com/guide/topic…。

首要在 res/xml 目录下新建一个 accessibility_service_config.xml 文件,代码如下所示:

<accessibility-service xmlns:android="http://s产品设计专业chemas.android.com/apk/res/android"
and产品设计roid:packageNames="applicationcom.andrappreciateoid.packageinstaller"
androapproachid:description="@string/accessibility_service_description"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFlags="flagD产品设计专业efault"
android:accessibilityFeedbackType="feedba宫颈癌ckGeneric"
android:canRetrieveWindowContent="true"
/>

其间,packageNames 指定咱们要监听哪个运用程序员是做什么的程序下的窗口活动,这儿写 com.android.packageinstalleappreciater 标明监听 Android 体系的设备界面。descriptionandroid开发 指定在无妨碍服务傍边闪现给用户看的阐明信息Go,上图中 360 手机辅佐的一大段内容android体系便是在这儿指定的。accessibilityEventTypes 指定咱们在监听窗口中能够模仿哪些作业,这儿写 typeAllMa狗狗币sk 标明全部的作业都能模仿。accessibilityFlags 能够指定无妨碍服务的一些附加参数,这儿咱们传默认值 flagDefaul工商银行t 就行。accessibilityFeedbackType 指定无妨碍服务的反响办法,实际上无妨碍服务这个功用是 Android 供给给一些残疾人士运用的,比如说盲人不便利运用手机,就能够凭仗无产品运营妨碍服务合作语音反响来操作手机,而咱们其实是不需求反响的,因approve此随意传一个值就能够,这儿传入 feedbackGeneric。毕竟 canR程序员etrieveWindowCoappearntent 指定是否答应咱们的程序读取窗口中的节公积金点和内容,有必要写产品质量法 tr龚俊ue。

产品质量法住在 string.xml 文件中写一下 descripti公积金on 中指定的内容,如下所示:

&ltandroid下载装置;resources>
<string name="app_name">InstallTest</string>
<string name="accessibility_service_description">智能设备服务,无需用户的任何操作就能够主动设备程序。</string>
</randroid体系esources>

接下来修改 Andrandroidstudio装置教程oidManifest.xml 文件,在android体系里面装备无妨碍服产品司理务:

&appearlt;?xml version="1.0" encoding="u产品定位tf-8"?>
<manifest xmlns程序员计算器:android="http://schemas.android.com/apk/res/android"
pack产品质量法age="com.approveexample.installtest">
<uses-permission android:name="android.permission.REA程序员D_EXTERNAL_STORAGE" />
<application
android:allo程序员计算器wBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@approvestring/app_name"
aappearancendroid:supportsRtl="true"
android:them产品生命周期e="@style/AppTheme程序员">
......
<service
android:name=".MyAccessapplicationibilityService"
android:label="我的智能设备"
android:permission="android.permissioappstoren.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action androandroid平板电脑价格id:name="android.accessibiliandroidstudio装置教程tyservice.AccessibilityService" />
</intent-filter>
<meta-data
anapp装置下载droid:n产品运营ame="android.accessibilityservice"
android:resource="@xml/accessibility_service_config" />
&l产品质量法t;/seappstorervice>
</applicatapp装置下载ion>
</manifest>

这部分装备的内容多数是程序员一分钟毛遂自荐固定的,有必要要声明一个 android.permission.BIND_ACCandroid平板电脑价格ESSIBILITY_SERVIandroid是什么手机牌子CE 的权限,且有必要要有一个值为 android.accessandroid的drawable类ibilityservice.AccessibilityService 的 action,然后咱们经过 将方才创建的装备文件指定进去程序员那么心爱

接下来便是要去完毕智能设备功用的具体逻辑了,创建一个 MyAccandroid下载装置essibilityService 类并承继自 AccessibilityService,代码如下所示:

/**
* 智能设备功用的程序员一分钟毛遂自荐完毕类。
* 原文地址:http://blog.csdn.net/guolin_android手机blog/article/details/47803149
* @author guolin
* @since 2015/12/7
*/
public class MyAccessibilityService extends AccessibilitySe程序员装逼代码rvice {
Map<Integer, Boolean> handledMap = new HashMandroid手机ap<>();
public MyAccessibilityService() {
}
@Override
public void onAccessibilityEvent(AccessibilityEvandroid开发ent event) {
AccessibilityNodeInfoapplication nodeInfo = event.getSource();
if (nodeInfo != null) {
int eventType = event.getEventType();
if (eventType== Acce龚俊ssibilityEvent.TYPE_WINDOW_CONTENandroid什么意思T_CHANGED ||
eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
if (handledMap.get(event.getappreciateWindowId()) == null) {
boolean handled = iterateNodesAndHandle(nodeInfo);
if (handled) {
handlGoedMap.put(event.getWindowId(), true)产品;
}
}
}
}
}
private boolean iterateNodesAndHandle(Access产品ibilityNodeInf产品质量法o nodeInfo) {宫崎骏
if (nodeInfo != null) {
int childCount = n程序员怎么学odeInfo.getChildCount();
if (程序员"android.widget.Button".equ公积金als(nodeInfo.getClassName())) {
String nodeConte宫颈癌nt = nodeInfo.gappearanceetText().产品司理toString();
Log.d("TAG", "content is " + nodeContent);
if ("设备"程序员客栈.equals(nodeContent)
|| "完毕".equals(nodeContent)
|| "确定".equaapplicationls(nodeContent)) {
nandroid体系odeInfo.performAction(AccessibilityNodeInfo.ACTION_CLICK);
return true;
}
} else if ("android.widget.ScrollView".equals(nodeInfo.getClassName())工商银行) {
nodeInfo.performAction(程序员薪酬一般多少AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
}
for (int i = 0; i < child狗狗币Count; i++) {
AccessibilityNodeInfo childandroid手机NodeInfo = nodeInfo.getChild(i);apple
if (iandroid什么意思terateNodesAndHandandroidstudio装置教程le(childNodeInfo)) {
return true;
}
}
}
return false;
}
@Override
public void onInterrupt() {
}
}

代码并不凌android什么意思乱,咱们来解析一下。每逢窗口有活动时,就会有消息回调到 onAccessibilityEvent() 办法中,因而全部的逻辑都是从这儿开始的。首要咱们能够经过传入的 AccessibilityEvent 参数来获取其时作业的类型,作业的种类十分多,可是咱们只需Android求监听 TYPE_WINDOW_CONTENT_CHANGE程序员计算器D 和 TYPE_WINDOW_STATE_CHANGED 这两种作业就能够了,由于在整个设备进程中,这两个作业必定有一个会被触发。当然也有两个一同都被触发的可能,那么appearance为了防止二次处理的情况,这儿咱们运用了一个 Map 来过滤掉重复作业。

接下来便是调用 iterateNodesAndHan程序员需要什么学历dle()办法来往不断解析其时产品生命周期界面的节点了,这儿咱们经过递归的办法将设备界面中全部的子节点全部进行遍历,当发现按钮节点的时分就进行判别,按钮上的文字是不是 “设备”、“完毕”、“确定” 这几种类型,假定是的话就模仿一下点击作业,这样也就相当于帮用户自程序员装逼代码动操作了这些按钮。其他从 Android 4.4 体系开始,用户需求将运用央求的全部权限看完才能够点击设备,因而假定咱们在节点中发现了 ScrollView,那就模仿一下滑动作业,将界面滑动到最底部,这样设备按钮application就能够点击了。

毕竟,回到 MainActivity 中,来增加对智能设备功用的调用,如下所示:

/**
* 仿3程序员薪酬一般多少60手机辅佐秒装和智能设备功用的主Activity。
* 原文地址:http://blog.csdn.net/guolin_blog/article/detAPPails/47803149
* @author gu程序员是做什么的olin程序员是学什么专业
* @since 2015/12/7
*公积金/
public class MainActivity extends AppCompat程序员计算器Activity {
......
public void onForwardToAccessibility(View view) {
Intent intent = new Intent(Sett程序员一分钟毛遂自荐ings.ACTION_ACCESSIBIL狗狗币ITY_SETTINGS);
startActivity(intent);
}
publi程序员是学什么专业c void onSmartInstall(View view) {
if (TextUtils.isEmpty(apkPath)) {
Toast.makeText(this, "请挑选设备包!", Toast.LENGT产品批号是生产日期吗H_SHORT).show();
return;
}
Uri uri = Uri.fromFile(new File(apkPaappreciateth));
Intent localIntent = new Intent(Intent.ACTION_VIEW);
localIntent.sappearetDataAndType(uri, "application/vnd.android.package-archive"产品设计);
startActivit宫颈癌前期症状y(localIntent);产品
}
}

当点击了打产品司理开智能设备服务按钮时,咱们经过 Intent 跳转到体系的无妨碍服务界面,在这儿发动智能设备服appstore狗狗币。当点击了智能设备按钮时,咱们经过 Intent 跳转到系产品设计统的设产品生命周期备界面,之后全部的设备操作都会主动完毕了。

现在能够从头运转一下程序,效果如下图所示:

Android静默装置完成计划,仿360手机帮手秒装和智能装置功用

能够看到,当翻开网易新闻的设备界面之后,咱们不需求进行任何的手动操作,界面的滑动、设备按钮、完毕按钮的点击都是主动完毕的,毕竟会主动回到手机原来的界面情况,这便是模仿 360 手机辅佐完毕的智能设备功用。

好的,本篇文章的全部内容就到这儿了,尽管不能说完全完毕静approach默设备,可是咱们现已在权限答应的规划内尽可能地去完毕了,而且 360 手机辅佐也只能完毕到这一步androidstudio装置教程罢了,那些被产品司理逼着去完毕静默设备的程序员们也有理由交差了吧?

重视application我的技能公众号“郭霖”,优质技能文章推送。