Integrating and working with .pkpass passes in Xamarin Android app

丶灬走出姿态 提交于 2019-12-08 13:45:29

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

And an example call is:

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

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!