Tig*_*ran 21 android file-type
我想在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>
Run Code Online (Sandbox Code Playgroud)
但是目前我启动浏览器并下载一些示例STL文件,下载中断,我报告系统的数据文件类型未知.我没有真正的Android设备,所以只使用模拟器,为了开发我在MonoDroid上使用C#(但我不认为这是老实说的问题)
关于主题的任何想法?
先感谢您.
gnc*_*ais 23
我正在使用此Manifest来注册(例如).stl文件类型与我的应用程序:
<?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>
Run Code Online (Sandbox Code Playgroud)
如您所见,我将.stl文件扩展名链接到活动OdinActivity
.在里面OdinActivity
,我使用以下行来获取文件路径,以便我可以打开它:
filePath = getIntent().getData().getEncodedPath();
Run Code Online (Sandbox Code Playgroud)
然后我打开它阅读它:
FileOutputStream out = new FileOutputStream(new File(filePath));
Run Code Online (Sandbox Code Playgroud)
我很惊讶gnclmorais解决方案应该有效.因为它data
在一个中有多个条目intent-filter
对我不起作用.到底有什么工作是多方面intent-filter
的activity
:
<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>
Run Code Online (Sandbox Code Playgroud)
请注意,同时具有两个pathPattern
和mimeType
一个data
条目也不起作用.最后,我建议在获取文件名时进行一些空检查:
/**
* <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
Run Code Online (Sandbox Code Playgroud)
样本中缺少文件的实际加载.它应该在"打开文件"日志命令之后插入.
我尝试了其他解决方案,这是唯一适合我的解决方案:
<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>
Run Code Online (Sandbox Code Playgroud)
有人知道为什么其他的不起作用?
归档时间: |
|
查看次数: |
23893 次 |
最近记录: |