...
This commit is contained in:
parent
d7f9c251a6
commit
8dd264dee0
@ -78,8 +78,8 @@ internal class AppMenu : BottomSheetDialogFragment() {
|
|||||||
private lateinit var binding: AppMenuBinding
|
private lateinit var binding: AppMenuBinding
|
||||||
private lateinit var packageName: String
|
private lateinit var packageName: String
|
||||||
private lateinit var packageManager: PackageManager
|
private lateinit var packageManager: PackageManager
|
||||||
private lateinit var appInfo: ApplicationInfo
|
|
||||||
private lateinit var defAppName: String
|
private lateinit var defAppName: String
|
||||||
|
var appInfo: ApplicationInfo? = null
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
binding = AppMenuBinding.inflate(inflater, container, false)
|
binding = AppMenuBinding.inflate(inflater, container, false)
|
||||||
@ -90,22 +90,47 @@ internal class AppMenu : BottomSheetDialogFragment() {
|
|||||||
|
|
||||||
/* get application info */
|
/* get application info */
|
||||||
appInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
appInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
try {
|
||||||
packageManager.getApplicationInfo(packageName,
|
packageManager.getApplicationInfo(packageName,
|
||||||
PackageManager.ApplicationInfoFlags.of(PackageManager.GET_META_DATA.toLong()))
|
PackageManager.ApplicationInfoFlags.of(PackageManager.GET_META_DATA.toLong()))
|
||||||
} else {
|
}catch (e :Exception) {
|
||||||
packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get default app name */
|
} else {
|
||||||
defAppName = packageManager.resolveActivity(Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)
|
try {
|
||||||
.setPackage(packageName), 0)?.loadLabel(packageManager).toString()
|
packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
|
||||||
|
}catch (e :Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(appInfo == null){
|
||||||
WorkersDb.getRealm().apply {
|
WorkersDb.getRealm().apply {
|
||||||
writeBlocking {
|
writeBlocking {
|
||||||
var result = query<AppInfo>("pkgName == $0",packageName).find()
|
defAppName = ""
|
||||||
if(result.size > 0) {
|
var result = query<AppInfo>("pkgName == $0", packageName).find()
|
||||||
|
if (result.size > 0) {
|
||||||
|
val app = result.first()
|
||||||
|
delete(app)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
/* get default app name */
|
||||||
|
defAppName = packageManager.resolveActivity(
|
||||||
|
Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
|
.setPackage(packageName), 0
|
||||||
|
)?.loadLabel(packageManager).toString()
|
||||||
|
WorkersDb.getRealm().apply {
|
||||||
|
writeBlocking {
|
||||||
|
var result = query<AppInfo>("pkgName == $0", packageName).find()
|
||||||
|
if (result.size > 0) {
|
||||||
val app = result.first()
|
val app = result.first()
|
||||||
binding.totalTouch.text = "총 실행 횟수 : ".plus(app.clickCount.toString())
|
binding.totalTouch.text = "총 실행 횟수 : ".plus(app.clickCount.toString())
|
||||||
binding.lastTouchDate.text = "최종 실행 일시 : ".plus(SimpleDateFormat("yyyy-MM-dd HH:mm").format(Date(app.lastUseDate)))
|
binding.lastTouchDate.text =
|
||||||
|
"최종 실행 일시 : ".plus(SimpleDateFormat("yyyy-MM-dd HH:mm").format(Date(app.lastUseDate)))
|
||||||
// app.clickCount = app.clickCount + 15
|
// app.clickCount = app.clickCount + 15
|
||||||
|
|
||||||
// app.lastUseDate = Math.max(app.lastUseDate, System.currentTimeMillis())
|
// app.lastUseDate = Math.max(app.lastUseDate, System.currentTimeMillis())
|
||||||
@ -114,7 +139,7 @@ internal class AppMenu : BottomSheetDialogFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun update() {
|
fun update() {
|
||||||
WorkersDb.getRealm().apply {
|
WorkersDb.getRealm().apply {
|
||||||
@ -127,7 +152,7 @@ internal class AppMenu : BottomSheetDialogFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.totalTouch.setOnClickListener { update() }
|
binding.totalTouch.setOnClickListener { update() }
|
||||||
binding.lastTouchDate.setOnClickListener { update() }
|
binding.lastTouchDate.setOnClickListener { update() }
|
||||||
/* set application name and package name */
|
/* set application name and package name */
|
||||||
binding.appName.apply {
|
binding.appName.apply {
|
||||||
@ -201,7 +226,7 @@ binding.totalTouch.setOnClickListener { update() }
|
|||||||
.setPositiveButton(android.R.string.cancel, null)
|
.setPositiveButton(android.R.string.cancel, null)
|
||||||
.show()
|
.show()
|
||||||
|
|
||||||
/* show app name */
|
appInfo?.let { appInfo ->
|
||||||
dialogBinding.appName.text = packageManager.getApplicationLabel(appInfo)
|
dialogBinding.appName.text = packageManager.getApplicationLabel(appInfo)
|
||||||
|
|
||||||
/* get package info */
|
/* get package info */
|
||||||
@ -223,6 +248,8 @@ binding.totalTouch.setOnClickListener { update() }
|
|||||||
dialogBinding.permissions.text = permissionsList
|
dialogBinding.permissions.text = permissionsList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* activity browser dialog */
|
/* activity browser dialog */
|
||||||
private fun activityBrowser() {
|
private fun activityBrowser() {
|
||||||
val dialogBinding = ActivityBrowserDialogBinding.inflate(lActivity!!.layoutInflater)
|
val dialogBinding = ActivityBrowserDialogBinding.inflate(lActivity!!.layoutInflater)
|
||||||
@ -231,6 +258,9 @@ binding.totalTouch.setOnClickListener { update() }
|
|||||||
.setPositiveButton(android.R.string.cancel, null)
|
.setPositiveButton(android.R.string.cancel, null)
|
||||||
.show()
|
.show()
|
||||||
|
|
||||||
|
appInfo?.let { appInfo ->
|
||||||
|
|
||||||
|
|
||||||
/* show app name */
|
/* show app name */
|
||||||
dialogBinding.appName.text = packageManager.getApplicationLabel(appInfo)
|
dialogBinding.appName.text = packageManager.getApplicationLabel(appInfo)
|
||||||
|
|
||||||
@ -277,6 +307,7 @@ binding.totalTouch.setOnClickListener { update() }
|
|||||||
dialogBuilder.dismiss()
|
dialogBuilder.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* open app's page in app store/market */
|
/* open app's page in app store/market */
|
||||||
private fun appStore() {
|
private fun appStore() {
|
||||||
@ -317,8 +348,10 @@ binding.totalTouch.setOnClickListener { update() }
|
|||||||
|
|
||||||
private fun share() {
|
private fun share() {
|
||||||
try {
|
try {
|
||||||
|
appInfo?.let { appInfo ->
|
||||||
// Create a temporary file to copy the APK
|
// Create a temporary file to copy the APK
|
||||||
val apkLabel = packageManager.getApplicationLabel(appInfo).toString().lowercase().replace(" ", "_")
|
val apkLabel = packageManager.getApplicationLabel(appInfo).toString().lowercase()
|
||||||
|
.replace(" ", "_")
|
||||||
val tempApkFile = File(requireContext().externalCacheDir, "$apkLabel.apk")
|
val tempApkFile = File(requireContext().externalCacheDir, "$apkLabel.apk")
|
||||||
|
|
||||||
// Copy the APK file
|
// Copy the APK file
|
||||||
@ -334,7 +367,11 @@ binding.totalTouch.setOnClickListener { update() }
|
|||||||
|
|
||||||
// Generate a content URI using FileProvider
|
// Generate a content URI using FileProvider
|
||||||
val contentUri =
|
val contentUri =
|
||||||
FileProvider.getUriForFile(requireContext(), "${requireContext().packageName}.fileprovider", tempApkFile)
|
FileProvider.getUriForFile(
|
||||||
|
requireContext(),
|
||||||
|
"${requireContext().packageName}.fileprovider",
|
||||||
|
tempApkFile
|
||||||
|
)
|
||||||
|
|
||||||
//requireContext().grantUriPermission(receivers.package.name, contentUri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
//requireContext().grantUriPermission(receivers.package.name, contentUri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
|
||||||
@ -348,6 +385,7 @@ binding.totalTouch.setOnClickListener { update() }
|
|||||||
startActivity(Intent.createChooser(it, getString(R.string.share_apk_message)))
|
startActivity(Intent.createChooser(it, getString(R.string.share_apk_message)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (e: PackageManager.NameNotFoundException) { e.printStackTrace() }
|
catch (e: PackageManager.NameNotFoundException) { e.printStackTrace() }
|
||||||
catch (e: IOException) { e.printStackTrace() }
|
catch (e: IOException) { e.printStackTrace() }
|
||||||
this.dismiss()
|
this.dismiss()
|
||||||
|
|||||||
@ -25,6 +25,7 @@ class AppInfoGetter : BaseGetter {
|
|||||||
}
|
}
|
||||||
override fun realWork(): Result {
|
override fun realWork(): Result {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
var packageManager = lActivity?.packageManager
|
var packageManager = lActivity?.packageManager
|
||||||
var packageInfoList: MutableList<ResolveInfo> = mutableListOf()
|
var packageInfoList: MutableList<ResolveInfo> = mutableListOf()
|
||||||
packageInfoList = (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
packageInfoList = (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
|||||||
@ -139,3 +139,8 @@ fun longitudeRange(latitude: Double, longitude: Double, radiusInMeters: Int): Do
|
|||||||
|
|
||||||
return doubleArrayOf(minLongitude, maxLongitude)
|
return doubleArrayOf(minLongitude, maxLongitude)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//https://jinkpark.tistory.com/296
|
||||||
|
//https://develoyummer.tistory.com/103
|
||||||
|
//https://ghj1001020.tistory.com/300
|
||||||
Loading…
x
Reference in New Issue
Block a user