Android 7.0 & 9.0 records of problems encountered during the automatic update of the APP

First, the first question:

After Android 7.0, an error is reported when opening the file:

Secondly, the second question, on android 9.0, when the intent is opened, it will flash, but it cannot be opened, only need to add permissions

	 <!--适应android 9.0 调用安装app-->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

Finally, the parsing package error encountered by android in 9.0, please see the code:

 未修改之前代码:
 	
  public static void installUPTSMServiceApk(final Activity activity) {

                File downNewAppFile = new File(Environment.getExternalStorageDirectory().getPath() + "/GDDownload", "UPTSMSeraviceApk.apk");
       			 Intent intent = new Intent(Intent.ACTION_VIEW);

                if (Build.VERSION.SDK_INT >= 24) {
                    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    Uri contentUri = FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".fileProvider", downNewAppFile);
                    intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
                } else {
                    intent.setDataAndType(Uri.fromFile(downNewAppFile), "application/vnd.android.package-archive");

                }
        		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                activity.startActivity(intent);
            }
修改之后代码:
	
    public static void installUPTSMServiceApk(final Activity activity) {
        // 启用安装新线程
                File downNewAppFile = new File(Environment.getExternalStorageDirectory().getPath() + "/GDDownload", "UPTSMSeraviceApk.apk");
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                if (Build.VERSION.SDK_INT >= 24) {
                    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    Uri contentUri = FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".fileProvider", downNewAppFile);
                    intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
                } else {
                    intent.setDataAndType(Uri.fromFile(downNewAppFile), "application/vnd.android.package-archive");

                }
                
                activity.startActivity(intent);
            }

If you look at the code carefully, you will see some clues. It doesn’t matter if you don’t have time to read it. In fact, the most important thing is to put

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

placed,

   intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

In front of , the specific reasons will not be described in detail, and interested students can refer to it by themselves.

Guess you like

Origin blog.csdn.net/a_Chaon/article/details/90373287