Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit df79657b authored by Mark Harman's avatar Mark Harman Committed by Mohammed Althaf T
Browse files

Fix crash for tiles for targetting Android 14.

parent f2a94263
Loading
Loading
Loading
Loading
+13 −1
Original line number Original line Diff line number Diff line
package net.sourceforge.opencamera;
package net.sourceforge.opencamera;


import android.app.PendingIntent;
import android.content.Intent;
import android.content.Intent;
import android.os.Build;
import android.os.Build;
import android.service.quicksettings.TileService;
import android.service.quicksettings.TileService;
@@ -47,6 +48,17 @@ public class MyTileService extends TileService {
        Intent intent = new Intent(this, MainActivity.class);
        Intent intent = new Intent(this, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setAction(TILE_ID);
        intent.setAction(TILE_ID);
        startActivityAndCollapse(intent); // use this instead of startActivity() so that the notification panel doesn't remain pulled down
        // use startActivityAndCollapse() instead of startActivity() so that the notification panel doesn't remain pulled down
        if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE ) {
            // startActivityAndCollapse(Intent) throws UnsupportedOperationException on Android 14+
            // FLAG_IMMUTABLE needed for PendingIntents on Android 12+
            PendingIntent pending_intent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE);
            startActivityAndCollapse(pending_intent);
        }
        else {
            // still get warning for startActivityAndCollapse being deprecated, but startActivityAndCollapse(PendingIntent) requires Android 14+
            // and only seems possible to disable the warning for the function, not this statement
            startActivityAndCollapse(intent);
        }
    }
    }
}
}
+13 −1
Original line number Original line Diff line number Diff line
package net.sourceforge.opencamera;
package net.sourceforge.opencamera;


import android.app.PendingIntent;
import android.content.Intent;
import android.content.Intent;
import android.os.Build;
import android.os.Build;
import android.service.quicksettings.TileService;
import android.service.quicksettings.TileService;
@@ -47,6 +48,17 @@ public class MyTileServiceFrontCamera extends TileService {
        Intent intent = new Intent(this, MainActivity.class);
        Intent intent = new Intent(this, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setAction(TILE_ID);
        intent.setAction(TILE_ID);
        startActivityAndCollapse(intent); // use this instead of startActivity() so that the notification panel doesn't remain pulled down
        // use startActivityAndCollapse() instead of startActivity() so that the notification panel doesn't remain pulled down
        if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE ) {
            // startActivityAndCollapse(Intent) throws UnsupportedOperationException on Android 14+
            // FLAG_IMMUTABLE needed for PendingIntents on Android 12+
            PendingIntent pending_intent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE);
            startActivityAndCollapse(pending_intent);
        }
        else {
            // still get warning for startActivityAndCollapse being deprecated, but startActivityAndCollapse(PendingIntent) requires Android 14+
            // and only seems possible to disable the warning for the function, not this statement
            startActivityAndCollapse(intent);
        }
    }
    }
}
}
+13 −1
Original line number Original line Diff line number Diff line
package net.sourceforge.opencamera;
package net.sourceforge.opencamera;


import android.app.PendingIntent;
import android.content.Intent;
import android.content.Intent;
import android.os.Build;
import android.os.Build;
import android.service.quicksettings.TileService;
import android.service.quicksettings.TileService;
@@ -47,6 +48,17 @@ public class MyTileServiceVideo extends TileService {
        Intent intent = new Intent(this, MainActivity.class);
        Intent intent = new Intent(this, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setAction(TILE_ID);
        intent.setAction(TILE_ID);
        startActivityAndCollapse(intent); // use this instead of startActivity() so that the notification panel doesn't remain pulled down
        // use startActivityAndCollapse() instead of startActivity() so that the notification panel doesn't remain pulled down
        if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE ) {
            // startActivityAndCollapse(Intent) throws UnsupportedOperationException on Android 14+
            // FLAG_IMMUTABLE needed for PendingIntents on Android 12+
            PendingIntent pending_intent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE);
            startActivityAndCollapse(pending_intent);
        }
        else {
            // still get warning for startActivityAndCollapse being deprecated, but startActivityAndCollapse(PendingIntent) requires Android 14+
            // and only seems possible to disable the warning for the function, not this statement
            startActivityAndCollapse(intent);
        }
    }
    }
}
}