การรวมและการทำงานกับ .pkpass pass ในแอป Xamarin Android

ฉันกำลังพัฒนาแอป Xamarin สำหรับ Android และฉันต้องการความสามารถในการทำงานกับ Passes (เช่น PassKit pass (JSON)) ฉันต้องสามารถแสดงรายการบัตรผ่านทั้งหมดใน ListVew และสามารถเปิดและแสดงบัตรผ่านได้ ยังสามารถบันทึกไว้ในกระเป๋าเงินเช่น PassWallet หรือ Pass2u ฉันไม่ต้องการความสามารถในการสร้างมัน แค่ดูมัน และบันทึกมันลงในกระเป๋าเงินหรือทิ้งมันไป

ดูเหมือนจะมีตัวอย่างแอป Xamarin iOS ที่ทำสิ่งที่ฉันต้องการได้ ที่นี่ แต่แน่นอนว่าฉัน จะต้องสามารถทำได้ใน Xamarin Android

ฉันค้นคว้าเรื่องนี้มาหลายชั่วโมงแล้ว แต่ไม่รู้ว่าจะบรรลุสิ่งที่ต้องการได้อย่างไร JSON.net ดูเหมือนจะเป็นวิธีในการอ่านบัตรผ่าน แต่นั่นก็เท่าที่ฉันทำได้ ตัวอย่างบางส่วนจะดีมาก ใครสามารถช่วยได้บ้าง?


person Can'tCodeWon'tCode    schedule 11.08.2014    source แหล่งที่มา


คำตอบ (1)


หากต้องการเพิ่มบัตรผ่านลงใน PassWallet คุณสามารถใช้สิ่งต่อไปนี้:

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 ได้หากคุณมีไฟล์อยู่ในเครื่อง

หากต้องการแสดงในรายการ คุณจะต้องแตกไฟล์ .pkpass แล้วแยกวิเคราะห์ JSON สำหรับฟิลด์ที่เกี่ยวข้อง

person Andy Nugent    schedule 25.09.2014
comment
และคำถาม: จะเพิ่มรายการผ่านได้อย่างไร? ตอนนี้สามารถเพิ่มได้ 1 ใบต่อ 1 ครั้งเท่านั้น - person RoShan Shan; 25.01.2017