-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
203 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 26 | ||
buildToolsVersion "26.0.1" | ||
|
||
defaultConfig { | ||
minSdkVersion 21 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
} | ||
|
||
dependencies { | ||
provided 'com.facebook.react:react-native:+' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.mybdesign.RNPassKit"> | ||
</manifest> |
69 changes: 69 additions & 0 deletions
69
android/src/main/java/com/mybdesign/RNPassKit/RNPassKitModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.mybdesign.RNPassKit; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.support.v4.content.FileProvider; | ||
import android.util.Base64; | ||
|
||
import com.facebook.react.bridge.JSApplicationCausedNativeException; | ||
import com.facebook.react.bridge.Promise; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.util.UUID; | ||
|
||
public class RNPassKitModule extends ReactContextBaseJavaModule { | ||
private final String FILE_PROVIDER = "com.mybdesign.RNPassKit.fileprovider"; | ||
private final String PKPASS_TYPE = "application/vnd.apple.pkpass"; | ||
|
||
public RNPassKitModule(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "RNPassKit"; | ||
} | ||
|
||
private Intent intentWithContentUri(Uri uri, String type) { | ||
return new Intent(Intent.ACTION_VIEW) | ||
.setDataAndType(uri, type) | ||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | ||
} | ||
|
||
@ReactMethod | ||
public void canAddPasses(Promise promise) { | ||
try { | ||
Intent intent = this.intentWithContentUri(Uri.parse("content://"), PKPASS_TYPE); | ||
boolean canAddPass = intent.resolveActivity(getReactApplicationContext().getPackageManager()) != null; | ||
promise.resolve(canAddPass); | ||
} catch (Exception e) { | ||
promise.reject(new JSApplicationCausedNativeException(e.getMessage())); | ||
} | ||
} | ||
|
||
@ReactMethod | ||
public void addPass(String base64Encoded, Promise promise) { | ||
try { | ||
Context context = getReactApplicationContext(); | ||
|
||
File file = new File(context.getCacheDir(), UUID.randomUUID().toString() + ".pkpass"); | ||
FileOutputStream stream = new FileOutputStream(file, true); | ||
stream.write(Base64.decode(base64Encoded, 0)); | ||
stream.flush(); | ||
stream.close(); | ||
|
||
Uri uri = FileProvider.getUriForFile(context, FILE_PROVIDER, file); | ||
Intent intent = this.intentWithContentUri(uri, PKPASS_TYPE); | ||
context.startActivity(intent); | ||
promise.resolve(null); | ||
} catch (Exception e) { | ||
promise.reject(new JSApplicationCausedNativeException(e.getMessage())); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
android/src/main/java/com/mybdesign/RNPassKit/RNPassKitPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.mybdesign.RNPassKit; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class RNPassKitPackage implements ReactPackage { | ||
@Override | ||
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { | ||
List<NativeModule> modules = new ArrayList<>(); | ||
|
||
modules.add(new RNPassKitModule(reactContext)); | ||
|
||
return modules; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "react-native-passkit-wallet", | ||
"version": "0.0.3", | ||
"description": "React Native module to handle PassKit.", | ||
"version": "0.1.0", | ||
"description": "React Native module to handle PassKit pass.", | ||
"main": "index", | ||
"scripts": { | ||
"lint": "eslint .", | ||
|
@@ -14,7 +14,8 @@ | |
}, | ||
"keywords": [ | ||
"react-native", | ||
"ios" | ||
"ios", | ||
"android" | ||
], | ||
"author": "Masayuki Iwai <[email protected]> (http://mybdesign.com/)", | ||
"license": "MIT", | ||
|