注册在Android的新的文件类型 [英] Register new file type in Android
问题描述
我想编写简单的STL(几何数据文件)在Android浏览器的应用程序,但我无法使识别的格式到系统中。我在我的应用程序清单文件中写道的:
I want to write simple STL (geometrical data file) viewer application on Android, but I'm not able to make recognize a format to the system. What I wrote in my app manifest file is:
<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文件,下载中断,我报告说,数据文件类型是未知的系统。 我没有真正的Android设备,所以只能使用模拟器,以及发展中,我使用C#的MonoDroid(但我不认为这是问题,老老实实)
But at the moment I launch browser and go to download some sample STL file, download is interrupted and I'm reported that the data file type is unknown for the system. I have no real android device, so use only emulator, and for development I use C# on MonoDroid (but I don't think that is the problem honestly)
在受任何想法?
感谢你在前进。
推荐答案
我用这个清单进行注册(例如)·STL文件,我的应用程序类型:
I'm using this Manifest to register (for example) .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屋!