如何調用系統的包安裝自己的apk呢?

來源:互聯網
上載者:User

其實看著覺著好像不知道如何?其實就是調用系統的intent來完成安裝

案例驅動:
123456789101112131415161718192021222324 public void onSuccess(File t) {     // 下載成功的條件下,替換應用程式     // TODO 這裡的東西不是很理解     // 下載成功 替換安裝 應用程式.     // <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 intent = new Intent();     intent.setAction("android.intent.action.VIEW");     intent.addCategory("android.intent.category.DEFAULT");     intent.setDataAndType(Uri.fromFile(t),            "application/vnd.android.package-archive");     Log.i(TAG, "成功進行下載");     startActivity(intent);     super.onSuccess(t); }

這段代碼是在斷點下載功能中實現的,也就是在成功下載了應用的情況下,安裝更新檔案主要是需要掌握如何去調用這個Intent也就是如何setAction和addCategory和setDataAndType。而這些東西可以查看原始碼擷取到。那麼這裡就有一個很關鍵的問題了,怎麼通過原始碼找到需要的intent設定資訊呢?

通過尋找原始碼中的apps中,發現有一個packageInstaller,看名字便知道這是一個安裝應用的系統應用,那麼如何調用它呢?直接查看他的資訊清單檔可以看到如下資訊:

案例驅動:
1234567891011 <activity android:name=".PackageInstallerActivity"                 android:configChanges="orientation|keyboardHidden"                 android:theme="@style/TallTitleBarTheme">             <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>

那麼就可以知道具體的調用方法了,將相應的參數設定就可以安裝自己的應用了。

歡迎大家留言,這個是我曾經的一些筆記,現在想在網上記錄下來,曾經的點點滴滴,當然肯定會有一些紕漏,還望指出

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.