...
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,32 +90,57 @@ 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) {
|
||||||
packageManager.getApplicationInfo(packageName,
|
try {
|
||||||
PackageManager.ApplicationInfoFlags.of(PackageManager.GET_META_DATA.toLong()))
|
packageManager.getApplicationInfo(packageName,
|
||||||
|
PackageManager.ApplicationInfoFlags.of(PackageManager.GET_META_DATA.toLong()))
|
||||||
|
}catch (e :Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
|
try {
|
||||||
|
packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
|
||||||
|
}catch (e :Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if(appInfo == null){
|
||||||
|
WorkersDb.getRealm().apply {
|
||||||
|
writeBlocking {
|
||||||
|
defAppName = ""
|
||||||
|
var result = query<AppInfo>("pkgName == $0", packageName).find()
|
||||||
|
if (result.size > 0) {
|
||||||
|
val app = result.first()
|
||||||
|
delete(app)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
/* get default app name */
|
/* get default app name */
|
||||||
defAppName = packageManager.resolveActivity(Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)
|
defAppName = packageManager.resolveActivity(
|
||||||
.setPackage(packageName), 0)?.loadLabel(packageManager).toString()
|
Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
WorkersDb.getRealm().apply {
|
.setPackage(packageName), 0
|
||||||
writeBlocking {
|
)?.loadLabel(packageManager).toString()
|
||||||
var result = query<AppInfo>("pkgName == $0",packageName).find()
|
WorkersDb.getRealm().apply {
|
||||||
if(result.size > 0) {
|
writeBlocking {
|
||||||
val app = result.first()
|
var result = query<AppInfo>("pkgName == $0", packageName).find()
|
||||||
binding.totalTouch.text = "총 실행 횟수 : ".plus(app.clickCount.toString())
|
if (result.size > 0) {
|
||||||
binding.lastTouchDate.text = "최종 실행 일시 : ".plus(SimpleDateFormat("yyyy-MM-dd HH:mm").format(Date(app.lastUseDate)))
|
val app = result.first()
|
||||||
|
binding.totalTouch.text = "총 실행 횟수 : ".plus(app.clickCount.toString())
|
||||||
|
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())
|
||||||
// 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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun update() {
|
fun update() {
|
||||||
WorkersDb.getRealm().apply {
|
WorkersDb.getRealm().apply {
|
||||||
writeBlocking {
|
writeBlocking {
|
||||||
@ -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,26 +226,28 @@ 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 */
|
||||||
val packageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
val packageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(0))
|
packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(0))
|
||||||
} else {
|
} else {
|
||||||
packageManager.getPackageInfo(packageName, 0)
|
packageManager.getPackageInfo(packageName, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* show infos */
|
||||||
|
dialogBinding.mixed.text =
|
||||||
|
"${resources.getString(R.string.version)}: ${packageInfo.versionName} (${PackageInfoCompat.getLongVersionCode(packageInfo).toInt()})\n" +
|
||||||
|
"${resources.getString(R.string.sdk)}: ${appInfo.minSdkVersion} ~ ${appInfo.targetSdkVersion}\n" +
|
||||||
|
"${resources.getString(R.string.uid)}: ${appInfo.uid}\n" +
|
||||||
|
"${resources.getString(R.string.first_install)}: ${dateTimeFormat(packageInfo.firstInstallTime)}\n" +
|
||||||
|
"${resources.getString(R.string.last_update)}: ${dateTimeFormat(packageInfo.lastUpdateTime)}"
|
||||||
|
|
||||||
|
/* show permissions */
|
||||||
|
dialogBinding.permissions.text = permissionsList
|
||||||
}
|
}
|
||||||
|
|
||||||
/* show infos */
|
|
||||||
dialogBinding.mixed.text =
|
|
||||||
"${resources.getString(R.string.version)}: ${packageInfo.versionName} (${PackageInfoCompat.getLongVersionCode(packageInfo).toInt()})\n" +
|
|
||||||
"${resources.getString(R.string.sdk)}: ${appInfo.minSdkVersion} ~ ${appInfo.targetSdkVersion}\n" +
|
|
||||||
"${resources.getString(R.string.uid)}: ${appInfo.uid}\n" +
|
|
||||||
"${resources.getString(R.string.first_install)}: ${dateTimeFormat(packageInfo.firstInstallTime)}\n" +
|
|
||||||
"${resources.getString(R.string.last_update)}: ${dateTimeFormat(packageInfo.lastUpdateTime)}"
|
|
||||||
|
|
||||||
/* show permissions */
|
|
||||||
dialogBinding.permissions.text = permissionsList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* activity browser dialog */
|
/* activity browser dialog */
|
||||||
@ -231,51 +258,55 @@ 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)
|
|
||||||
|
|
||||||
/* get activity info */
|
|
||||||
val activityInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
/* show app name */
|
||||||
packageManager.getPackageInfo(
|
dialogBinding.appName.text = packageManager.getApplicationLabel(appInfo)
|
||||||
packageName, PackageManager.PackageInfoFlags.of(PackageManager.GET_ACTIVITIES.toLong())
|
|
||||||
)
|
/* get activity info */
|
||||||
} else {
|
val activityInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
|
packageManager.getPackageInfo(
|
||||||
}
|
packageName, PackageManager.PackageInfoFlags.of(PackageManager.GET_ACTIVITIES.toLong())
|
||||||
// BLog.LOGE("activity. >>>>> ${Gson().toJson(activityInfo)}")
|
|
||||||
/* show activity list */
|
|
||||||
val activityAdapter: ArrayAdapter<String> =
|
|
||||||
ArrayAdapter(requireContext(), R.layout.list_item, R.id.itemText, ArrayList())
|
|
||||||
if (activityInfo.activities.isNotEmpty()) {
|
|
||||||
for (activity in activityInfo.activities) {
|
|
||||||
if (packageName.contains("com.kakao") == true) {
|
|
||||||
// BLog.LOGE("activity. >>>>> ${Gson().toJson(activity)}")
|
|
||||||
}
|
|
||||||
activityAdapter.add(
|
|
||||||
activity.toString().split(" ").toTypedArray()[1].replace("}", "")
|
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
|
||||||
}
|
}
|
||||||
dialogBinding.activityList.adapter = activityAdapter
|
// BLog.LOGE("activity. >>>>> ${Gson().toJson(activityInfo)}")
|
||||||
}
|
/* show activity list */
|
||||||
|
val activityAdapter: ArrayAdapter<String> =
|
||||||
/* listen item clicks */
|
ArrayAdapter(requireContext(), R.layout.list_item, R.id.itemText, ArrayList())
|
||||||
dialogBinding.activityList.onItemClickListener =
|
if (activityInfo.activities.isNotEmpty()) {
|
||||||
AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, i: Int, _: Long ->
|
for (activity in activityInfo.activities) {
|
||||||
try {
|
if (packageName.contains("com.kakao") == true) {
|
||||||
/* open activity */
|
// BLog.LOGE("activity. >>>>> ${Gson().toJson(activity)}")
|
||||||
val intent = Intent()
|
}
|
||||||
intent.component = ComponentName(packageName, activityAdapter.getItem(i).toString())
|
activityAdapter.add(
|
||||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
activity.toString().split(" ").toTypedArray()[1].replace("}", "")
|
||||||
requireContext().startActivity(intent)
|
)
|
||||||
} catch (exception: Exception) {
|
|
||||||
/* couldn't open activity */
|
|
||||||
exception.printStackTrace()
|
|
||||||
val exceptionShort = (exception.toString().split(": ").toTypedArray())[0]
|
|
||||||
Toast.makeText(requireContext(),
|
|
||||||
"${resources.getString(R.string.unable_to_launch)} -\n$exceptionShort", Toast.LENGTH_LONG).show()
|
|
||||||
}
|
}
|
||||||
dialogBuilder.dismiss()
|
dialogBinding.activityList.adapter = activityAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* listen item clicks */
|
||||||
|
dialogBinding.activityList.onItemClickListener =
|
||||||
|
AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, i: Int, _: Long ->
|
||||||
|
try {
|
||||||
|
/* open activity */
|
||||||
|
val intent = Intent()
|
||||||
|
intent.component = ComponentName(packageName, activityAdapter.getItem(i).toString())
|
||||||
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
requireContext().startActivity(intent)
|
||||||
|
} catch (exception: Exception) {
|
||||||
|
/* couldn't open activity */
|
||||||
|
exception.printStackTrace()
|
||||||
|
val exceptionShort = (exception.toString().split(": ").toTypedArray())[0]
|
||||||
|
Toast.makeText(requireContext(),
|
||||||
|
"${resources.getString(R.string.unable_to_launch)} -\n$exceptionShort", Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
dialogBuilder.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* open app's page in app store/market */
|
/* open app's page in app store/market */
|
||||||
@ -317,35 +348,42 @@ binding.totalTouch.setOnClickListener { update() }
|
|||||||
|
|
||||||
private fun share() {
|
private fun share() {
|
||||||
try {
|
try {
|
||||||
// Create a temporary file to copy the APK
|
appInfo?.let { appInfo ->
|
||||||
val apkLabel = packageManager.getApplicationLabel(appInfo).toString().lowercase().replace(" ", "_")
|
// Create a temporary file to copy the APK
|
||||||
val tempApkFile = File(requireContext().externalCacheDir, "$apkLabel.apk")
|
val apkLabel = packageManager.getApplicationLabel(appInfo).toString().lowercase()
|
||||||
|
.replace(" ", "_")
|
||||||
|
val tempApkFile = File(requireContext().externalCacheDir, "$apkLabel.apk")
|
||||||
|
|
||||||
// Copy the APK file
|
// Copy the APK file
|
||||||
FileInputStream(File(appInfo.sourceDir)).use { `in` ->
|
FileInputStream(File(appInfo.sourceDir)).use { `in` ->
|
||||||
FileOutputStream(tempApkFile).use { out ->
|
FileOutputStream(tempApkFile).use { out ->
|
||||||
val buffer = ByteArray(1024)
|
val buffer = ByteArray(1024)
|
||||||
var length: Int
|
var length: Int
|
||||||
while (`in`.read(buffer).also { length = it } > 0) {
|
while (`in`.read(buffer).also { length = it } > 0) {
|
||||||
out.write(buffer, 0, length)
|
out.write(buffer, 0, length)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 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)
|
||||||
|
|
||||||
// Create a Share Intent
|
// Create a Share Intent
|
||||||
Intent(Intent.ACTION_SEND).apply {
|
Intent(Intent.ACTION_SEND).apply {
|
||||||
type = "application/vnd.android.package-archive"
|
type = "application/vnd.android.package-archive"
|
||||||
putExtra(Intent.EXTRA_STREAM, contentUri)
|
putExtra(Intent.EXTRA_STREAM, contentUri)
|
||||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
}.let {
|
}.let {
|
||||||
// Start the chooser activity
|
// Start the chooser activity
|
||||||
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() }
|
||||||
|
|||||||
@ -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