mirror of
https://github.com/wanxf-shuto/CordovaReadApplicationSignature.git
synced 2026-06-05 00:00:35 +08:00
+1
-1
@@ -11,7 +11,7 @@
|
||||
</feature>
|
||||
</config-file>
|
||||
<config-file parent="/*" target="AndroidManifest.xml" />
|
||||
<source-file src="src/android/ReadAppSignature.java" target-dir="src/cordova/plugin/appSignature/ReadAppSignature" />
|
||||
<source-file src="src/android/ReadAppSignature.java" target-dir="src/cordova/plugin/appSignature" />
|
||||
</platform>
|
||||
</plugin>
|
||||
|
||||
|
||||
@@ -23,11 +23,11 @@ You can read more about it on [Android official website](https://source.android.
|
||||
|
||||
```javascript
|
||||
|
||||
cordova.exec(function success(signature){
|
||||
//Check signature
|
||||
}, function failure(error){
|
||||
//alert("Something went wrong");
|
||||
}, "ReadAppSignature", "getAppSignature", []);
|
||||
cordova.plugins.ReadAppSignature.getAppSignature(function(signature){
|
||||
console.debug("signature: %s", signature);
|
||||
}, function(error){
|
||||
console.debug("signature error: %s", JSON.stringify(error));
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package cordova.plugin.appSignature;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.PluginResult;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.pm.PackageInfo;
|
||||
@@ -22,6 +23,7 @@ import java.security.NoSuchProviderException;
|
||||
* This class echoes a string called from JavaScript.
|
||||
*/
|
||||
public class ReadAppSignature extends CordovaPlugin {
|
||||
private final String TAG = "ReadAppSignature";
|
||||
|
||||
@Override
|
||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
||||
@@ -46,9 +48,10 @@ public class ReadAppSignature extends CordovaPlugin {
|
||||
cordova.getActivity().getPackageName(), PackageManager.GET_SIGNATURES);
|
||||
|
||||
//note sample just checks the first signature
|
||||
for (Signature signature : packageInfo.signatures) {
|
||||
// SHA1 the signature
|
||||
LogUtils.LOGD(TAG, "getAppSignature() called : " + getSHA1(signature.toByteArray()));
|
||||
Signature[] signatures = packageInfo.signatures;
|
||||
if (signatures.length > 0) {
|
||||
Signature signature = signatures[0];
|
||||
Log.d(TAG, "getAppSignature() called : " + getSHA1(signature.toByteArray()));
|
||||
return getSHA1(signature.toByteArray());
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var exec = require('cordova/exec');
|
||||
|
||||
exports.getAppSignature = function (arg0, success, error) {
|
||||
exec(success, error, 'ReadAppSignature', 'getAppSignature', [arg0]);
|
||||
exports.getAppSignature = function (success, error) {
|
||||
exec(success, error, 'ReadAppSignature', 'getSignature', []);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user