[英]How to find the file passed to a Delphi app on Android?
我们必须编写一个知道如何打开.xyz文件的Android应用程序。
但是当我们将.xyz文件分配给我们的应用程序时,之后我们在Android的文件资源管理器中点击.xyz文件,应用程序正常启动但程序没有看到文件名作为参数。
编码
ShowMessage(ParamStr(0)); //for debug...
ShowMessage(ParamStr(1));
而不是在消息框中显示应用程序的完整路径,在此之后,轻敲(单击)文件名的完整路径显示两个空字符串。
我们如何获得tapped(clicked)文件的完整路径?
更新:
(一部分)清单看起来像这样:
<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>
您需要调用SharedActivity.getIntent()
来检查您的应用是否是由Intent
启动的。 如果返回非零的Intent
则可以检索其数据(即文件名)并相应地执行操作。 有关示例,请参阅我对以下问题的回答:
在Delphi XE5 Android App中处理自定义URI
https://stackoverflow.com/a/20465775/65863
在Android上,使用Intents和Intent过滤器实现启动活动并从其他应用程序传递文件。 (请参阅允许其他应用程序开始您的活动 )
通常你的应用程序必须实现一个Intent处理程序。 为了确定您的活动中要采取的操作,您可以阅读用于启动它的Intent。
然后可以使用Intent.getData()
检索所选文件的URI
Java示例:
// 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.