Create an NFC trigger application and install it on the device (different from the one on which you want to make your application the owner of the device) with NFC.
Below is the NFC startup code
public class MainActivity extends Activity implements CreateNdefMessageCallback { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this); nfcAdapter.setNdefPushMessageCallback(this, this); } @Override public NdefMessage createNdefMessage(NfcEvent event) { try { Properties p = new Properties(); p.setProperty( DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, "apk package name"); p.setProperty( DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION, "app download url"); p.setProperty( DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM, "apk checksum"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputStream out = new ObjectOutputStream(bos); p.store(out, ""); final byte[] bytes = bos.toByteArray(); NdefMessage msg = new NdefMessage(NdefRecord.createMime( DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC, bytes)); return msg; } catch (Exception e) { throw new RuntimeException(e); } } }
For the checksum, run the following command
cat your_device_owner_app_name.apk | openssl dgst -binary -sha1 | openssl base64 | tr '+ /' '-_' | tr -d '='
- Insert the generated checksum into the NFC startup code.
- Compile and run the NFC trigger application on the device.
Now download the apk app that you want to make the device owner on the Google drive or Dropbox.
Take the new device or factory reset the device on which you want to install the application as the owner of the device.
Reboot the device and on the initial screen, bring your device containing the NFC trigger application and tap to transmit the beam.
Your application will be downloaded and installed as the owner of the device.
Spynet Nov 19 '14 at 4:48 2014-11-19 04:48
source share