Skip to content

Commit

Permalink
Add support for external intent to view directory
Browse files Browse the repository at this point in the history
  • Loading branch information
VishalNehra committed Oct 9, 2017
1 parent 2cce881 commit 2c14ba5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
18 changes: 14 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,39 +57,49 @@
android:launchMode="singleInstance"
android:name=".activities.MainActivity"
android:theme="@style/appCompatLight">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<data android:mimeType="*/*" />
<category android:name="android.intent.category.OPENABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.RINGTONE_PICKER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="application/zip" />
<data android:mimeType="application/rar" />
<data android:mimeType="application/x-rar-compressed"/><!--<category android:name="android.intent.category.OPENABLE" />-->
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
</intent-filter>
<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="com.amaze.filemanager" />
<data android:mimeType="resource/folder" />

This comment has been minimized.

Copy link
@friedger

friedger Oct 9, 2017

Where does this mime type come from?
Wouldn't it be better to use DocumentContracts.Document.MIME_TYPE_DIR?

This comment has been minimized.

This comment has been minimized.

Copy link
@VishalNehra

VishalNehra Oct 9, 2017

Author Member

Indeed, this is a better option I completely overlooked. But many third party apps define resource/folder as their mime type instead (they were probably defined before DocumentsContract came out). Regardless, I'll report this to them here and here

</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="resource/folder" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<intent-filter android:label="@string/intent_save_as">
Expand All @@ -98,8 +108,8 @@
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>

</activity>

<activity
android:uiOptions="splitActionBarWhenNarrow"
android:label="@string/setting"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
import com.amaze.filemanager.fragments.SearchWorkerFragment;
import com.amaze.filemanager.fragments.TabFragment;
import com.amaze.filemanager.fragments.ZipExplorerFragment;
import com.amaze.filemanager.fragments.preference_fragments.PrefFrag;
import com.amaze.filemanager.fragments.preference_fragments.QuickAccessPref;
import com.amaze.filemanager.ui.dialogs.GeneralDialogCreation;
import com.amaze.filemanager.ui.dialogs.RenameBookmark;
Expand Down Expand Up @@ -276,6 +277,12 @@ public class MainActivity extends ThemedActivity implements
public static final String TAG_INTENT_FILTER_GENERAL = "general_communications";
public static final String ARGS_KEY_LOADER = "loader_cloud_args_service";

/**
* Mime type in intent that apps need to pass when trying to open file manager from a specific directory
* Should be clubbed with {@link Intent#ACTION_VIEW} and send in path to open in intent data field
*/
public static final String ARGS_INTENT_ACTION_VIEW_MIME_FOLDER = "resource/folder";

private static final String CLOUD_AUTHENTICATOR_GDRIVE = "android.intent.category.BROWSABLE";
private static final String CLOUD_AUTHENTICATOR_REDIRECT_URI = "com.amaze.filemanager:/oauth2redirect";

Expand Down Expand Up @@ -373,8 +380,25 @@ public void onSearch(String queue) {

// zip viewer intent
Uri uri = intent.getData();
openzip = true;
zippath = uri.toString();
String type = intent.getType();

if (type != null && type.equals(ARGS_INTENT_ACTION_VIEW_MIME_FOLDER)) {
// support for syncting or intents from external apps that
// need to start file manager from a specific path

if (uri != null) {

path = uri.getPath();

This comment has been minimized.

Copy link
@friedger

friedger Oct 9, 2017

the path is probably something like content://... you need to get the absolute path from extras, I'd say.

} else {
// no data field, open home for the tab in later processing
path = null;
}
} else {
// we don't have folder resource mime type set, supposed to be zip/rar
openzip = true;
zippath = uri.toString();
}

} else if (actionIntent.equals(Intent.ACTION_SEND) && typeIntent != null) {
// save a single file to filesystem

Expand Down

1 comment on commit 2c14ba5

@VishalNehra
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #791 and #419

Please sign in to comment.