Sender App Example: DragAndSend

 

When the Dual window application sends the object except for text data, the Android permission error can be occurred since SAF (Storage Access Frameworks) of Android KitKat does not recommend it. Therefore, this document does NOT also recommend sending the object except of the text data.
For this reason, sample applications only focus on sending text drag & drop.

Android SAF (Storage Access Framework) on Kitkat
SAF provides the common Documents UI to access content. Android KitKat recommends that the application use this Documents UI for accessing the other application’s content. To implement drag and drop using Documents UI, the application need the permission, android.permission.MANAGE_DOCUMENTS. However, this permission is NOT allowed for third-party applications. Therefore, Dual window applications may not allow you to send some content, such as: images, video, and so on from one app to the other.

 
The sample application consists of the following files:

 

Files

Description

\src\com\lge\example\dragandsend\MainActivity.java

Main activity class

\res\layout\ activity_main.xml

Layout file for the main activity in Full screen

\res\layout\guide.xml

Layout file for the dialog

\res\values\strings.xm

the file including string values

AndroidManifest.xml

manifest file

 

Modifying the AndroidManifest.xml

The manifest file should add the following metadata to enable Dual window.

<application
...
<meta-data android:name="com.lge.support.SPLIT_WINDOW" ①
android:value="true"/>
<activity
android:name="com.lge.example.dragandsend.MainActivity" ②
...
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

① The metadata for application to be executed in Dual window
② If the application has the above metadata, its main/launcher activity can be included in the Dual window App Drawer.

 

Getting Ready

The sample application sets the main layout and retrieves views.

private Context mContext;
private AlertDialog mGuideDialog = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
setContentView(R.layout.activity_main);
mContext = this.getApplicationContext();
...
}

Dealing with Notification on KitKat SAF (Storage Access Framework) for Image

1. Regarding the text data, Android framework supports text drag & drop between applications, so developers do not need to implement it.
2. Regarding the image data, the application shows the notification of SAF (Storage Access Framework) instead of drag & drop.

@Override
protected void onCreate(Bundle savedInstanceState) {
...
Button button = (Button) findViewById(R.id.id_button); ①
button.setOnClickListener(clicklistener);
...
}

private OnClickListener clicklistener = new OnClickListener() {
public void onClick(View v) {
// Show up a noti popup describes Android Storage Access Framework
...
popInitialGuideUp(); ②
}
};
private void popInitialGuideUp() {
final View contents = View.inflate(mContext, R.layout.guide, null); ③
AlertDialog.Builder builder = new
AlertDialog.Builder(MainActivity.this); ④
builder.setTitle(R.string.title_guide)
.setCancelable(false)
.setView(contents)
.setPositiveButton(R.string.confirm_guide,
new DialogInterface.OnClickListener()
{

@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
});

mGuideDialog = builder.create();
mGuideDialog.show();
}

① retrieve the button for image and set the listener
② implement the listener to show AlertDialog when users click the button
③ set the layout for the AlertDialog to show a notification for dealing with object interact exception because of the Android KitKat SAF
④ set properties of AlertDialog.

 

Navigation