Java 使用apk安装代码更新应用程序时出现奇怪问题
应用程序已成功更新,但根据不同的代码使用情况出现以下问题Java 使用apk安装代码更新应用程序时出现奇怪问题,java,android,android-install-apk,Java,Android,Android Install Apk,应用程序已成功更新,但根据不同的代码使用情况出现以下问题 apk安装后,未显示应用程序安装程序的“应用程序安装成功”屏幕 如果我使用debug apks测试上述情况,对于一个特定的代码,就像总是安装成功一样,“应用程序安装成功”屏幕出现,单击打开按钮成功打开应用程序。但是,如果我使用已签名的APK来测试相同的代码,单击“安装成功”中的“打开”按钮将无法打开应用程序。如果从启动器打开,应用程序可以正常打开 我尝试了许多stackoverflow问题和博客中的不同代码。我甚至在这里尝试了一个谷歌示例
private static Uri uriFromFile(Context context, File file) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileprovider", file);
} else {
return Uri.fromFile(file);
}
}
案例1:
(“应用程序安装程序的应用程序安装成功”屏幕未显示)
案例2:
(对于发布APK,单击“应用程序安装成功”屏幕中的“打开”不会打开应用程序。但是对于调试APK,应用程序可以正常打开)
但应用程序并没有打开
在本例中,应用程序类和spashActivity onCreate()屏幕中的日志不会出现
public void installNewFile() {
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
.
.
startActivityForResult(intent, 999);
}
public void installNewFile() {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uriFromFile(context, new File(path)), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
intent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME,
context.getApplicationInfo().packageName);
try {
startActivity(intent);
finish();
}catch (ActivityNotFoundException e){
Toast.makeText(context, "Application installer not found!", Toast.LENGTH_SHORT).show();
Log.e(TAG, "installNewFile: ", e);
}
}
Manifest:
<application
android:name=".MposApp"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
<provider
android:authorities="com.example.appname.fileprovider"
android:name=".autoupdateutil.ApkProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
<activity
android:name=".activity.base.SplashActivity"
android:configChanges="orientation|screenSize"
android:resizeableActivity="false"
android:exported="true"
tools:targetApi="n">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="ANDROID.INTENT.CATEGORY.DEFAULT" />
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/usb_device_filter" />
<meta-data
android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="@xml/usb_device_filter" />
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
</intent-filter>
</activity>
.
.
.
.
"I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.example.appname cmp=com.example.appname/.activity.base.SplashActivity} from uid 10021 pid 31899"