diff --git a/app/build.gradle b/app/build.gradle
index 005cf3d..06a8859 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -16,11 +16,11 @@ android {
// prod - production, preprod - preproduction, quality - qc
defaultConfig {
- applicationId "in.sminnovations.hpostesting"
+ applicationId "in.sminnovations.hpostesting.preprod"
minSdk 21
targetSdk 34
- versionCode 56
- versionName "2.1.56"
+ versionCode 26
+ versionName "2.1.26"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
@@ -83,7 +83,7 @@ dependencies {
implementation 'androidx.preference:preference-ktx:1.2.1'
implementation 'androidx.preference:preference-ktx:1.2.1'
implementation 'com.google.android.play:core:1.10.3'
-
+ implementation 'io.nats:jnats:2.11.2'
@@ -138,4 +138,6 @@ dependencies {
implementation "androidx.preference:preference-ktx:1.2.1"
implementation 'io.nats:jnats:2.11.2'
+ implementation 'com.google.android.play:core:1.10.3'
+
}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 61c85a5..c5913bd 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,6 +5,8 @@
+
+
@@ -62,7 +64,17 @@
android:exported="false"
android:label="@string/title_activity_dashboard"
android:theme="@style/Theme.HPOS.NoActionBar"
- tools:ignore="MissingClass" />
+ tools:ignore="AppLinkUrlError,MissingClass">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/example/hpostesting/presentation/dashboard/DashboardActivity.kt b/app/src/main/java/com/example/hpostesting/presentation/dashboard/DashboardActivity.kt
index 584138a..88ee490 100644
--- a/app/src/main/java/com/example/hpostesting/presentation/dashboard/DashboardActivity.kt
+++ b/app/src/main/java/com/example/hpostesting/presentation/dashboard/DashboardActivity.kt
@@ -1,10 +1,20 @@
package com.example.hpostesting.presentation.dashboard
+import android.app.DownloadManager
+import android.content.BroadcastReceiver
import android.content.Context
+import android.content.Intent
+import android.content.Intent.ACTION_INSTALL_PACKAGE
+import android.content.IntentFilter
+import android.content.pm.PackageManager
+import android.content.pm.ResolveInfo
+import android.net.Uri
import android.os.Bundle
+import android.util.Log
import android.view.Menu
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
+import androidx.core.content.FileProvider
import androidx.drawerlayout.widget.DrawerLayout
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
@@ -13,22 +23,21 @@ import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.example.hpostesting.data.constant.LanguageManager
import com.google.android.material.navigation.NavigationView
-import com.google.android.play.core.appupdate.AppUpdateManager
-import com.google.android.play.core.appupdate.AppUpdateManagerFactory
+
import com.google.firebase.appdistribution.FirebaseAppDistribution
import com.google.firebase.appdistribution.FirebaseAppDistributionException
import com.google.firebase.crashlytics.FirebaseCrashlytics
import dagger.hilt.android.AndroidEntryPoint
import `in`.sminnovations.hpostesting.R
import `in`.sminnovations.hpostesting.databinding.ActivityDashboardBinding
+import java.io.File
@AndroidEntryPoint
class DashboardActivity : AppCompatActivity() {
private lateinit var appBarConfiguration: AppBarConfiguration
private lateinit var binding: ActivityDashboardBinding
- val appUpdateManager: AppUpdateManager = AppUpdateManagerFactory.create(applicationContext)
- val appUpdateInfoTask = appUpdateManager.appUpdateInfo
+ private var downloadId: Long = 0
override fun attachBaseContext(newBase: Context?) {
val languageCode = LanguageManager.getSavedLanguage(newBase!!)
LanguageManager.setLocale(newBase, languageCode)
@@ -41,7 +50,7 @@ class DashboardActivity : AppCompatActivity() {
binding = ActivityDashboardBinding.inflate(layoutInflater)
setContentView(binding.root)
setSupportActionBar(binding.appBarDashboard.toolbar)
-
+ initiateUpdate()
val drawerLayout: DrawerLayout = binding.drawerLayout
val navView: NavigationView = binding.navView
val navController = findNavController(R.id.nav_host_fragment_content_dashboard)
@@ -67,6 +76,64 @@ class DashboardActivity : AppCompatActivity() {
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
}
+ private fun initiateUpdate() {
+ val apkUrl = "https://www.dropbox.com/scl/fi/v0hux8qrby54rjns8mhum/hpos-testing_preprod_2.1.27.apk?rlkey=ias0fe0zq72avy01rk4cvzmvp&dl=1"
+
+ val request = DownloadManager.Request(Uri.parse(apkUrl))
+ request.setTitle("App Update")
+ request.setDescription("Downloading update...")
+ request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
+ request.setDestinationInExternalFilesDir(this, "Updates", "update.apk")
+
+ val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
+ downloadId = downloadManager.enqueue(request)
+
+ // Register a BroadcastReceiver to receive the download complete event
+ val filter = IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
+ registerReceiver(downloadReceiver, filter)
+ }
+
+ private val downloadReceiver = object : BroadcastReceiver() {
+ override fun onReceive(context: Context?, intent: Intent?) {
+ val id = intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)
+ if (id == downloadId) {
+ // Install the downloaded APK
+ installApk()
+ }
+ }
+ }
+
+ private fun installApk() {
+ val file = File(getExternalFilesDir("Updates"), "update.apk")
+ file.setReadable(true, false) // Ensure the file is readable
+
+ val uri: Uri = FileProvider.getUriForFile(
+ this,
+ "in.sminnovations.hpostesting.preprod.fileprovider",
+ file
+ )
+
+ // Create an intent to install the APK
+ val installIntent = Intent(Intent.ACTION_INSTALL_PACKAGE)
+ installIntent.data = uri
+ installIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
+ Intent.FLAG_ACTIVITY_NEW_TASK or
+ Intent.FLAG_ACTIVITY_CLEAR_TOP
+ installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
+
+ // Start the installation
+ startActivity(installIntent)
+
+ Log.d("InstallApk", "Install Intent URI: $uri")
+ Log.d("InstallApk", "Package Name: $packageName")
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ unregisterReceiver(downloadReceiver)
+ }
+
+
override fun onResume() {
super.onResume()
@@ -106,4 +173,7 @@ class DashboardActivity : AppCompatActivity() {
// Toast.makeText(this, "App Update: Success!", Toast.LENGTH_SHORT).show()
}
}
+
+
+
}
\ No newline at end of file
diff --git a/app/src/main/res/xml/file_paths.xml b/app/src/main/res/xml/file_paths.xml
new file mode 100644
index 0000000..6e9c380
--- /dev/null
+++ b/app/src/main/res/xml/file_paths.xml
@@ -0,0 +1,3 @@
+
+
+