1

パッケージ インストーラーで apk をインストールしようとしているときに問題に直面しています。非常にあいまいなステータス メッセージ「INSTALL_FAILED_INTERNAL_ERROR: セッションが放棄されました」でインストールが失敗します。

パッケージをインストールするコードは次のとおりです。

public static void installPackage(Context context, String packageName, String apkPath)
{
    Logger.debug("Installing package " + apkPath);
    PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller();

    PackageInstaller.SessionParams params = new PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL);
    params.setAppPackageName(packageName);

    try {
        Logger.debug("Creating session");
        int sessionId = packageInstaller.createSession(params);
        PackageInstaller.Session session = packageInstaller.openSession(sessionId);

        Logger.debug("Copying buffer");
        OutputStream out = session.openWrite(packageName, 0, -1);
        FileInputStream fileInputStream = new FileInputStream(new File(apkPath));

        byte[] buffer = new byte[1024];
        int len = fileInputStream.read(buffer);
        while(len != -1)
        {
            out.write(buffer,0, len);
            len = fileInputStream.read(buffer);
        }

        session.fsync(out);
        fileInputStream.close();
        out.close();

        Logger.debug("Buffer copied, sending intent");

        Intent intent = new Intent(INSTALL_COMPLETE_ACTION);
        IntentSender intentSender = PendingIntent.getBroadcast(context, sessionId,
                intent, 0) .getIntentSender();
        session.commit(intentSender);
        session.close();
    }
    catch(IOException e)
    {
        Logger.error("IOException while installing package");
        Logger.error(e);
    }
    catch(Exception e)
    {
        Logger.error("Unknown exception while installing package");
        Logger.error(e);
    }
}

インテントを処理するブロードキャスト レシーバは次のとおりです。

private BroadcastReceiver mInstallReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {

        Logger.debug("Received intent");
        Logger.debug("Intent action: " + intent.getAction());
        int status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE);
        Logger.debug("Intent status: " + status);
        String message = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE);
        Logger.debug("Status message: " + message);

        if(status == PackageInstaller.STATUS_PENDING_USER_ACTION)
        {
            Intent innerIntent = (Intent) intent.getParcelableExtra(Intent.EXTRA_INTENT);
            startActivity(innerIntent);
        }
    }
};

そして、ブロードキャストレシーバーによって生成されたログは次のとおりです。

11-12 15:22:08.364  7179  7179 D DummyActivity @ onReceive()        Received intent
11-12 15:22:08.365  7179  7179 D DummyActivity @ onReceive()        Intent action: net.test.INSTALL_COMPLETE
11-12 15:22:08.365  7179  7179 D DummyActivity @ onReceive()        Intent status: -1
11-12 15:22:08.365  7179  7179 D DummyActivity @ onReceive()        Status message: null
11-12 15:22:08.378  7179  7179 D DummyActivity @ onReceive()        Received intent
11-12 15:22:08.378  7179  7179 D DummyActivity @ onReceive()        Intent action: net.test.INSTALL_COMPLETE
11-12 15:22:08.379  7179  7179 D DummyActivity @ onReceive()        Intent status: -1
11-12 15:22:08.379  7179  7179 D DummyActivity @ onReceive()        Status message: null
11-12 15:22:08.387  7179  7179 D DummyActivity @ onReceive()        Received intent
11-12 15:22:08.387  7179  7179 D DummyActivity @ onReceive()        Intent action: net.test.INSTALL_COMPLETE
11-12 15:22:08.387  7179  7179 D DummyActivity @ onReceive()        Intent status: -1
11-12 15:22:08.388  7179  7179 D DummyActivity @ onReceive()        Status message: null
11-12 15:22:09.155  7179  7179 D DummyActivity @ onReceive()        Intent action: net.test.INSTALL_COMPLETE
11-12 15:22:09.155  7179  7179 D DummyActivity @ onReceive()        Intent status: 1
11-12 15:22:09.155  7179  7179 D DummyActivity @ onReceive()        Status message: INSTALL_FAILED_INTERNAL_ERROR: Session relinquished
11-12 15:22:09.155  7179  7179 D DummyActivity @ onReceive()        Received intent
11-12 15:22:09.155  7179  7179 D DummyActivity @ onReceive()        Intent action: net.test.INSTALL_COMPLETE
11-12 15:22:09.156  7179  7179 D DummyActivity @ onReceive()        Intent status: 1
11-12 15:22:09.156  7179  7179 D DummyActivity @ onReceive()        Status message: INSTALL_FAILED_INTERNAL_ERROR: Session relinquished
11-12 15:22:09.156  7179  7179 D DummyActivity @ onReceive()        Received intent
11-12 15:22:09.157  7179  7179 D DummyActivity @ onReceive()        Intent action: net.test.INSTALL_COMPLETE
11-12 15:22:09.157  7179  7179 D DummyActivity @ onReceive()        Intent status: 1
11-12 15:22:09.157  7179  7179 D DummyActivity @ onReceive()        Status message: INSTALL_FAILED_INTERNAL_ERROR: Session relinquished
11-12 15:22:09.214  7179  7179 D DummyActivity @ onReceive()        Received intent
11-12 15:22:09.214  7179  7179 D DummyActivity @ onReceive()        Intent action: net.test.INSTALL_COMPLETE
11-12 15:22:09.215  7179  7179 D DummyActivity @ onReceive()        Intent status: 4
11-12 15:22:09.215  7179  7179 D DummyActivity @ onReceive()        Status message: INSTALL_PARSE_FAILED_NOT_APK: Failed parse during installPackageLI: Failed to parse /data/app/vmdl1253852664.tmp
11-12 15:22:09.215  7179  7179 D DummyActivity @ onReceive()        Received intent
11-12 15:22:09.215  7179  7179 D DummyActivity @ onReceive()        Intent action: net.test.INSTALL_COMPLETE
11-12 15:22:09.215  7179  7179 D DummyActivity @ onReceive()        Intent status: 4
11-12 15:22:09.216  7179  7179 D DummyActivity @ onReceive()        Status message: INSTALL_PARSE_FAILED_NOT_APK: Failed parse during installPackageLI: Failed to parse /data/app/vmdl1253852664.tmp
11-12 15:22:09.216  7179  7179 D DummyActivity @ onReceive()        Received intent
11-12 15:22:09.216  7179  7179 D DummyActivity @ onReceive()        Intent action: net.test.INSTALL_COMPLETE
11-12 15:22:09.216  7179  7179 D DummyActivity @ onReceive()        Intent status: 4
11-12 15:22:09.216  7179  7179 D DummyActivity @ onReceive()        Status message: INSTALL_PARSE_FAILED_NOT_APK: Failed parse during installPackageLI: Failed to parse /data/app/vmdl1253852664.tmp

前もって感謝します。

4

0 に答える 0