mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Avoid potential Google Play Store ban
This commit is contained in:
		@@ -24,11 +24,15 @@
 | 
			
		||||
        <intent>
 | 
			
		||||
            <action android:name="android.media.action.VIDEO_CAPTURE" />
 | 
			
		||||
        </intent>
 | 
			
		||||
 | 
			
		||||
        <intent>
 | 
			
		||||
            <action android:name="android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS" />
 | 
			
		||||
        </intent>
 | 
			
		||||
    </queries>
 | 
			
		||||
 | 
			
		||||
    <!-- This is required for independent push notifications service to work
 | 
			
		||||
            (when FCM service can not be used) -->
 | 
			
		||||
    <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
 | 
			
		||||
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
 | 
			
		||||
 | 
			
		||||
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
 | 
			
		||||
         calls FlutterMain.startInitialization(this); in its onCreate method.
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,8 @@
 | 
			
		||||
package org.communiquons.comunic.independentnotifications;
 | 
			
		||||
 | 
			
		||||
import android.annotation.SuppressLint;
 | 
			
		||||
import android.app.Activity;
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.content.Intent;
 | 
			
		||||
import android.net.Uri;
 | 
			
		||||
import android.os.PowerManager;
 | 
			
		||||
import android.provider.Settings;
 | 
			
		||||
 | 
			
		||||
@@ -23,9 +21,10 @@ public class NotificationsChannel implements MethodChannel.MethodCallHandler {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
 | 
			
		||||
        try {
 | 
			
		||||
            if (call.method.equals("needPreConfiguration"))
 | 
			
		||||
                result.success(needPreConfiguration());
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            if (call.method.equals("preConfigure"))
 | 
			
		||||
            else if (call.method.equals("preConfigure"))
 | 
			
		||||
                preConfigure(result);
 | 
			
		||||
 | 
			
		||||
            else
 | 
			
		||||
@@ -37,19 +36,25 @@ public class NotificationsChannel implements MethodChannel.MethodCallHandler {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean needPreConfiguration() {
 | 
			
		||||
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
 | 
			
		||||
            if (!context.getSystemService(PowerManager.class).isIgnoringBatteryOptimizations(context.getPackageName())) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Pre-configure independent notifications service
 | 
			
		||||
     */
 | 
			
		||||
    private void preConfigure(@NonNull MethodChannel.Result result) throws Exception {
 | 
			
		||||
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
 | 
			
		||||
            if (!context.getSystemService(PowerManager.class).isIgnoringBatteryOptimizations(context.getPackageName())) {
 | 
			
		||||
                @SuppressLint("BatteryLife")
 | 
			
		||||
                Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
 | 
			
		||||
                        Uri.parse("package:" + context.getPackageName()));
 | 
			
		||||
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 | 
			
		||||
    private void preConfigure(@NonNull MethodChannel.Result result) {
 | 
			
		||||
        if (needPreConfiguration() && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
 | 
			
		||||
            // See https://stackoverflow.com/a/41853011
 | 
			
		||||
            Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
 | 
			
		||||
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 | 
			
		||||
 | 
			
		||||
                context.startActivity(intent);
 | 
			
		||||
            }
 | 
			
		||||
            context.startActivity(intent);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        result.success(null);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user