[英]react-native Android Module open PassWallet
I want to save a .pkpass WalletPass in my react-native app. 我想在我的react-native应用程序中保存一个.pkpass WalletPass。 I made a Module with information from this developer guide: http://passwallet.attidomobile.com/PassWallet%20Developer%20Guide.pdf my module looks like the following: 我使用此开发人员指南中的信息制作了一个模块: http : //passwallet.attidomobile.com/PassWallet%20Developer%20Guide.pdf我的模块如下所示:
PassWallet.java: PassWallet.java:
package mypackage;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class PassWallet extends ReactContextBaseJavaModule {
public PassWallet(ReactApplicationContext reactContext) {
super(reactContext);
}
public String getName() {
return "PassWallet";
}
@ReactMethod
public void saveToPassWallet(String url) {
launchPassWallet(getReactApplicationContext().getApplicationContext(), Uri.parse(url), true);
}
private 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 {
final String strEncodedURL = URLEncoder.encode(uri.toString(), "UTF-8");
strReferrer = "&referrer=" + strEncodedURL;
}
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;
}
}
I added the module correctly and can open it in my react-native javascript files: 我正确添加了模块,可以在我的react-native javascript文件中打开它:
const AndroidWalletManager = NativeModules.PassWallet;
...
AndroidWalletManager.saveToPassWallet(url);
...
When I open a .pkpass file and the Wallet App (PassWallet, like the link to the developer guide) is not installed, the Play store opens correctly. 当我打开.pkpass文件并且未安装电子钱包应用程序(PassWallet,如指向开发人员指南的链接)时,Play商店会正确打开。 But when the app is installed the following error is shown: 但是,在安装应用程序后,将显示以下错误:
I'm not a android developer so maybe this is a basic problem, but I don't know how to solve this. 我不是android开发人员,所以也许这是一个基本问题,但我不知道如何解决。 If I had to guess I would say the PassWallet App changed the activity name, is this correct? 如果我不得不猜测我会说PassWallet App更改了活动名称,这是正确的吗? I had this solution for like two years and it worked in the past. 我有两年左右的解决方案,并且在过去一直有效。 I contacted the author of this developer guide but didn't get a response so far. 我联系了该开发人员指南的作者,但到目前为止没有得到答复。 Is there a better way to do this? 有一个更好的方法吗?
I just want to be able to save a .pkpass directly to a Wallet App on android. 我只希望能够将.pkpass直接保存到android上的电子钱包应用中。
The activity name was changed after a major release 2.00.XX Please find the latest instructions here: https://github.com/Kwiket/passwallet 在主要版本2.00.XX之后更改了活动名称。请在此处找到最新说明: https : //github.com/Kwiket/passwallet
Passwallet Team 通行证团队
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.