使用特定意图获取包名称或应用程序名称

编程入门 行业动态 更新时间:2024-10-22 18:34:37
本文介绍了使用特定意图获取包名称或应用程序名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

关于获取包名称或使用特定意图的应用程序名称(例如 Camera),我需要一些帮助.

I need some help regarding getting the package name or the application name that is using a specific intent say Camera.

我正在开发一个应用程序,用于扫描哪个应用程序在后台使用摄像头或其他一些(如麦克风等).但我找不到任何方法来获取此类详细信息.任何帮助,将不胜感激.谢谢

I am developing an application that scans which application is using the camera in background or some other like microphone etc. But I couldn't find any way to get the such detail. Any help would be appreciated. Thanks

推荐答案

另外请告诉我是否可以显示一个对话框询问一些权限用于像在棉花糖 6.0 中一样使用相机.我需要做这样的事情在棉花糖 23 api 下方的设备中.就像启动相机应用程序一样应该在对话框中询问许可,如果我点击否,它应该关闭相机应用

Also please tell me if I can display a dialog asking some permission for using the camera like in marshmallow 6.0. I need such thing to do in device below marshmallow 23 api. Like launching the camera app should ask the permission in a dialog and if I click on no it should close the camera app

对于 Android Marshmallow ,无论何时你想启动相机,你应该检查你是否有访问相机的权限,如果没有,你可以通过显示系统对话框来请求权限 -

For Android Marshmallow , whenever you want to launch camera you should check whether you have permissions for accessing camera and if not you can request for permissions by showing the system dialog -

if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, 1001); //May be any number } else { //Launch camera since you have the permission }

此外,您必须实现 onRequestPermissionsResult() 回调,以便您可以检查权限对话框上的用户操作并做出相应的反应 -

Also, you have to implement onRequestPermissionsResult() callback so that you can check the user action on the permission dialog and react accordingly -

@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case 1001 : //Same request code if (grantResults.length <= 0 || grantResults[0] != PackageManager.PERMISSION_GRANTED) { Toast.makeText(MainActivity.this,"Camera permission requied", Toast.LENGTH_LONG).show(); } else if (grantResults.length > 0 && (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)) { //Launch camera } break; } }

更多推荐

使用特定意图获取包名称或应用程序名称

本文发布于:2023-11-09 05:46:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571537.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:名称   意图   应用程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!