Skip to content

Commit

Permalink
improve intent-filter support for absolute directory paths
Browse files Browse the repository at this point in the history
  • Loading branch information
warren-bank committed Mar 24, 2020
1 parent c1e3c4c commit 6d573b9
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>

<!-- DIRECTORY INDEX playlist -->

<data android:scheme=""/>
<data android:scheme="file"/>
<data android:mimeType="application/octet-stream"/> <!-- Total Commander: "Open with.." -->
<data android:mimeType="resource/folder"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>

<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>

<data android:scheme=""/>
<data android:scheme="file"/>
<data android:host="*"/>
Expand All @@ -193,6 +206,16 @@

<data android:pathPattern=".*/"/>
</intent-filter>
<intent-filter android:label="Play with ExoAirPlayer">
<action android:name="android.intent.action.SEND"/>

<category android:name="android.intent.category.DEFAULT"/>

<!-- DIRECTORY INDEX playlist -->

<data android:mimeType="application/octet-stream"/> <!-- Total Commander: "Send to.." -->
<data android:mimeType="resource/folder"/>
</intent-filter>
</activity>

</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.github.warren_bank.exoplayer_airplay_receiver.service.NetworkingService;
import com.github.warren_bank.exoplayer_airplay_receiver.utils.NetworkUtils;

import java.io.File;

public class StartNetworkingServiceActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -33,11 +35,79 @@ private void startListenService() {
}

private void forwardMedia(Intent intent) {
Uri data = getIntent().getData();
String action = getIntent().getAction();
Uri data = null;
String type;

if (action == null) return;

try {
switch(action) {
case Intent.ACTION_VIEW : {
data = getIntent().getData();
type = getIntent().getType();

if (type != null) {
type = type.toLowerCase();

switch(type) {
case "application/octet-stream" :
case "resource/folder" : {
data = filterDirectory(data);
break;
}
}
}
break;
}
case Intent.ACTION_SEND : {
data = (Uri) getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
data = filterDirectory(data);
break;
}
}
}
catch(Exception e) {
data = null;
}

if (data != null) {
intent.setAction(NetworkingService.ACTION_PLAY);
intent.setData(data);
}
}

private Uri filterDirectory(Uri data) {
Uri filtered = data;
String scheme, path, uri;
File file;

try {
if (data == null)
throw new Exception();

scheme = data.getScheme();
if (scheme == null)
throw new Exception();
if (!scheme.toLowerCase().equals("file"))
throw new Exception();

path = data.getPath();
file = new File(path);
if (!file.isDirectory())
throw new Exception();

// normalize uri, such that directory path always ends with '/' separator
uri = data.toString();
if (uri.charAt(uri.length() - 1) != '/') {
uri += "/";
filtered = Uri.parse(uri);
}
}
catch (Exception e) {
filtered = null;
}

return filtered;
}
}
4 changes: 2 additions & 2 deletions android-studio-project/constants.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project.ext {
releaseVersionCode = Integer.parseInt("001002016", 10)
releaseVersion = '001.00.20-16API'
releaseVersionCode = Integer.parseInt("001002116", 10)
releaseVersion = '001.00.21-16API'
minSdkVersion = 16
targetSdkVersion = 28
compileSdkVersion = 28
Expand Down

0 comments on commit 6d573b9

Please sign in to comment.