mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
Merge pull request #6 from finnmglas/fix/open-finder
Show alertbox if an app is installed but not launchable
This commit is contained in:
commit
d6c430ae2e
3 changed files with 35 additions and 12 deletions
|
@ -1,7 +1,10 @@
|
||||||
package com.finnmglas.launcher
|
package com.finnmglas.launcher
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.AlertDialog
|
||||||
|
import android.content.ActivityNotFoundException
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.DialogInterface
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.DisplayMetrics
|
import android.util.DisplayMetrics
|
||||||
|
@ -36,8 +39,7 @@ GestureDetector.OnDoubleTapListener {
|
||||||
private val displayMetrics = DisplayMetrics()
|
private val displayMetrics = DisplayMetrics()
|
||||||
|
|
||||||
private fun getIntent(packageName: String): Intent? {
|
private fun getIntent(packageName: String): Intent? {
|
||||||
val pm = applicationContext.packageManager
|
val intent: Intent? = packageManager.getLaunchIntentForPackage(packageName)
|
||||||
val intent: Intent? = pm.getLaunchIntentForPackage(packageName)
|
|
||||||
intent?.addCategory(Intent.CATEGORY_LAUNCHER)
|
intent?.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
return intent
|
return intent
|
||||||
}
|
}
|
||||||
|
@ -49,11 +51,25 @@ GestureDetector.OnDoubleTapListener {
|
||||||
applicationContext.startActivity(intent1)
|
applicationContext.startActivity(intent1)
|
||||||
overridePendingTransition(0, 0)
|
overridePendingTransition(0, 0)
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(
|
if (isInstalled(packageName, this)){
|
||||||
this,
|
|
||||||
"Open settings to choose an app for this action",
|
AlertDialog.Builder(this)
|
||||||
Toast.LENGTH_SHORT
|
.setTitle("Can't open app")
|
||||||
).show()
|
.setMessage("Want to change its settings ('add it to the apps screen')?")
|
||||||
|
.setPositiveButton(android.R.string.yes,
|
||||||
|
DialogInterface.OnClickListener { dialog, which ->
|
||||||
|
openAppSettings(packageName, this)
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.no, null)
|
||||||
|
.setIcon(android.R.drawable.ic_dialog_info)
|
||||||
|
.show()
|
||||||
|
} else {
|
||||||
|
Toast.makeText(
|
||||||
|
this,
|
||||||
|
"Open settings to choose an app for this action",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,30 @@
|
||||||
package com.finnmglas.launcher
|
package com.finnmglas.launcher
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
|
import android.net.Uri
|
||||||
|
import android.provider.Settings
|
||||||
|
import androidx.core.content.ContextCompat.startActivity
|
||||||
|
|
||||||
val none_msg = "None found"
|
val none_msg = "None found"
|
||||||
|
|
||||||
fun isInstalled(uri: String, context: Context): Boolean {
|
fun isInstalled(uri: String, context: Context): Boolean {
|
||||||
val pm: PackageManager = context.packageManager
|
|
||||||
try {
|
try {
|
||||||
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES)
|
context.packageManager.getPackageInfo(uri, PackageManager.GET_ACTIVITIES)
|
||||||
return true
|
return true
|
||||||
} catch (e: PackageManager.NameNotFoundException) {
|
} catch (e: PackageManager.NameNotFoundException) {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun openAppSettings(pkg :String, context:Context){
|
||||||
|
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||||
|
intent.data = Uri.parse("package:$pkg")
|
||||||
|
context.startActivity(intent)
|
||||||
|
}
|
||||||
|
|
||||||
fun loadSettings(sharedPref : SharedPreferences){
|
fun loadSettings(sharedPref : SharedPreferences){
|
||||||
upApp = sharedPref.getString("action_upApp", "").toString()
|
upApp = sharedPref.getString("action_upApp", "").toString()
|
||||||
downApp = sharedPref.getString("action_downApp", "").toString()
|
downApp = sharedPref.getString("action_downApp", "").toString()
|
||||||
|
|
|
@ -98,9 +98,7 @@ class SettingsActivity : AppCompatActivity() {
|
||||||
.setPositiveButton(android.R.string.yes,
|
.setPositiveButton(android.R.string.yes,
|
||||||
DialogInterface.OnClickListener { dialog, which ->
|
DialogInterface.OnClickListener { dialog, which ->
|
||||||
try {
|
try {
|
||||||
val intent = Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
openAppSettings(packageName, this)
|
||||||
intent.data = Uri.parse("package:$packageName")
|
|
||||||
startActivity(intent)
|
|
||||||
} catch ( e : ActivityNotFoundException) {
|
} catch ( e : ActivityNotFoundException) {
|
||||||
val intent = Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS)
|
val intent = Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
|
|
Loading…
Add table
Reference in a new issue