在 Xamarin Android 应用程序中集成和使用 .pkpass pass [英] Integrating and working with .pkpass passes in Xamarin Android app

查看:25
本文介绍了在 Xamarin Android 应用程序中集成和使用 .pkpass pass的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Xamarin Android 应用程序,我需要能够使用 Passes(例如 PassKit 传递 (JSON)).我需要能够在 ListVew 中列出所有通行证并能够打开和显示通行证.也可以将它们保存到 PassWallet 或 Pass2u 等钱包中.我不需要创建它们的能力,只需查看它们,并将它们保存到钱包或丢弃它们.

I'm developing a Xamarin Android app and I need the ability to be able to work with Passes (PassKit passes for example (JSON)). I need to be able to list all the passes in a ListVew and be able to open and display the pass. Also be able to save them to a wallet such as PassWallet or Pass2u. I don't need the ability to create them, just view them, and save them to a wallet or discard them.

似乎有一个 Xamarin iOS 应用程序示例,它完全满足我的需求这里但是当然,我需要能够在 Xamarin Android 中做到这一点.

There seems to be an example Xamarin iOS app which does exactly what i need here but of course I need to be able to do this in Xamarin Android.

我已经研究了几个小时,但不知道如何实现我的需求.JSON.net 似乎是阅读通行证的方法,但这是我设法获得的.一些例子会很棒.有人可以帮忙吗?

I've been researching this for hours but don't know how to achieve what i need. JSON.net seems the way to go to read the passes, but that's as far as I've managed to get. Some examples would be great. Can anybody help?

推荐答案

要将通行证添加到 PassWallet,您可以使用以下命令:

To add the pass into PassWallet you can use the following:

private static boolean launchPassWallet(Context applicationContext, Uri uri, boolean launchGooglePlay) {
    if (null != applicationContext) {
        PackageManager packageManager = applicationContext.getPackageManager();
        if (null != packageManager) {
            final String strPackageName = "com.attidomobile.passwallet";
            Intent startIntent = new Intent();
            startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startIntent.setAction(Intent.ACTION_VIEW);
            Intent passWalletLaunchIntent = packageManager
                    .getLaunchIntentForPackage(strPackageName);
            if (null == passWalletLaunchIntent) {
                // PassWallet isn't installed, open Google Play:
                if (launchGooglePlay) {

                    String strReferrer = "";

                    try {
                        strReferrer = "&referrer=" + URLEncoder.encode(uri.toString(), "UTF-8");
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                        strReferrer = "";
                    }

                    try {
                        startIntent.setData(Uri.parse("market://details?id=" + strPackageName + strReferrer));
                        applicationContext.startActivity(startIntent);
                    } catch (android.content.ActivityNotFoundException anfe) {
                        // Google Play not installed, open via website
                        startIntent.setData(Uri.parse("http://play.google.com/store/apps/details?id=" + strPackageName + strReferrer));
                        applicationContext.startActivity(startIntent);
                    }
                }
            } else {

                final String strClassName = "com.attidomobile.passwallet.activity.TicketDetailActivity";
                startIntent.setClassName(strPackageName, strClassName);
                startIntent.addCategory(Intent.CATEGORY_BROWSABLE);
                startIntent.setDataAndType(uri, "application/vnd.apple.pkpass");

                applicationContext.startActivity(startIntent);

                return true;
            }
        }
    }
    return false;
}

一个示例调用是:

launchPassWallet(getApplicationContext(),Uri.parse("http://test.attidomobile.com/PassWallet/Passes/AttidoMobile.pkpass"), true); 

如果您在本地拥有该文件,也可以使用 file://URL.

You can also use a file:// URL if you have the file locally.

要在列表中显示它们,您需要解压缩 .pkpass 文件,然后解析相关字段的 JSON.

To display them in the list, you'd need to unzip the .pkpass file and then parse the JSON for the relevant fields.

这篇关于在 Xamarin Android 应用程序中集成和使用 .pkpass pass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆