Android में Permissions का इस्तेमाल Apps को Sensitive Features और Data (जैसे Camera, Location, Storage, Contacts) को Access देने के लिए किया जाता है.
Users की Privacy और Security को Maintain करने के लिए Android में Permission System होता है।
जब कोई App Sensitive Information या Hardware Features का Use करना चाहती है, तो पहले User की Permission लेनी पड़ती है।
Android में Permissions को दो मुख्य Categories में बाँटा गया है:
इन Permissions से User की Privacy को ज़्यादा खतरा नहीं होता।
Android इन्हें Automatically Approve कर देता है, इसलिए User से Permission मांगने की ज़रूरत नहीं होती।
Example:
⚠ Sensitive Data या Hardware Features को Access करने के लिए User की मंज़ूरी चाहिए।
⚠ Android User से Runtime पर Permission मांगता है।
⚠ Example:
अगर किसी App को कोई Permission चाहिए, तो उसे AndroidManifest.xml फाइल में Declare करना ज़रूरी है।
Example: App को Internet, Location और Camera Access चाहिए
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp"> <!-- Normal Permission (Automatically Granted) --> <uses-permission android:name="android.permission.INTERNET" /> <!-- Dangerous Permissions (User Approval Required) --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.CAMERA" /> </manifest>
Normal Permission Automatically मिल जाती है, लेकिन Dangerous Permission को Runtime पर मांगना पड़ता है।
Android 6.0 (API Level 23) और उससे ऊपर Dangerous Permissions को Runtime पर Grant करना पड़ता है।
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { // Permission Granted नहीं है, अब इसे Request करेंगे }
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 100);
यहाँ 100 एक Request Code है, जिससे हम Response को Identify कर सकते हैं।
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == 100) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.d("Permission", "Camera Permission Granted!"); } else { Log.d("Permission", "Camera Permission Denied!"); } } }
✔ अगर User Permission Grant करता है, तो App को Access मिल जाता है।
❌ अगर User Permission Deny कर देता है, तो App को Access नहीं मिलता।
अगर App को एक से ज्यादा Dangerous Permissions चाहिए, तो एक साथ Request कर सकते हैं।
ActivityCompat.requestPermissions(this, new String[]{ Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.CAMERA, Manifest.permission.READ_CONTACTS }, 101);
अगर User Permission Deny कर देता है, तो उसे समझाने के लिए "Why Permission is Required?" Dialog दिखा सकते हैं।
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) { new AlertDialog.Builder(this) .setTitle("Camera Permission Required") .setMessage("This app needs Camera access to take photos.") .setPositiveButton("OK", (dialog, which) -> { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 100); }) .setNegativeButton("Cancel", (dialog, which) -> dialog.dismiss()) .create() .show(); }
अगर User "Don't Ask Again" पर क्लिक कर देता है, तो उसे Settings में Permission Enable करने के लिए कहना होगा।
अगर User ने "Don't Ask Again" को Select कर लिया है, तो उसे Manually Settings में Permission Enable करने को कह सकते हैं।
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", getPackageName(), null); intent.setData(uri); startActivity(intent);
इस Code से App के Settings Page Open होंगे, जहाँ User Permission Enable कर सकता है।
Android 11 और ऊपर में कुछ नए Security और Privacy Updates आए हैं:
User "Allow only this time" Option चुन सकता है।
अगली बार फिर से Permission मांगनी होगी।
पहले Foreground Permission लेनी होगी, फिर Background Location मांग सकते हैं।
अगर User लंबे समय तक App को Use नहीं करता, तो Android Automatic Permissions Reset कर देता है।
हैलो दोस्तों! उम्मीद करता हूं आपको हमारा यह content/post पसंद आया होगा। अगर आपको हमारा ये content/post पसंद आई हो तो अपने दोस्तों के पास भी share करे। और अगर आपको कोई problem या कोई specific content हिन्दी में चाहिए है तो आप हमें नीचे दिए गए Email या whatsapp number के जरिए बता सकते है।
अगर आप CCC/diploma/polytechnic/MCA/BCA etc कर रहे है तो ये website स्पेशली आपके लिए ही है, जो student हिंदी में पढ़ाई करते है।
Email: deepanshuranjan8057@gmail.com
Whatsapp: +91 8057754706