[Android Software Development] Geeks Empire:
[IMG="osp"]https://img.xda-cdn.com/8MNv6s7SdaI9j88WeIdsKNpiKik=/https%3A%2F%2F3.bp.blogspot.com%2F-dACv-8g3aM8%2FValm_sjO4EI%2FAAAAAAAACVA%2FEqeU6zuJBos%2Fs640%2FUntitled%252B-%252B3.png[/IMG]​

Split-Screen Or Multi-Window introduced on Android 7 (API 24) for All Android devices.

Samsung added new Software features on Galaxy Note 8 that allows users to select pair of apps to open in simultaneously in split screen. Check it out

But If you want to configure your current app to support multi-window you need to read this documentation.

[YOUTUBE]qbxI95Nl-p0[/YOUTUBE]

[IMG="split"]https://developer.android.com/images/android-7.0/mw-splitscreen.png[/IMG]

# Let Start #​

- Right Click on package name of app & Create a Java Class for AccessibilityService

public class [COLOR="royalblue"]SplitScreenService [/COLOR]extends [B]AccessibilityService [/B]{
@Override
protected void onServiceConnected() {
System.out.println("onServiceConnected");
//system will call this whenever you turn on Accessibility for this app
}
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
switch (event.getEventType()){
case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
//this is a sample event that you can perform some action whenever it called
//and i will create split-screen here
[COLOR="DarkRed"]performGlobalAction(GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN);[/COLOR]
//this is how you can enter split-screen mode
break;
}
}

@Override
public void onInterrupt() {
System.out.println(">>> onInterrupt");
}
@Override
public void onCreate() {
super.onCreate();
System.out.println("onCreate");
}
@Override
public void onDestroy(){
super.onDestroy();
}
}

- Right Click on /res/... folder, create another folder and name it xml then you will have /res/xml/...

Then right click on /xml/... folder and create an xml file and choose a name (split.xml)

This xml file contains configuration of AccessibilityService.

<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="[COLOR="red"]typeAllMask[/COLOR]" // all mask means to get all event which most of time you don't need it.
android:accessibilityFeedbackType="feedbackGeneric"
android:accessibilityFlags="flagRetrieveInteractiveWindows|flagDefault"
android:settingsActivity="com.example.android.globalactionbarservice"
android:description="@string/describe_what_will_you_do" //here you must describe to user what will you do with this special permission />

- Open AndroidManifest.xml to define AccessbilityService & Add required permissions

Inside <application/> tag add this.

<service
android:name="com.example.android.split.SplitScreenService" //change it to your package name and class
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService"/>
</intent-filter>

<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/split"/> //add name of configuration file split.xml
</service>

Note that this app will only work when user enables Accessibility for it manually.

So first thing on Main Activity of the app must be to check this and redirect users to Accessibility Setting.

Open Main Activity of app and [MENTION=530167]onc[/MENTION]reate() add this

final AccessibilityManager accessibilityManager = (AccessibilityManager)getSystemService(ACCESSIBILITY_SERVICE);
if([COLOR="Red"]!accessibilityManager.isEnabled()[/COLOR]){
Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);

finish();
return;
}

after this app should enter split-screen & try to open another apps inside split-screen.

that s why I set BroadcastReceiver to send proper action in right time after entering split-screen mode.

So to perform this app must have proper BroadcastReceiver & AccessibilityEvent listener.

//Custom BroadcastReceiver in activity

@Override
protected void onCreate(Bundle Saved){
super.onCreate(Saved);

final AccessibilityManager accessibilityManager = (AccessibilityManager)getSystemService(ACCESSIBILITY_SERVICE);
if(!accessibilityManager.isEnabled()){
Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);

finish();
return;
}
else {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("[B]open_split[/B]");
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("open_split")){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent spliteOne = [COLOR="seagreen"]getPackageManager().getLaunchIntentForPackage[/COLOR]("com.whatsapp");// change to whatever you want
spliteOne.addCategory(Intent.CATEGORY_LAUNCHER);
spliteOne.setFlags(
Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT |
Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

final Intent spliteTwo = [COLOR="SeaGreen"]getPackageManager().getLaunchIntentForPackage[/COLOR]("com.google.android.youtube");[B]3*[/B]// change to whatever you want
spliteTwo.addCategory(Intent.CATEGORY_LAUNCHER);
spliteTwo.setFlags(
Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | [B]1*[/B]
Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

startActivity(spliteOne);
new Handler().postDelayed(new Runnable() { [B]2*[/B]
@Override
public void run() {
startActivity(spliteTwo);
}
}, 200);
}
}, 500);
}
}
};
registerReceiver(broadcastReceiver, intentFilter);
}
}

1* These are required flags to open an activity inside split-screen If the split screen already available.

.setFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

2* I set some delays for smoother performance of app and system & allow system to completely enter split-screen mode.

3* I set YouTube and WhatsApp for examples. you can set another apps or let users to select from a list. But there might be problem with some apps to enter split-screen mode cause they are not compatible. system will try to force them which is successful most of the time.

//AccessibilityEvent Listener in AccessibilityService

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
switch (event.getEventType()){
case AccessibilityEvent.[B]TYPE_WINDOW_STATE_CHANGED[/B]:
//system will call this event whenever something change open or close
//so app need to identify when to perform action to avoid lots of conflict
//event.getClassName() is name of the class that send this event which is OpenActivities for my app
if(event.getClassName().equals("com.example.android.split.OpenActivities")){
performGlobalAction([COLOR="RoyalBlue"]GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN[/COLOR]);[B]1*[/B]//this is the function to ask system to enter to split-screen
[B]sendBroadcast[/B](new Intent("[B]open_split[/B]"));[B]2*[/B]//to send action after asking system to enter split-screen
}
}
break;
}
}

1* System going to enter Split-Screen mode.

2* App will send action to activity to open other apps with proper Intent.Flags... in split-screen.

Download

Sample Source Code | Sample Apk File (WhatsApp & YouTube)

Oo. Download | Split Shortcuts .oO

Floating Shortcuts | Super Shortcut

Promo Code Available

[IMG="geeks"]https://img.xda-cdn.com/ecTRQ0jFnETW73vt2H-3fQtmFTg=/https%3A%2F%2Flh3.googleusercontent.com%2F5RM5FsviY5rVG2r5NgU1fnvDe5LS0Nd-X8_KBcKZ6GbFxso80uAvEsYBuRxOJzpKlbjMHu8T%3Dw576-h324-p-rw[/IMG]​

Thanks for Support my Projects​

Don't forget to Hit Thanks​