亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

android通過代碼的形式來實現應用程序的方法

 更新時間:2013年10月04日 16:47:33   作者:  
因為應用程序的安裝與卸載模塊在android系統(tǒng)中已經寫好了,所以我們只需要激活就行了

注意:
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");這一句話中,第一個參數是要安裝的apk的路徑,第二個參數是apk所對應的類型。可以砸tomcat的安裝目錄下的conf目錄下的web.xml中找到
程序運行截圖:

 代碼實現如下:
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;
 }
}

相關文章

  • android 線性布局LinearLayout實例代碼

    android 線性布局LinearLayout實例代碼

    android 線性布局LinearLayout實例代碼,需要的朋友可以參考一下
    2013-05-05
  • android獲取屏幕的長與寬實現代碼(手寫)

    android獲取屏幕的長與寬實現代碼(手寫)

    android中獲取屏幕的長于寬,參考了網上有很多代碼,但結果與實際不符,如我的手機是i9000,屏幕大小是480*800px,得到的結果卻為320*533,于此問題很是疑惑,于是自己寫了幾行代碼,親測一下,效果還不錯,需要了解的朋友可以參考下
    2012-12-12
  • Android變形(Transform)之Camera使用介紹

    Android變形(Transform)之Camera使用介紹

    Camera主要實現3D的變形,有轉動,旋轉等,Camera的源碼是由Native(本地代碼)實現,提供的接口也比較簡單,感興趣的朋友可以參考下,或許對你學習有所幫助
    2013-02-02
  • 詳解Android首選項框架的使用實例

    詳解Android首選項框架的使用實例

    首選項這個名詞對于熟悉Android的朋友們一定不會感到陌生,它經常用來設置軟件的運行參數。本篇文章主要介紹詳解Android首選項框架的使用實例,有興趣的可以了解一下。
    2016-11-11
  • Android Handler,Message,MessageQueue,Loper源碼解析詳解

    Android Handler,Message,MessageQueue,Loper源碼解析詳解

    這篇文章主要介紹了Android Handler,Message,MessageQueue,Loper源碼解析詳解,本篇文章通過簡要的案例,講解了該項技術的了解與使用,以下就是詳細內容,需要的朋友可以參考下
    2021-09-09
  • Android實現畫板、寫字板功能(附源碼下載)

    Android實現畫板、寫字板功能(附源碼下載)

    這篇文章主要介紹了Android實現畫板、寫字板功能的方法,文中給出了簡單的介紹和示例代碼,想要了解更多的朋友可以下載源碼進行學習,感興趣的朋友們下面來一起看看吧。
    2017-01-01
  • Flutter 實現虎牙/斗魚 彈幕功能

    Flutter 實現虎牙/斗魚 彈幕功能

    這篇文章主要介紹了Flutter 實現虎牙/斗魚 彈幕功能,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-04-04
  • Kotlin自定義菜單控件

    Kotlin自定義菜單控件

    這篇文章主要為大家詳細介紹了Kotlin自定義菜單控件,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • Android使用系統(tǒng)自帶的相機實現一鍵拍照功能

    Android使用系統(tǒng)自帶的相機實現一鍵拍照功能

    這篇文章主要介紹了Android使用系統(tǒng)自帶的相機實現一鍵拍照功能,非常不錯,具有參考借鑒價值,需要的朋友參考下
    2017-01-01
  • Android接入阿里云熱修復介紹

    Android接入阿里云熱修復介紹

    大家好,本篇文章主要講的是Android接入阿里云熱修復介紹,感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下
    2022-01-01

最新評論