直銷網(wǎng)站系統(tǒng)制作價(jià)格小說引流推廣
在應(yīng)用申請(qǐng)懸浮窗權(quán)限的時(shí)候,可以跳轉(zhuǎn)到相應(yīng)的設(shè)置界面,并且自動(dòng)切換到應(yīng)用的條目,高亮顯示一下,
android懸浮窗權(quán)限怎么申請(qǐng)
在Android中,要申請(qǐng)懸浮窗權(quán)限,需要以下步驟:
- 在 AndroidManifest.xml 文件中添加權(quán)限聲明。在?
<manifest>
?標(biāo)簽內(nèi)部添加以下代碼:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
- 在你的應(yīng)用程序中請(qǐng)求懸浮窗權(quán)限??梢酝ㄟ^以下代碼在你的 Activity 或者 Fragment 中請(qǐng)求權(quán)限:
java
復(fù)制
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) {Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,Uri.parse("package:" + getPackageName()));startActivityForResult(intent, REQUEST_CODE);
}
上述代碼會(huì)打開一個(gè)系統(tǒng)設(shè)置界面,允許用戶授予懸浮窗權(quán)限。
而申請(qǐng)通知訪問權(quán)限時(shí),在跳轉(zhuǎn)的頁面中沒有高亮顯示應(yīng)用的條目,為什么呢,
因?yàn)?span style="background-color:#ffffff;">OverlaySettingsActivity 中設(shè)置了?<data?android:scheme="package"?/>
packages/apps/Settings/AndroidManifest.xml<activity
android:name="Settings$OverlaySettingsActivity"
android:exported="true"
android:label="@string/draw_overlay">
<intent-filter android:priority="1">
<action android:name="android.settings.action.MANAGE_OVERLAY_PERMISSION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter android:priority="1">
<action android:name="android.settings.action.MANAGE_OVERLAY_PERMISSION" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.manageapplications.ManageApplications" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_apps"/>
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity><activity
android:name="Settings$NotificationAssistantSettingsActivity"
android:exported="true"
android:label="@string/notification_assistant_title">
<intent-filter android:priority="1">
<action android:name="android.settings.NOTIFICATION_ASSISTANT_SETTINGS" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.notification.ConfigureNotificationSettings" />
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
android:value="@string/menu_key_notifications"/>
</activity>
附:
android中怎么跳轉(zhuǎn)到NotificationAssistantSettingsActivity
在Android中,沒有名為 NotificationAssistantSettingsActivity 的標(biāo)準(zhǔn)活動(dòng)或類。如果你希望跳轉(zhuǎn)到通知助手設(shè)置界面,可以使用以下代碼:
Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
startActivity(intent);
上述代碼將打開通知訪問權(quán)限設(shè)置界面,其中用戶可以配置通知助手相關(guān)的權(quán)限。
請(qǐng)注意,根據(jù)不同的Android版本和設(shè)備制造商,界面的外觀和可用選項(xiàng)可能會(huì)有所不同。確保你的應(yīng)用程序具有適當(dāng)?shù)臋?quán)限,以請(qǐng)求用戶打開通知助手設(shè)置界面。