gpt4 book ai didi

android - Android 上的 Pkpass

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:36:21 27 4
gpt4 key购买 nike

有一个 Android 应用程序 Passwallet,它能够解释用于苹果应用程序 Passbook (https://play.google.com/store/apps/details?id=com.attidomobile.passwallet) 的 pkpass 文件

我想知道如何读取 pkpass 文件。

Pkpass 文件似乎是 json 文件中包含所有信息的 zip 文件。 pkpass 文件是否有默认结构?如果有,那是什么?将其导入 Android 应用程序的好方法是什么?


想知道如何读取pkpass文件内容的 friend 请引用以下代码:

我使用 pkpass 文件的 Intent 过滤器设置了这个 Activity

        <intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />

<data
android:mimeType="application/vnd-com.apple.pkpass"
android:scheme="content" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />

<data
android:mimeType="application/vnd.apple.pkpass"
android:scheme="content" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />

<data
android:mimeType="application/vnd-com.apple.pkpass"
android:scheme="file" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />

<data
android:mimeType="application/vnd.apple.pkpass"
android:scheme="file" />
</intent-filter>

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
Intent intent = getIntent();
Uri uri = intent.getData();
String scheme = uri.getScheme();

if(ContentResolver.SCHEME_CONTENT.equals(scheme)) {
try {
InputStream attachment = getContentResolver().openInputStream(uri);
handleZipInput(attachment);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
else {
String path = uri.getEncodedPath();
try {
FileInputStream fis = new FileInputStream(path);
handleZipInput(fis);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}

private void handleZipInput(InputStream in) {
try {
ZipInputStream zis = new ZipInputStream(in);
ZipEntry entry;
while((entry = zis.getNextEntry()) != null) {
String filename = entry.getName();
if(filename.equals("pass.json")) {
StringBuilder s = new StringBuilder();
int read = 0;
byte[] buffer = new byte[1024];
while((read = zis.read(buffer, 0, 1024)) >= 0)
s.append(new String(buffer, 0, read));

JSONObject pass = new JSONObject(s.toString());
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

最佳答案

您可以从 here 下载 .pkpass 包的完整规范。 .传递内容存储在名为 pass.json 的 JSON 文件中。 .pkpass 包是一个 zip 文件,其中包含 pass.json、传递图像、可选的语言环境文件和 list 文件。

list 需要使用 Apple 颁发的 Pass ID 证书进行签名。然而,对于 Android 或任何其他第三方应用程序,构建通行证所需的一切都可以从 pass.json 和 bundle 的图像中读取。

关于android - Android 上的 Pkpass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14559959/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com