Android使用靜默安裝時碰見的問題,android靜默

來源:互聯網
上載者:User

Android使用靜默安裝時碰見的問題,android靜默

升級時碰見的異常

private void installPackage(String appName,final File apk) {        if (!apk.exists()) {            setHasNewVersion(appName,false);            hideProgressDialog();            return;        }        apk.setReadable(true, false);        apk.setExecutable(true, false);                //走完installPackage之後就結束了,回調observer內的代碼是非同步執行了        final PackageManager pm = getPackageManager();        PackageInstallObserver observer = new PackageInstallObserver(appName);        Log.i(TAG, "install the apk begin : "+appName+";;getAbsolutePath="+apk.getAbsolutePath());        pm.installPackage(                Uri.parse("file://" + apk.getAbsolutePath()), observer,                PackageManager.INSTALL_REPLACE_EXISTING, null);    }
private class PackageInstallObserver extends IPackageInstallObserver.Stub {        private String appname;        public PackageInstallObserver(String appName) {            appname=appName;        }                public void packageInstalled(final String packageName, int returnCode) {            setHasNewVersion(appname,false);            String appPath = getFilesDir().getAbsolutePath()+"/apps/"+appname+".apk";            File apk = new File(getFilesDir(), appname+".apk");                        Log.i(TAG, "install is end and delete "+apk.getAbsoluteFile());            apk.delete();            hideProgressDialog();            if(returnCode==1){                installReturnCode=3;            }else{                if(returnCode<0){                    installReturnCode=returnCode;                }else{                    installReturnCode=-123455;                }            }            Log.i(TAG, "installReturnCode "+installReturnCode+"; packageName = "+packageName);            new Thread(){                public void run() {                    postUpdateResult(packageName,appname,installReturnCode);//安裝成功                };            }.start();        }    }

異常

W/asset ( 1245): Asset path /data/data/com.****.******/files/apps/pjlauncher.apk is neither a directory nor file (type=0).
W/DefContainer( 1245): Failed to parse package
W/ActivityManager( 535): No content provider found for permission revoke: file:///data/data/com.****.***/files/apps/*****.apk
D/dalvikvm( 535): GC_EXPLICIT freed 573K, 24% free 4589K/6028K, paused 2ms+3ms, total 35ms

I/AppUpgradeService( 1227): install is end and delete /data/data/com.****.******/files/apps/*****.apk

 

 

查了好半天有說是要添加許可權的,有說是要在使用時給apk修改許可權的,試了半天都沒有效果。

最後修改了apk檔案的下載存放路徑,結果安裝成功。

* 如果apk下載到這個目錄/data/data/com.****.******/files/apps
* 會出現No content provider found for permission這個異常
* 如果是這個目錄/data/data/com.****.******/files
* 則沒有問題

 

感覺很奇怪我在其他機頂盒上測試的時候,即使是在/data/data/com.****.******/files/apps這個目錄也可以順利安裝apk,但是換了一台機頂盒之後就不可以了

可能是不同機頂盒系統有差異吧!

 

ps:這個功能需要進行系統簽名,以及配置android:sharedUserId="android.uid.system"

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.