Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. httpModule.getFile( url, destFilePath ).then(
  2. function( result: fileModule.File )
  3. {
  4.  
  5. let destFile = fileModule.File.fromPath( result.path );
  6.  
  7. let file = new java.io.File(destFile.path);
  8.  
  9.  
  10. let context = application.android.context;
  11.  
  12. let shareableFileUri;
  13. let sdkVersionInt = parseInt(platformModule.device.sdkVersion);
  14.  
  15. let intent;
  16.  
  17. if (sdkVersionInt >= 24) // Nougat 7.0
  18. {
  19. shareableFileUri = android.support.v4.content.FileProvider.getUriForFile(context, application.android.nativeApp.getPackageName() + ".provider", file);
  20.  
  21. intent = new android.content.Intent( android.content.Intent.ACTION_INSTALL_PACKAGE );
  22.  
  23. intent.setDataAndType( shareableFileUri, "application/vnd.android.package-archive" );
  24.  
  25. intent.setFlags( android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION|android.content.Intent.FLAG_ACTIVITY_NEW_TASK );
  26. }
  27. else
  28. {
  29. // not testing this version
  30. }
  31.  
  32. application.android.foregroundActivity.startActivity( intent );
  33.  
  34. } ).catch( (reason) =>
  35. {
  36. console.error( "_downloadAndInstallApkFile " + reason );
  37. } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement