Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

launch two apps, Android nougat

Tags:

java

android

I want to create an app for android nougat, when I click on a button I launch two apps at the same moment and the same screen. I want to use this new feature of Android 7, Is it possible?

like image 532
Hassine Othmane Avatar asked Oct 30 '22 11:10

Hassine Othmane


1 Answers

You can use Accessibility API for such feature. It doesn't require any permissions.

android.accessibilityservice.AccessibilityService has following apis:

service.performGlobalAction(GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN) which you can use to initiate split screen mode.

public List<AccessibilityWindowInfo> getWindows () to check wether split screen mode is on. Look for a window with AccessibilityWindowInfo.TYPE_SPLIT_SCREEN_DIVIDER

You also will need to play with intent flags when launching activities.

 val options = ActivityOptionsCompat.makeBasic().toBundle()?.apply {
     putInt(
         ActivityOptionsFlags.KEY_LAUNCH_WINDOWING_MODE,
         ActivityOptionsFlags.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY
     )
     putInt(
         ActivityOptionsFlags.KEY_SPLIT_SCREEN_CREATE_MODE,
         ActivityOptionsFlags.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT
     )
 }

 startActivities(listOf(intentBottom, intentTop).toTypedArray(), options)

Using this accessibility apis and intent flags you can achieve your goal. Consult this repo by stavangr for detailed implementation.

https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.html

like image 188
Maksim Turaev Avatar answered Nov 15 '22 05:11

Maksim Turaev