You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Embarcadero Android Permission Model,如何自定义权限请求提示信息?

Customizing Read External Storage Permission Prompt in Embarcadero Android

Great question! I’ve dealt with this exact scenario when working with Embarcadero’s Android permission model, so let’s break down how to tailor the permission prompt to avoid mentioning photos or unrelated media content.

1. Show a Custom Explanation Dialog Before the System Prompt

The key here is to take control before the default Android system prompt appears. Embarcadero’s TPermissionService lets you check permissions first, then display your own dialog to explain exactly why you need the storage permission. This way, you set clear context before the system’s generic prompt shows up.

Here’s a C++Builder code example:

#include <System.Permissions.hpp>
#include <System.Dialogs.hpp>

void __fastcall TMainForm::RequestStorageAccess()
{
    const String StoragePermission = Permissions::JStringToString(
        TJManifest_permission::JavaClass::READ_EXTERNAL_STORAGE);

    // Skip if permission is already granted
    if (TPermissionService::Service->CheckPermission(StoragePermission))
    {
        ProceedWithFileOperations();
        return;
    }

    // Show your custom explanation first
    TDialogService::ShowMessage(
        "We need access to external storage to load and save app-specific files only. We won't access photos, videos, or other personal media.",
        "Storage Access Required",
        TMsgDlgBtn::mbOK,
        [this, StoragePermission](const TModalResult Result)
        {
            if (Result == mrOK)
            {
                // Now trigger the system permission request
                TPermissionService::Service->RequestPermissions(
                    {StoragePermission},
                    [this](const DynamicArray<String> APermissions, const DynamicArray<bool> AGrantResults)
                    {
                        if (AGrantResults[0])
                        {
                            ProceedWithFileOperations();
                        }
                        else
                        {
                            // Handle denied permission (e.g., show a message about restricted functionality)
                            TDialogService::ShowMessage("Storage access is required to use this feature. You can enable it in App Settings.");
                        }
                    });
            }
        });
}

2. Customize Permission Descriptions in the Android Manifest

While the system’s core prompt text is controlled by Android, you can add custom labels and descriptions that may appear alongside it (depending on the Android version and device manufacturer).

To edit your manifest in Embarcadero:

  • Go to Project > Options > Application > Manifest > Custom Manifest
  • Enable "Use a custom AndroidManifest.xml template"
  • Add or modify the <uses-permission> entry for storage access:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
    android:label="App File Access"
    android:description="This permission allows the app to access only its own files stored on external storage. No personal photos or media will be accessed." />

3. Handle "Never Ask Again" Scenarios

If a user denies the permission and checks "Never ask again," the system prompt won’t appear again. In this case, you should guide them to your app’s settings page with a clear message:

// Inside the permission denied callback
if (!TPermissionService::Service->ShouldShowRequestPermissionRationale(StoragePermission))
{
    TDialogService::ShowMessage(
        "Storage access was permanently disabled. To enable it, go to Settings > Apps > [Your App] > Permissions and enable Storage access.",
        "Permission Required",
        TMsgDlgBtn::mbOK,
        [this]()
        {
            // Open app settings directly
            TPermissionService::Service->OpenSettings();
        });
}

Key Notes

  • For Android 11 (API 30+) and above, READ_EXTERNAL_STORAGE has limited access. If you only need to access your app’s own files, consider using scoped storage instead (which doesn’t require this permission at all in many cases).
  • Always keep your explanation concise and honest—users are more likely to grant permissions when they understand the exact purpose.

内容的提问来源于stack exchange,提问作者relayman357

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:46:42