android - Ask in runtime permission for push notification -
i'm workin app , when app start, need ask @ user if want receive push notification. know push notification aren't dangerous permission need show popup possibility chose. manifest
<uses-permission android:name="android.permission.bind_notification_listener_service"/>
and runtime method should show popup
public void receivenotification(view v) { boolean haspermission = (contextcompat.checkselfpermission(mainactivity.this, manifest.permission.bind_notification_listener_service) == packagemanager.permission_granted); if (haspermission) { string token = firebaseinstanceid.getinstance().gettoken(); log.d(tag, "token"+token); toast.maketext(mainactivity.this, token, toast.length_short).show(); } else { activitycompat.requestpermissions(mainactivity.this, new string[]{manifest.permission.bind_notification_listener_service}, request_code_ask_permissions); } } @override public void onrequestpermissionsresult(int requestcode, @nonnull string[] permissions, @nonnull int[] grantresults) { super.onrequestpermissionsresult(requestcode, permissions, grantresults); if (requestcode == request_code_ask_permissions) { if (grantresults[0] == packagemanager.permission_granted) { string token = firebaseinstanceid.getinstance().gettoken(); log.d(tag, "token"+token); toast.maketext(mainactivity.this, token, toast.length_short).show(); } else { // permission denied toast.maketext(mainactivity.this, "message", toast.length_short) .show(); } } }
someone has idea how can show popup? it's importat :) thanks!
Comments
Post a Comment