关于获取包名称或使用特定意图的应用程序名称(例如 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; } }更多推荐
使用特定意图获取包名称或应用程序名称
发布评论