溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

Android安裝卸載程序的具體操作方法

發(fā)布時(shí)間:2021-11-11 15:57:19 來(lái)源:億速云 閱讀:198 作者:柒染 欄目:移動(dòng)開(kāi)發(fā)

Android安裝卸載程序的具體操作方法,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。

對(duì)于編程愛(ài)好者們來(lái)說(shuō),Android手機(jī)操作系統(tǒng)是一款非常實(shí)用的系統(tǒng)。他們可以進(jìn)行各種Android應(yīng)用程序的開(kāi)發(fā)來(lái)滿(mǎn)足自的應(yīng)用需求。在這里我們就先來(lái)為大家講解一下有關(guān)Android安裝卸載程序的具體操作步驟。

在Android安裝卸載程序的源碼中我們知道:

< 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>

因?yàn)楦鶕?jù)里面的權(quán)限我們可以 安裝一個(gè)程序從sd卡:

  1. String fileName = Environment.getExternalStorageDirectory() 
    + "/myApp.apk";   

  2. Intent intent = new Intent(Intent.ACTION_VIEW);   

  3. intent.setDataAndType(Uri.fromFile(new File(fileName)), 
    "application/vnd.android.package-archive");   

  4. startActivity(intent);  

Android安裝卸載程序的操作中要想卸載一個(gè)程序;

  1. Uri packageURI = Uri.parse("package:com.android.myapp");   

  2. Intent uninstallIntent = new Intent
    (Intent.ACTION_DELETE, packageURI);   

  3. startActivity(uninstallIntent);  

默認(rèn)是不支持安裝非市場(chǎng)程序的 因此判斷一下

  1. int result = Settings.Secure.getInt(getContentResolver(),
     Settings.Secure.INSTALL_NON_MARKET_APPS, 0);   

  2. if (result == 0) {   

  3. // show some dialog here   

  4. // ...   

  5. // and may be show application settings dialog manually   

  6. Intent intent = new Intent();   

  7. intent.setAction(Settings.ACTION_APPLICATION_SETTINGS);   

  8. startActivity(intent);   

看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝您對(duì)億速云的支持。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI