地址汇总配置实例
2015-05-06 10:54
225 查看
Install and Uninstall Android applications with PackageInstaller
This is actually very simple.
See PackageInstaller code here:http://android.git.kernel.org/?p=platform/packages/apps/PackageInstaller.git;a=tree;h=refs/heads/donut;hb=refs/heads/donut
Intent filters for such actions are:
<activity android:name=".PackageInstallerActivity">
<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>
</activity>
<activity android:name=".UninstallerActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DELETE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
</activity>
so if you want to install your .apk file from SD card – just write something like that:
String fileName = Environment.getExternalStorageDirectory() + "/myApp.apk";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent);
for uninstallation:
Uri packageURI = Uri.parse("package:com.android.myapp");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);
be aware that by default INSTALL_NON_MARKET_APPS option is disabled. You may want to check this option and show user friendly dialog before trying to install the app:
int result = Settings.Secure.getInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, 0);
if (result == 0) {
// show some dialog here
// ...
// and may be show application settings dialog manually
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_SETTINGS);
startActivity(intent);
}
enjoy
This is actually very simple.
See PackageInstaller code here:http://android.git.kernel.org/?p=platform/packages/apps/PackageInstaller.git;a=tree;h=refs/heads/donut;hb=refs/heads/donut
Intent filters for such actions are:
<activity android:name=".PackageInstallerActivity">
<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>
</activity>
<activity android:name=".UninstallerActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DELETE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
</activity>
so if you want to install your .apk file from SD card – just write something like that:
String fileName = Environment.getExternalStorageDirectory() + "/myApp.apk";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent);
for uninstallation:
Uri packageURI = Uri.parse("package:com.android.myapp");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);
be aware that by default INSTALL_NON_MARKET_APPS option is disabled. You may want to check this option and show user friendly dialog before trying to install the app:
int result = Settings.Secure.getInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, 0);
if (result == 0) {
// show some dialog here
// ...
// and may be show application settings dialog manually
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_SETTINGS);
startActivity(intent);
}
enjoy
相关文章推荐
- 地址汇总配置实例(路由)
- 2010_8_17_静态路由_静态路由配置(不连续地址汇总)
- 网络地址转换原理及其配置实例
- OSPF的高级应用之地址汇总与虚链路的配置
- 实例演示:GRUB安装、配置及使用汇总
- iptables的SNAT和DNAT地址转换配置实例
- Grub相关安装配置及使用实例汇总讲析
- 思科路由器NAT地址映射配置实例
- 笔记 OSPF地址汇总 、 虚链路配置 、 IPV6的原理与配置
- 配置H3C交换机实例(设置安全策略版,通过源IP地址对WEB登录用户进行控制)[连载之电子商务系统架构]
- Grub安装、配置以及使用实例汇总讲解
- OSPF路由汇总的配置实例实验
- OSPF地址汇总配置
- 地址汇总、nssa区域配置、虚链路的设置
- 网络地址转换(NAT)配置实例
- 用配置文件设置服务端数据库连接和端口号,服务端的URL地址
- slf4j配置实例
- 具体实例汇总android
- android跳转系统配置界面汇总
- [置顶] 搞IT,算法编程不错的学习网址 & 一些专栏博客大神的地址(汇总)