android通過代碼的形式來實(shí)現(xiàn)應(yīng)用程序的方法
注意:
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");這一句話中,第一個(gè)參數(shù)是要安裝的apk的路徑,第二個(gè)參數(shù)是apk所對應(yīng)的類型。可以砸tomcat的安裝目錄下的conf目錄下的web.xml中找到
程序運(yùn)行截圖:
代碼實(shí)現(xiàn)如下:
1、main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="安裝"
android:onClick="install"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="卸載"
android:onClick="uninstall"
/>
</LinearLayout>
2、MainActivity
package com.njupt.install;
import java.io.File;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void install(View v){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
File file = new File(Environment.getExternalStorageDirectory(),"HtmlUI1.apk");
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);
}
public void uninstall(View v){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:com.njupt.htmlui1"));
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
相關(guān)文章
android 線性布局LinearLayout實(shí)例代碼
android 線性布局LinearLayout實(shí)例代碼,需要的朋友可以參考一下2013-05-05android獲取屏幕的長與寬實(shí)現(xiàn)代碼(手寫)
android中獲取屏幕的長于寬,參考了網(wǎng)上有很多代碼,但結(jié)果與實(shí)際不符,如我的手機(jī)是i9000,屏幕大小是480*800px,得到的結(jié)果卻為320*533,于此問題很是疑惑,于是自己寫了幾行代碼,親測一下,效果還不錯(cuò),需要了解的朋友可以參考下2012-12-12Android變形(Transform)之Camera使用介紹
Camera主要實(shí)現(xiàn)3D的變形,有轉(zhuǎn)動,旋轉(zhuǎn)等,Camera的源碼是由Native(本地代碼)實(shí)現(xiàn),提供的接口也比較簡單,感興趣的朋友可以參考下,或許對你學(xué)習(xí)有所幫助2013-02-02詳解Android首選項(xiàng)框架的使用實(shí)例
首選項(xiàng)這個(gè)名詞對于熟悉Android的朋友們一定不會感到陌生,它經(jīng)常用來設(shè)置軟件的運(yùn)行參數(shù)。本篇文章主要介紹詳解Android首選項(xiàng)框架的使用實(shí)例,有興趣的可以了解一下。2016-11-11Android Handler,Message,MessageQueue,Loper源碼解析詳解
這篇文章主要介紹了Android Handler,Message,MessageQueue,Loper源碼解析詳解,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-09-09Android實(shí)現(xiàn)畫板、寫字板功能(附源碼下載)
這篇文章主要介紹了Android實(shí)現(xiàn)畫板、寫字板功能的方法,文中給出了簡單的介紹和示例代碼,想要了解更多的朋友可以下載源碼進(jìn)行學(xué)習(xí),感興趣的朋友們下面來一起看看吧。2017-01-01Flutter 實(shí)現(xiàn)虎牙/斗魚 彈幕功能
這篇文章主要介紹了Flutter 實(shí)現(xiàn)虎牙/斗魚 彈幕功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04Android使用系統(tǒng)自帶的相機(jī)實(shí)現(xiàn)一鍵拍照功能
這篇文章主要介紹了Android使用系統(tǒng)自帶的相機(jī)實(shí)現(xiàn)一鍵拍照功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下2017-01-01