我是android的新手
基本上我想了解如何从后台服务中查找当前运行的前台应用程序是否为相机应用程序(本机和第三方)的建议。
我可以使用以下代码片段获取当前运行活动的类名和包名称,
ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
Log.d("TopActivity", "Class Name:" + taskInfo.get(0).topActivity.getClassName());
ComponentName componentInfo = taskInfo.get(0).topActivity;
Log.d("TopActivity", "Package Name:" + componentInfo.getPackageName());
和各种相机应用的结果是,
Native Camera
D/TopActivity(23237): Class Name: com.lge.camera.CameraAppLauncher
D/TopActivity(23237): Package Name: com.lge.camera
Google Camera
D/TopActivity(23237): Class Name: com.android.camera.CameraLauncher
D/TopActivity(23237): Package Name: com.google.android.GoogleCamera
Cartoon Camera
D/TopActivity(23237): Class Name: com.fingersoft.camera.MainActivity
D/TopActivity(23237): Package Name: com.fingersoft.cartooncamera
QR Droid - Scan
D/TopActivity(23237): Class Name: la.droid.qr.DeCamara
D/TopActivity(23237): Package Name: la.droid.qr
Little Photo - Camera App
D/TopActivity(23237): Class Name: com.littlephoto.TakeActivity
D/TopActivity(23237): Package Name: com.littlephoto
正如您所看到的,从日志中无法确定应用程序是否为相机。
有没有办法实现它?
提前致谢:)