在Android中注册新文件types

我想在Android上编写简单的STL(几何数据文件)查看器应用程序,但是我无法识别系统的格式。 我在我的应用清单文件中写的是:

<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文件,下载被中断,我被报告的数据文件types是未知的系统。 我没有真正的Android设备,所以只使用模拟器,并为开发我在MonoDroid上使用C#(但我不认为这是真正的问题)

任何主题的想法?

先谢谢你。

我使用这个Manifest来注册(例如).stl文件types与我的应用程序:

 <?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内部,我使用下面这行来获取文件path,以便我可以打开它:

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

然后我打开它来读取它:

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

我很惊讶,gnclmorais解决scheme应该工作。 因为它有一个intent-filter中的多个data条目不适合我。 最后的工作是在一个activity进行多个intent-filter

 <activity android:description='@string/Activity_Description' android:icon='@drawable/ic_launcher' android:label='@string/Activity_Name' android:name='net.sourceforge.uiq3.fx603p.Calculator_Activity' > <intent-filter> <action android:name='android.intent.action.MAIN' ></action> <category android:name='android.intent.category.LAUNCHER' ></category> </intent-filter> <intent-filter android:icon='@drawable/ic_fx_603p_pf' android:label='FX-603P Simulator Program' android:priority='1' > <category android:name='android.intent.category.DEFAULT' ></category> <action android:name='android.intent.action.VIEW' ></action> <data android:host='*' android:pathPattern='.*\\.pf' android:scheme='file' ></data> </intent-filter> <intent-filter android:icon='@drawable/ic_fx_603p_df' android:label='FX-603P Simulator Datafile' android:priority='1' > <category android:name='android.intent.category.DEFAULT' ></category> <action android:name='android.intent.action.VIEW' ></action> <data android:host='*' android:pathPattern='.*\\.df' android:scheme='file' ></data> </intent-filter> <intent-filter android:icon='@drawable/ic_fx_603p_af' android:label='FX-603P Simulator Allfile (Data and Program)' android:priority='1' > <category android:name='android.intent.category.DEFAULT' ></category> <action android:name='android.intent.action.VIEW' ></action> <data android:host='*' android:pathPattern='.*\\.af' android:scheme='file' ></data> </intent-filter> <intent-filter android:icon='@drawable/ic_fx_603p_pf' android:label='FX-603P Simulator Program' android:priority='1' > <category android:name='android.intent.category.DEFAULT' ></category> <action android:name='android.intent.action.VIEW' ></action> <data android:host='*' android:mimeType='application/x-fx-602p.program' ></data> </intent-filter> <intent-filter android:icon='@drawable/ic_fx_603p_df' android:label='FX-603P Simulator Datafile' android:priority='1' > <category android:name='android.intent.category.DEFAULT' ></category> <action android:name='android.intent.action.VIEW' ></action> <data android:host='*' android:mimeType='application/x-fx-602p.data' ></data> </intent-filter> <intent-filter android:icon='@drawable/ic_fx_603p_af' android:label='FX-603P Simulator Allfile (Data and Program)' android:priority='1' > <category android:name='android.intent.category.DEFAULT' ></category> <action android:name='android.intent.action.VIEW' ></action> <data android:host='*' android:mimeType='application/x-fx-602p.all' ></data> </intent-filter> </activity> 

请注意,同时在一个data条目中同时使用pathPatternmimeType也不行。 最后不是最不重要的,我会build议在获取文件名时进行一些空的检查:

  /** * <p>Open calculator and load file (if one was passed).</p> * @see android.app.Activity#onStart() */ @Override public void onStart () { android.util.Log.d (Calculator_Activity.TAG, "+ onStart"); super.onStart (); final android.content.Intent intent = getIntent (); if (intent != null) { android.util.Log.d (Calculator_Activity.TAG, "> Got intent : " + intent); final android.net.Uri data = intent.getData (); if (data != null) { android.util.Log.d (Calculator_Activity.TAG, "> Got data : " + data); final String filePath = data.getEncodedPath (); android.util.Log.d (Calculator_Activity.TAG, "> Open file : " + filePath); // file loading comes here. } // if } // if android.util.Log.d (Calculator_Activity.TAG, "- onStart"); return; } // onStart 

示例中缺less文件的实际加载。 它应该在“打开文件”日志命令之后插入。

我尝试了其他解决scheme,这是唯一适用于我的解决scheme:

  <intent-filter android:icon="@drawable/icon" android:label="Armro File" android:priority="1" > <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" /> <data android:scheme="https" /> <data android:scheme="ftp" /> <data android:scheme="file" /> <data android:host="*" /> <data android:mimeType="*/*" /> <data android:pathPattern=".*\\.myowntype" /> </intent-filter> 

有人有一个想法,为什么其他人不工作?