在Android中注册新文件类型 [英] Register a new file type in Android
问题描述
我想在Android上编写一个简单的STL(几何数据文件)查看器应用程序,但无法识别系统的格式.我在应用清单文件中写了这个:
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>
但是当我启动浏览器并下载一些示例STL文件时,下载被中断,并且我报告系统的数据文件类型未知.
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.
我没有真正的Android设备,所以我只使用一个仿真器,并且为了开发我在MonoDroid上使用C#(但老实说我不认为这是问题所在).
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).
我该如何解决此问题?
推荐答案
我正在使用此清单在我的应用程序中注册(例如).stl文件类型:
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>
如您所见,我将.stl文件扩展名链接到活动OdinActivity
.在OdinActivity
内,我使用以下行获取文件路径,以便可以打开它:
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));
这篇关于在Android中注册新文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!