Skip to content

Commit

Permalink
Search for deskclock package
Browse files Browse the repository at this point in the history
  • Loading branch information
gerard87 committed Apr 2, 2021
1 parent 5e875d2 commit 76ff850
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.clockwidget">

<queries>
<package android:name="com.google.android.deskclock" />
</queries>
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ package com.example.clockwidget.widgetprovider
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager

const val CLICK_PACKAGE: String = "com.google.android.deskclock"

private fun getOpenIntent(context: Context): Intent? =
context.packageManager.getLaunchIntentForPackage(CLICK_PACKAGE)
private fun getOpenIntent(context: Context): Intent? {
val apps: MutableList<ApplicationInfo> =
context.packageManager?.getInstalledApplications(PackageManager.GET_META_DATA) as MutableList<ApplicationInfo>
var pck: String = "com.google.android.deskclock"
for (app in apps) {
if (app.packageName.contains("deskclock")) pck = app.packageName
}
return context.packageManager.getLaunchIntentForPackage(pck)
}

fun getPendingIntent(context: Context) : PendingIntent {
// Create an Intent to launch OpenActivity
Expand Down

0 comments on commit 76ff850

Please sign in to comment.