Skip to content

Commit

Permalink
chore: add QUERY_ALL_PACKAGES permission and some misc. changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash-Garg committed Mar 17, 2022
1 parent 4817f4e commit bb31270
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 65 deletions.
5 changes: 4 additions & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dev.yashgarg.appcheck">
package="dev.yashgarg.appcheck">

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class AppcheckPlugin : FlutterPlugin, MethodCallHandler {
}

private fun isAppEnabled(packageName: String, result: Result) {
var appStatus = false
val appStatus: Boolean
try {
val appInfo: ApplicationInfo = context.packageManager.getApplicationInfo(packageName, 0)
appStatus = appInfo.enabled
Expand Down
3 changes: 2 additions & 1 deletion example/android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
</manifest>
23 changes: 13 additions & 10 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dev.yashgarg.appcheck_example">
<application
android:label="appcheck_example"

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />


<application
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
android:icon="@mipmap/ic_launcher"
android:label="appcheck_example">
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:exported="true"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
Expand Down
103 changes: 51 additions & 52 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,31 @@ class _AppCheckExampleState extends State<AppCheckExample> {
List<AppInfo>? _installedApps;

if (Platform.isAndroid) {
const package = "com.android.chrome";
const package = "com.google.android.apps.maps";
_installedApps = await AppCheck.getInstalledApps();
debugPrint(_installedApps.toString());

// await AppCheck.checkAvailability(package).then(
// (app) => debugPrint(app.toString()),
// );
await AppCheck.checkAvailability(package).then(
(app) => debugPrint(app.toString()),
);

// await AppCheck.isAppEnabled(package).then(
// (enabled) => enabled
// ? debugPrint('$package enabled')
// : debugPrint('$package disabled'),
// );
// } else if (Platform.isIOS) {
// // iOS doesn't allow to get installed apps.
// _installedApps = iOSApps;
await AppCheck.isAppEnabled(package).then(
(enabled) => enabled
? debugPrint('$package enabled')
: debugPrint('$package disabled'),
);
} else if (Platform.isIOS) {
// iOS doesn't allow to get installed apps.
_installedApps = iOSApps;

// await AppCheck.checkAvailability("calshow://").then(
// (app) => debugPrint(app.toString()),
// );
// }

// setState(() {
// installedApps = _installedApps;
// });
await AppCheck.checkAvailability("calshow://").then(
(app) => debugPrint(app.toString()),
);
}

setState(() {
installedApps = _installedApps;
});
}

@override
Expand All @@ -66,39 +65,39 @@ class _AppCheckExampleState extends State<AppCheckExample> {
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: const Text('App Availability Example App')),
// body: installedApps != null && installedApps!.isNotEmpty
// ? ListView.builder(
// itemCount: installedApps!.length,
// itemBuilder: (context, index) {
// final app = installedApps![index];
body: installedApps != null && installedApps!.isNotEmpty
? ListView.builder(
itemCount: installedApps!.length,
itemBuilder: (context, index) {
final app = installedApps![index];

// return ListTile(
// title: Padding(
// padding: const EdgeInsets.only(left: 12.0),
// child: Text(app.appName ?? app.packageName),
// ),
// trailing: IconButton(
// icon: const Icon(Icons.open_in_new),
// onPressed: () {
// ScaffoldMessenger.of(context).hideCurrentSnackBar();
// AppCheck.launchApp(app.packageName).then((_) {
// debugPrint(
// "${app.appName ?? app.packageName} launched!",
// );
// }).catchError((err) {
// ScaffoldMessenger.of(context).showSnackBar(SnackBar(
// content: Text(
// "${app.appName ?? app.packageName} not found!",
// ),
// ));
// debugPrint(err.toString());
// });
// },
// ),
// );
// },
// )
// : const Center(child: Text('No installed apps found!')),
return ListTile(
title: Padding(
padding: const EdgeInsets.only(left: 12.0),
child: Text(app.appName ?? app.packageName),
),
trailing: IconButton(
icon: const Icon(Icons.open_in_new),
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
AppCheck.launchApp(app.packageName).then((_) {
debugPrint(
"${app.appName ?? app.packageName} launched!",
);
}).catchError((err) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"${app.appName ?? app.packageName} not found!",
),
));
debugPrint(err.toString());
});
},
),
);
},
)
: const Center(child: Text('No installed apps found!')),
),
);
}
Expand Down

0 comments on commit bb31270

Please sign in to comment.