Launching default android launcher programmatically

前端 未结 3 1051
温柔的废话
温柔的废话 2020-12-25 15:14

I\'m looking for a way to launch the default android launcher programatically, something perhaps like the code below. Or do I have to add something to the manifest file? Tha

3条回答
  •  眼角桃花
    2020-12-25 15:49

    => In kotlin add below code in onDestroy method of appCompactActvity use to make your app as default launcher, 
    
    override fun onDestroy() {
            var intent = Intent(Intent.ACTION_MAIN)
            var packageManager: PackageManager = packageManager
            for (resolveInfo in packageManager.queryIntentActivities(Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), PackageManager.MATCH_DEFAULT_ONLY)) {
                if (packageName != resolveInfo.activityInfo.packageName)  //if this activity is not in our activity (in other words, it's another default home screen)
                {
                    startActivity(intent)
                }
                break
            }
            super.onDestroy()
        }
    

提交回复
热议问题