20_Android中apk安装器,通过WebView来load进一个页面,Android通知,程序退出自动杀死进程,通过输入包名的方式杀死进程
场景:实现安装一个apk应用程序的过程。界面如下:
编写如下应用,应用结构如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <EditText android:hint="请输入安装apk文件的路径" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/et_path"/> <Button android:onClick="click" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="安装"/> </RelativeLayout> |
MainActivity的内容如下:
package com.itheima.apkinstaller; import java.io.File; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.EditText; public class MainActivity extends Activity { private EditText et_path; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et_path = (EditText) findViewById(R.id.et_path); } public void click(View view) { String path = et_path.getText().toString().trim(); // <intent-filter> // <action android:name="android.intent.action.VIEW" /> // <category android:name="android.intent.category.DEFAULT" /> // <data android:scheme="content" /> // <data android:scheme="file" /> // <data android:mimeType="application/vnd.android.package-archive" /> // </intent-filter> Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); intent.setDataAndType(Uri.fromFile(new File(path)), "application/vnd.android.package-archive"); startActivity(intent); } } |
Android清单文件内容如下:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.itheima.apkinstaller" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.itheima.apkinstaller.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> |
1 场景:通过WebView加载一个页面,程序运行后的界面如下(注意:下面的页面是通过WebView通过load的方式加载进去的):
程序案例结构如下:
2 编写activity_main.xml布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <!-- 嵌入的浏览器 --> <WebView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/wv"/> </RelativeLayout> |
3 Android的清单文件:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.itheima.htmlui" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> <uses-permission android:name="android.permission.INTERNET"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.itheima.htmlui.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> |
1 Android通知,界面效果:
点击”点击显示通知”,发现上方出现了一个红色小人的通知
点击”新版点击显示通知”,将通知滑动显示查看,效果如下:
程序案例结构如下:
2 编写布局文件:activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <Button android:onClick="click" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="点击显示通知" /> <Button android:onClick="click2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="新版点击显示通知" /> </RelativeLayout> |
3 编写MainActivity,代码如下:
package com.itheima.notification; import android.annotation.SuppressLint; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.View; public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void click(View view){ NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new "我是一个通知", System.currentTimeMillis()); notification.flags = Notification.FLAG_AUTO_CANCEL; Intent intent = new Intent(); intent.setAction(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:10086")); //延期的意图 PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0); //设置点击事件的类型 notification. nm.notify(0, notification); } /** * 新版本的notification * @param view */ @SuppressLint("NewApi") public void click2(View view){ Notification noti = new Notification.Builder(this) .setContentTitle("我是标题") //这些都是Android版本11版本开始的 .setContentText("我是内容") .setSmallIcon(R.drawable.notification) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)) .build(); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); nm.notify(0, noti); } } |
Android清单文件:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.itheima.notification" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> <uses-permission android:name="android.permission.CALL_PHONE"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.itheima.notification.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> |
=============================================================================
1 自杀代码:杀死进程的代码如下:
package com.itheima.exit; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.os.Bundle; public class MainActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public void onBackPressed() { AlertDialog.Builder builder = new Builder(this); builder.setTitle("提醒"); builder.setMessage("确定退出当前应用程序吗?"); builder.setPositiveButton("立刻退出", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish();//关闭当前的activity //把自己的进程杀死 //自杀的方法 android.os.Process.killProcess(android.os.Process.myPid()); } }); builder.setNegativeButton("取消", null); builder.show(); } } |
程序退出先的效果(在Devices中的效果):
退出后:
1 杀死进程,场景:杀死空进程,后台进程,他杀(也就是说杀不死自己),界面效果:
程序案例代码结构如下:
2 编写activity_main.xml布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <EditText android:hint="请输入要杀死的进程包名" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/et_packname"/> <Button android:onClick="click" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="杀死进程"/> </RelativeLayout> |
3 MainActivity的代码如下:
package com.itheima.killother; import android.app.Activity; import android.app.ActivityManager; import android.os.Bundle; import android.view.View; import android.widget.EditText; public class MainActivity extends Activity { private ActivityManager am;//相当于进程管理器 private EditText et_packname; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //所有程序的开启都是由Activity的ActivityManager来管理的 am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); et_packname = (EditText) findViewById(R.id.et_packname); } public void click(View view) { String packname = et_packname.getText().toString().trim(); //注意要杀死别的进程需要加上权限 //<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/> //这里中方式只是杀死别人,注意:手机里面有些进程是杀死不掉的,比如电话进程 am.killBackgroundProcesses(packname); } } |
程序运行结果:
注意:如果有时候提示要重启adb,可以通过下面的方式:
下面以杀死上面的com.android.music为例:
点击”杀死进程”前:
点击”杀死进程”之后的效果:
20_Android中apk安装器,通过WebView来load进一个页面,Android通知,程序退出自动杀死进程,通过输入包名的方式杀死进程相关推荐
- Android软件安装工具-APK安装器
Android软件安装工具-APK安装器 2008-11-16 作者:android手机网 网友抱怨购买了T-Mobile G1手机后无法离线安装APK文件,除了从Android Market上下载外 ...
- android apk安装工具,APK安装器下载-APK安装器手机版下载v2.9-1 安卓版-西西软件下载...
APK安装器取代手机当中自带的APK安装器,让安装的界面在整体上面变得更加的好看,对于颜值有着极高要求的用户而言,虽然安装界面我们不一定能够经常的进行看到,但是界面的丑美也非常影响感官体验,感兴趣的话 ...
- android 安装器,APK安装器
详情 APK安装器是一款最新推出的功能非常强大的安卓软件安装器.APK安装器颠覆了以往的安卓手机常规的安装方式和规则.操作非常简单,功能十分多样化,而且不会显示在你的手机桌面上占用你的手机桌面影响美观 ...
- 从源码角度解析Android中APK安装过程
从源码角度解析Android中APK的安装过程 1. Android中APK简介 Android应用Apk的安装有如下四种方式: 1.1 系统应用安装 没有安装界面,在开机时自动完成 1.2 网络下载 ...
- Android中APK安装流程解析
前言:大家都知道,手机关机以后,就是一个冰冷的砖头,只能用来做防身的利器,但是开机后,点击桌面上的任何一个图片,都能开启一个APP,这说明在开机过程中,系统把已经安装好的APP加载到内存中,这到底是怎 ...
- 安卓网apk安装器_短视频无水印下载,apk提取,带壳截图 iOS Android极客必备的三款软件,你全都用上了吗?...
短视频无水印下载,apk提取,带壳截图 iOS Android 极客必备的三款软件,你全都用上了吗? 7SIZE丨插图内容来自于网络侵权删 给大家介绍 Android,iOS 上三款在生活中必备的三款 ...
- 安卓网apk安装器_安卓APP推荐:假日时间规划师,定时音乐播放器,最小的APK提取器...
今天小趣同学给大家推荐3款非常精美实用的安卓APP,都是小编精心挑选出来的应用,喜欢的同学可以试试: Sectograph-假日里的时间规划师 Sectograph 是一款非常精美实用的时间规划应用, ...
- 【转】Android中APK安装过程及原理解析
应用安装是智能机的主要特点,即用户可以把各种应用(如游戏等)安装到手机上,并可以对其进行卸载等管理操作.APK是Android Package的缩写,即Android安装包.APK是类似Symbian ...
- 体积最小,极速秒装的APK安装器
经常安装APK ? 每次都要打开占用资源,广告满天飞的手机助手? 每次都要等待设备连接? 每次都要等待手机端助手启动? 每次都要狂按退出,结束手机端残余进程? 有了这个东东,上面这些问题都不存在了. ...
最新文章
- 海思 HI35* rtsp服务器
- python输入两个整数按先大后小的顺序输出_指针变量:输入a和b两个整数,按先大后小的顺序输出a和b。...
- Java设计模式(四):工厂设计模式
- Java并发编程——线程池初步
- ios html5 不支持 flv_iExplorer v4.2.6 一款优秀强大的 iOS 资源管理工具
- 【C语言】(数组)C语言字符串中的小写字母转换为大写字母
- 机器视觉:锡膏印刷质量3D检测光学系统
- grubbs准则 matlab_MATLAB-格拉布斯准则(MATLAB-Grubbs criterion)-M
- 对象可以创建数组吗_淘宝联盟平台可以创建淘礼金吗?相关问题解答
- 餐饮行业为什么要开发点餐app?
- mysql 性能优化,减轻数据库的压力。(减少数据库查询的次数)
- 闲扯Maven项目代码组织形式
- c mysql创建索引,如何创建mysql索引
- html 字体模糊,css – Chrome字体显示模糊
- java中fractions,[CF743C]Vladik and fractions
- 有关“夜壶冲”的由来
- Blender 裙子和大腿穿模的问题
- RPG游戏经典的系统架构
- 亚马逊cpc广告关键词设置技巧有哪些?
- macOS Mojave 10.14.4 (18E226) 最新苹果系统镜像下载+在线升级方法
热门文章
- python 排序算法
- boost::phoenix::if_else相关的测试程序
- boost::graph模块BC聚类算法程序的实现
- 基于 flyweight 的格式化文本处理的 Boost.Flyweight 示例
- Boost::context模块fiber的throw测试程序
- Boost:基于不同容器的有界缓冲区比较
- ITK:遮盖一张图像给定标签图
- ITK:从图像区域中随机选择像素
- DCMTK:验证服务类用户(C-ECHO操作)
- VTK:图片之ImageCorrelation