我需要创建可以处理从浏览器共享的文件并返回结果文件的应用程序。我可以从链接中检索所需的操作。但我不知道如何获取文件内容。
我已经在AndroidManifest.xml中设置了Intent Filters:
<activity android:name="activity">
<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="app"
android:host="action" />
</intent-filter>
</activity>
我已经在 Activity 中添加了处理代码。
我制作了以下 HTML 原型:
document.getElementById('sendButton').addEventListener('click', function() {
const fileInput = document.getElementById('fileInput');
if (fileInput.files.length > 0) {
const file = fileInput.files[0];
const url = app://action?operation=sign&filename=${encodeURIComponent(file.name)};
window.location.href = url;
} else {
alert('Please select a file first.');
}
});
但这不起作用。当我按下按钮时,没有任何反应(在 logcat 中也没有任何反应)。但是当我使用
adb
检查深层链接时,应用程序会唤醒。
我不完全明白它是否可行,或者是否有其他方法可以完成此任务。从哪里开始调查问题?
在我看来,您只需要从清单文件中导出活动。另外,您不需要指定主机 - 尝试使用路径。
您正在使用私有 URI 方案 URL 链接到应用程序。这些通常还用于在移动应用程序中接收 OAuth 响应。以下是一些可供比较的示例语法:
<activity
android:name=".oauth.LoginRequestResponseActivity"
android:exported="true"
android:launchMode="singleTask"
android:configChanges="orientation|screenSize">
<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="com.example.demoapp" android:path="/callback" />
</intent-filter>
</activity>