Reputation: 148
I am still new with flutter plugins development and method channels.
I have this function in my flutter code that shows a pop up window
void _showOverlayWindow() {
if (!_isShowingWindow) {
SystemWindowHeader header = SystemWindowHeader(...);
SystemWindowBody body = SystemWindowBody(...);
SystemWindowFooter footer = SystemWindowFooter(...);
SystemAlertWindow.showSystemWindow(...);
}
}
and in my java code I have a brodcast receiver that triggers on some event
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("MYTAG","Sent from brodcast receiver");
}
}
the receiver works on it's own, now I'd like to know if it's possible to run my flutter function that shows the pop up from the java side. Currently I am able to run the app through the receiver as follows
public void onReceive(Context context, Intent intent) {
Log.d("MYTAG","Sent from brodcast receiver");
Intent i = new Intent();
i.setClassName("com.example.myApp","com.example.myApp.MainActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(i);
}
but I was wondering if it possible to run only that function, just showing the pop up without the app screen view, and if it is possible, does that mean I still have to load the whole app? because the function depends on other states in the class.
Thanks.
Upvotes: 0
Views: 466
Reputation: 3326
When setting the background color to transparent
, you can see the view still has a black background because of the default setting of the Android app theme. You need to modify the config to achieve total transparent, which is:
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
Then adding transparent to the launching intent here:
import android.os.Bundle
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.android.FlutterActivityLaunchConfigs.BackgroundMode.transparent
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
override fun onCreate(savedInstanceState: Bundle?) {
intent.putExtra("background_mode", transparent.toString())
super.onCreate(savedInstanceState)
}
}
You can look at a simple example with only a Dialog
display on the screen here: https://github.com/NMateu/flutter_transparent_app
You can look into these projects that implement background running:
This is a good guide on Flutter background service as well
Upvotes: 1