Last active
June 13, 2018 18:35
-
-
Save teshi04/953c5e3105fc065a4aac to your computer and use it in GitHub Desktop.
Device owner using NFC on Android Lollipop
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
MessageDigest digest = null; | |
try { | |
digest = MessageDigest.getInstance("SHA-1"); | |
} catch (NoSuchAlgorithmException e) { | |
e.printStackTrace(); | |
} | |
byte[] apkBytes = new byte[0]; | |
try { | |
apkBytes = IOUtils.toByteArray(getAssets().open("app-debug.apk")); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
digest.update(apkBytes); | |
NfcAdapter defaultAdapter = NfcAdapter.getDefaultAdapter(this); | |
try { | |
Properties p = new Properties(); | |
p.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, "com.manijshrestha.lollipopkiosk"); | |
p.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION, "https://www.dropbox.com/s/8o3soifag7g84ls/app-debug.apk?dl=1"); | |
p.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM, Base64.encodeToString(digest.digest(), Base64.URL_SAFE)); | |
StringWriter stringWriter = new StringWriter(); | |
p.store(stringWriter, ""); | |
NdefMessage msg = new NdefMessage(NdefRecord.createMime(DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC, stringWriter.toString().getBytes("UTF-8"))); | |
defaultAdapter.setNdefPushMessage(msg, this); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment