Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detecing file extension when receiving a binary file type #52

Open
realcr opened this issue Apr 25, 2020 · 0 comments
Open

Detecing file extension when receiving a binary file type #52

realcr opened this issue Apr 25, 2020 · 0 comments

Comments

@realcr
Copy link

realcr commented Apr 25, 2020

Hey, thank you for the work receive_sharing_intent! I am trying to use the "receive any file type" feature (Mentioned in issue #13) , but I am hitting some problems. It is possible that I do not use it correctly.

I am trying to have my application accept binary files with the ".invoice" extension, for example. It seems like I am able now to accept files, but I can not identify the *.invoice extension. This is an issue for me, because I also handle other incoming files with different extensions, like *.index and
*.relay, and I am left with no ability to distinguish between different file types.

Below you can see the relevant simplified dart code example. The AndroidManifest.xml file is also included below.

Dart code snippet:

    _streamSubs
        .add(ReceiveSharingIntent.getMediaStream().listen((List<SharedMediaFile> sharedMediaFiles) {
      /* ... Some checks here ... */

      // We received exactly one filePath:
      logger.w(
        'fileType = ${sharedMediaFiles[0].type}');
      logger.w(
        'filePath = ${sharedMediaFiles[0].path}');

    }, onError: (err) {
        /* .. error handling ... */
    }));

Output:

I/flutter (11804): ⚠️  main - fileType = SharedMediaType.FILE
I/flutter (11804): ⚠️  main - filePath = /data/user/0/org.freedomlayer.offset/cache/VID_1587811736322.bin

I was expecting to be able to deduce from either fileType or filePath the original shared file extension, but it seems like I can't identify the file extension. Is this something this receive_sharing_intent plans on supporting?

Contents of androidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.freedomlayer.offset">
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->

    <uses-permission android:name="android.permission.INTERNET"/>
    <!-- When we used launchMode="singleTop", a new application instance was created when a file was shared with the application.
    Using launchMode="singleTask" instead seems to solve this issue -->
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="Offset"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTask"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <!-- Handle file sharing intents -->
            <!-- See also: https://stackoverflow.com/questions/1733195/android-intent-filter-for-a-particular-file-extension -->
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="*/*" />
                <data android:pathPattern=".*\\.(invoice|receipt|commit|friend|relay|index|rcard)" />
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

Possibly also related to issue: #51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant