android 跳轉到應用通知設定介面的樣本

來源:互聯網
上載者:User

標籤:code   task   class   系統   enabled   DApp   details   get   介面   

4.4以下並沒有提過從app跳轉到應用通知設定頁面的Action,可考慮跳轉到應用詳情頁面,下面是直接跳轉到應用通知設定的代碼:

        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {          Intent intent = new Intent();          intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");          intent.putExtra("app_package", getActivity().getPackageName());          intent.putExtra("app_uid", getActivity().getApplicationInfo().uid);          startActivity(intent);        } else if (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {          Intent intent = new Intent();          intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);          intent.addCategory(Intent.CATEGORY_DEFAULT);          intent.setData(Uri.parse("package:" + getActivity().getPackageName()));          startActivity(intent);        }

跳轉到應用詳情頁面的代碼如下:
        Intent localIntent = new Intent();        localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        if (Build.VERSION.SDK_INT >= 9) {          localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");          localIntent.setData(Uri.fromParts("package", getActivity().getPackageName(), null));        } else if (Build.VERSION.SDK_INT <= 8) {          localIntent.setAction(Intent.ACTION_VIEW);          localIntent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");          localIntent.putExtra("com.android.settings.ApplicationPkgName", getActivity().getPackageName());        }        startActivity(localIntent);

對於檢測app是否開啟通知,同樣是針對4.4以上的系統才有效:

NotificationManagerCompat manager = NotificationManagerCompat.from(App.getInstance().getContext());boolean isOpened = manager.areNotificationsEnabled();

4.4以下調用該方法並不會出錯,只是全部返回true,預設開啟狀態

---------

Android判斷APP通知許可權是否開啟

情境:判斷使用者是否屏蔽了應用的推送許可權
NotificationManagerCompat.from(context).areNotificationsEnabled()

android 跳轉到應用通知設定介面的樣本

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.