Pkpass在AndroidPkpass、Android

2023-09-05 00:57:53 作者:甜言丶幂语

有一个Android应用程序,Passwallet,即能intented为苹果App存折( https://play.google.com/store/apps/details?id=com.attidomobile.passwallet )

我不知道怎么读pkpass文件。

Pkpass文件似乎与所有的JSON文件的内幕信息的zip文件。是否有一个默认的结构,为pkpass文件?如果是的话是什么呢?什么是导入到Android应用程序的好方法?

有关谁不知道如何读的pkpass文件的内容请参考以下code的人:

我成立了这个活动的意图过滤器pkpass文件

 <意向滤光器>
            <作用机器人:名称=android.intent.action.VIEW/>

            <类机器人:名称=android.intent.category.DEFAULT/>

            <数据
                机器人:MIMETYPE =应用/越南盾,com.apple.pkpass
                机器人:计划=内容/>
        &所述; /意图滤光器>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.VIEW/>

            <类机器人:名称=android.intent.category.DEFAULT/>

            <数据
                机器人:MIMETYPE =应用/ vnd.apple.pkpass
                机器人:计划=内容/>
        &所述; /意图滤光器>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.VIEW/>

            <类机器人:名称=android.intent.category.DEFAULT/>

            <数据
                机器人:MIMETYPE =应用/越南盾,com.apple.pkpass
                机器人:计划=文件/>
        &所述; /意图滤光器>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.VIEW/>

            <类机器人:名称=android.intent.category.DEFAULT/>

            <数据
                机器人:MIMETYPE =应用/ vnd.apple.pkpass
                机器人:计划=文件/>
        &所述; /意图滤光器>
 

  @覆盖
保护无效的onCreate(包savedInstanceState){

super.onCreate(savedInstanceState);
意向意图= getIntent();
开放的我们的uri = intent.getData();
字符串模式= uri.getScheme();

如果(ContentResolver.SCHEME_CONTENT.equals(方案)){
    尝试 {
        InputStream的附着= getContentResolver()openInputStream(URI)。
        handleZipInput(挂职);
    }赶上(FileNotFoundException异常E){
        e.printStackTrace();
    }
}
其他 {
    字符串路径= uri.getEn codeDPATH();
    尝试 {
        的FileInputStream FIS =新的FileInputStream(路径);
        handleZipInput(FIS);
    }赶上(FileNotFoundException异常E){
        e.printStackTrace();
    }
}
}

私人无效handleZipInput(InputStream中的){
    尝试 {
        ZipInputStream ZIS =新ZipInputStream(中);
        ZipEntry的进入;
        而((进入= zis.getNextEntry())!= NULL){
            字符串文件名= entry.getName();
            如果(filename.equals(pass.json)){
                StringBuilder的S =新的StringBuilder();
                INT读= 0;
                byte []的缓冲区=新的字节[1024];
                而((读取= zis.read(缓冲液,0,1024))> = 0)
                    s.append(新的String(缓冲,0,读));

                JSONObject的通=新的JSONObject(s.toString());
                打破;
            }
        }
    }赶上(例外五){
        e.printStackTrace();
    }
}
 
PassFab Android Unlocker破解版下载 PassFab Android Unlocker v2.0.1.1 绿色中文版下载 9553下载

解决方案

您可以下载完整的规范,从here.该过程的内容存储在一个名为pass.json一个JSON文件。该.pkpass包是包含pass.json,传图片,可选的区域设置文件和清单文件的zip文件。

该清单必须签署与苹果发出的通行证身份证件。然而,对于Android或建立通所需的任何其他第三方应用程序,都可以从pass.json和捆绑的图像读取。

There is an android app, Passwallet, that is able to interpret pkpass files intented for the apple app Passbook (https://play.google.com/store/apps/details?id=com.attidomobile.passwallet)

I was wondering how to read pkpass files.

Pkpass files seem to be zip files with all the information inside in json files. Is there a default structure for the pkpass files? If so what is it? And what would be a good way to import that into a android app?

For the people who wonder how read the content of the pkpass file refer to the following code:

I set up this activity with the intent filter for pkpass files

        <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();
    }
}

解决方案

You can download the full specification for the .pkpass bundle from here. The pass content is stored in a JSON file named pass.json. The .pkpass bundle is a zip file containing pass.json, the pass images, optional locale files and a manifest file.

The manifest needs to be signed with an Apple issued Pass ID certificate. However for Android, or any other third party App, everything required to build the pass can be read from pass.json and the bundled images.