Request permission to send notifications
This commit is contained in:
parent
f07886fc5e
commit
9d01d88eed
|
@ -157,10 +157,13 @@ public class MainActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
openMiniPlayerUponPlayerStarted();
|
openMiniPlayerUponPlayerStarted();
|
||||||
|
|
||||||
|
if (PermissionHelper.checkPostNotificationsPermission(this,
|
||||||
|
PermissionHelper.POST_NOTIFICATIONS_REQUEST_CODE)) {
|
||||||
// Schedule worker for checking for new streams and creating corresponding notifications
|
// Schedule worker for checking for new streams and creating corresponding notifications
|
||||||
// if this is enabled by the user.
|
// if this is enabled by the user.
|
||||||
NotificationWorker.initialize(this);
|
NotificationWorker.initialize(this);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostCreate(final Bundle savedInstanceState) {
|
protected void onPostCreate(final Bundle savedInstanceState) {
|
||||||
|
@ -599,6 +602,9 @@ public class MainActivity extends AppCompatActivity {
|
||||||
((VideoDetailFragment) fragment).openDownloadDialog();
|
((VideoDetailFragment) fragment).openDownloadDialog();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case PermissionHelper.POST_NOTIFICATIONS_REQUEST_CODE:
|
||||||
|
NotificationWorker.initialize(this);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.settings.NewPipeSettings;
|
import org.schabi.newpipe.settings.NewPipeSettings;
|
||||||
|
|
||||||
public final class PermissionHelper {
|
public final class PermissionHelper {
|
||||||
|
public static final int POST_NOTIFICATIONS_REQUEST_CODE = 779;
|
||||||
public static final int DOWNLOAD_DIALOG_REQUEST_CODE = 778;
|
public static final int DOWNLOAD_DIALOG_REQUEST_CODE = 778;
|
||||||
public static final int DOWNLOADS_REQUEST_CODE = 777;
|
public static final int DOWNLOADS_REQUEST_CODE = 777;
|
||||||
|
|
||||||
|
@ -71,8 +72,7 @@ public final class PermissionHelper {
|
||||||
|
|
||||||
// No explanation needed, we can request the permission.
|
// No explanation needed, we can request the permission.
|
||||||
ActivityCompat.requestPermissions(activity,
|
ActivityCompat.requestPermissions(activity,
|
||||||
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
|
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, requestCode);
|
||||||
requestCode);
|
|
||||||
|
|
||||||
// PERMISSION_WRITE_STORAGE is an
|
// PERMISSION_WRITE_STORAGE is an
|
||||||
// app-defined int constant. The callback method gets the
|
// app-defined int constant. The callback method gets the
|
||||||
|
@ -83,6 +83,18 @@ public final class PermissionHelper {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean checkPostNotificationsPermission(final Activity activity,
|
||||||
|
final int requestCode) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
|
||||||
|
&& ContextCompat.checkSelfPermission(activity,
|
||||||
|
Manifest.permission.POST_NOTIFICATIONS)
|
||||||
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
|
ActivityCompat.requestPermissions(activity,
|
||||||
|
new String[] {Manifest.permission.POST_NOTIFICATIONS}, requestCode);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In order to be able to draw over other apps,
|
* In order to be able to draw over other apps,
|
||||||
|
|
Loading…
Reference in New Issue