APK更新中断应用功能

时间:2017-12-05 13:23:12

标签: android apk adb

我需要通过APK下载来提供应用更新。将已签名的APK下载到设备后,打开它并安装更新后,某些应用功能就会被破坏。

例如,它显示错误的警报。 这里调用了showDefaultAlert而不是showWifiAlert

mNetworkTester = new Runnable() {
    @Override
    public void run() {
        NetworkInfo networkInfo = getActiveNetworkInfo();
        if (networkInfo != null) {
            networkType = networkInfo.getType();
        }
        if (!isNetworkAvailable(networkInfo)) {
            if (!mShowingDefaultAlert) {
                if (networkType == ConnectivityManager.TYPE_WIFI) {
                    showWifiAlert(null, null);
                } else {
                    showDefaultAlert(null, null);
                }
                AppCardServer.reset();
                mShowingDefaultAlert = true;
            }
        } else if (mShowingDefaultAlert) {
            if (internetTest != null && internetTest.getStatus().equals(AsyncTask.Status.PENDING)) {
                internetTest.execute();
            } else {
                internetTest = new InternetTestTask(new OnSocketListener() {
                    @Override
                    public void onConnect(boolean connected) {
                        if (connected) {
                            mShowingDefaultAlert = false;
                            showDialog(null);
                            initConfiguration();
                        }
                    }
                });
            }
        }
        handler.postDelayed(mNetworkTester, INTERVAL);
    }
};
handler.post(mNetworkTester);

如果我使用adb install -r安装相同的APK,或者从Android Studio运行它,一切正常。为什么会发生这种情况以及如何解决?

这是我的AndroidManifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.appcard.androidterminal">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.GET_TASKS"/>
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

    <application
        android:name=".AppContext"
        android:allowBackup="false"
        android:icon="@drawable/logo_small"
        android:label="@string/app_name"
        android:supportsRtl="false"
        android:theme="@style/AppTheme"
        tools:ignore="GoogleAppIndexingWarning">

        <activity
            android:name=".ui.MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service android:name=".KioskService" android:exported="false"/>

        <service
            android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService"
            android:enabled="true" />

        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/paths"/>
        </provider>

        <receiver android:name=".BootReceiver">
            <intent-filter >
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>

        <receiver
            android:name=".content.UpdateAlarmReceiver"
            android:exported="false" >
        </receiver>

    </application>

</manifest>

1 个答案:

答案 0 :(得分:0)

我正在推出像这样下载的apk的安装

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

该应用程序仍处于后台,在安装新的apk并打开应用程序后,某些活动流程失败。这解决了我的问题:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();