2014-10-27 67 views
1

我们必须编写一个知道如何打开.xyz文件的Android应用程序。如何找到传递给Android上的Delphi应用程序的文件?

但是,当我们将.xyz文件分配给我们的应用程序时,之后我们点击Android文件资源管理器中的.xyz文件,应用程序已正确启动,但程序没有看到文件名作为参数。

代码

ShowMessage(ParamStr(0)); //for debug... 
    ShowMessage(ParamStr(1)); 

而是在消息框中显示应用程序的完整路径的完整路径,并在此之后,轻触(点击)文件名就显示了两个空字符串。

我们如何获得点击(点击)文件的完整路径?

UPDATE:

(的一部分)的清单如下:

<activity android:name="com.embarcadero.firemonkey.FMXNativeActivity" 
      android:label="MMBook" 
      android:configChanges="orientation|keyboardHidden"> 
     <!-- Tell NativeActivity the name of our .so --> 
     <meta-data android:name="android.app.lib_name" 
      android:value="MMBook" /> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     <intent-filter> 
      <action android:name="android.intent.action.VIEW" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <data android:scheme="file" android:host="*" android:pathPattern=".*\\.mma" android:mimeType="*/*" /> 
     </intent-filter> 
    </activity> 

回答

1

在Android,启动一个活动,并从不同的应用程序传递一个文件与意图和实现意图过滤器。 (见Allowing Other Apps to Start Your Activity

所以通常你的应用必须实现一个Intent处理程序。为了决定在您的活动中采取何种行动,您可以阅读用于启动它的Intent。

选定的文件,然后可以用Intent.getData()

Java示例检索的URI:

// Get the intent that started this activity 
Intent intent = getIntent(); 
Uri data = intent.getData(); 

// Figure out what to do based on the intent type 
if (intent.getType().indexOf("image/") != -1) { 
    // Handle intents with image data ... 
} else if (intent.getType().equals("text/plain")) { 
    // Handle intents with text ... 
} 

参见:http://codeverge.com/embarcadero.delphi.firemonkey/android-intent-filter-associate/1057456

+0

不要忘记检查,如果'getIntent()'返回'nil'指针,表示该应用程序是正常启动。此外,这个答案不是用Delphi编写的(这个片段不是用Delphi语法编写的,也没有显示如何在Delphi中调用'getIntent()')。 – 2014-10-27 19:22:05

相关问题