Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
71 views
in Technique[技术] by (71.8m points)

Register a new file type in Android

I want to write a simple STL (geometrical data file) viewer application on Android, but I'm not able to make recognize a format to the system. I wrote this in my app manifest file:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <action android:name="android.intent.action.EDIT" />
    <action android:name="android.intent.action.PICK" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="http" />
    <data android:pathPattern=".*\.stl" />
    <data android:mimeType="application/sla" />
    <data android:host="*" />
</intent-filter>

But the moment I launch the browser and go to download some sample STL file, the download is interrupted and I'm reported that the data file type is unknown for the system.

I have no real Android device, so I use only an emulator, and for development I use C# on MonoDroid (but I honestly don't think that is the problem).

How could I fix this problem?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm using this manifest to register (for example) a .stl file type with my application:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.test.core" android:versionCode="1" android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Testy" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name="ThorActivity" android:label="@string/app_name">
        </activity>

        <activity android:name="LokiActivity" android:label="@string/app_name">
        </activity>

        <activity android:name="OdinActivity" android:label="@string/app_name">
            <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="http" android:host="*"
                    android:pathPattern=".*\.stl" />
                <data android:scheme="https" android:host="*"
                    android:pathPattern=".*\.stl" />
                <data android:scheme="content" android:host="*"
                    android:pathPattern=".*\.stl" />
                <data android:scheme="file" android:host="*"
                    android:pathPattern=".*\.stl" />
            </intent-filter>
        </activity>
    </application>

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

</manifest>

As you can see, I'm linking the .stl file extension to the activity OdinActivity. Inside the OdinActivity, I use the following line to get the file path so I can open it:

filePath = getIntent().getData().getEncodedPath();

Then I just open it to read from it:

FileOutputStream out = new FileOutputStream(new File(filePath));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...