有一个安卓应用程序Passwallet可以解释苹果应用程序Passbook (https://play.google.com/store/apps/details?id=com.attidomobile.passwallet)的pkpass文件
我在想怎么读pkpass文件。
Pkpass文件似乎是压缩文件,其中包含json文件中的所有信息。pkpass文件有默认结构吗?如果是这样,那又是什么呢?将其导入android应用程序的好方法是什么?
对于那些想知道如何读取pkpass文件内容的人,请参考以下代码:
我使用pkpass文件的意图筛选器设置了此活动。
<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();
}
}
发布于 2013-01-28 02:48:09
您可以从.pkpass下载这里包的完整规范。pass内容存储在一个名为pass.json的JSON文件中。.pkpass包是一个包含pass.json、pass图像、可选地区文件和清单文件的压缩文件。
清单需要用苹果颁发的通行证ID证书进行签名。然而,对于Android或任何其他第三方应用程序,构建pass所需的一切都可以从pass.json和捆绑的图像中读取。
https://stackoverflow.com/questions/14559959
复制相似问题