mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-11 11:35:07 -05:00
calculate nfc packet on demand only
This commit is contained in:
parent
2227705d65
commit
a1e13f7893
@ -50,34 +50,22 @@ public class ViewKeyActivityJB extends ViewKeyActivity implements CreateNdefMess
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
initNfc(mDataUri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NFC: Initialize NFC sharing if OS and device supports it
|
* NFC: Initialize NFC sharing if OS and device supports it
|
||||||
*/
|
*/
|
||||||
private void initNfc(Uri dataUri) {
|
private void initNfc() {
|
||||||
// check if NFC Beam is supported (>= Android 4.1)
|
// check if NFC Beam is supported (>= Android 4.1)
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
// Check for available NFC Adapter
|
// Check for available NFC Adapter
|
||||||
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
|
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
|
||||||
if (mNfcAdapter != null) {
|
if (mNfcAdapter != null) {
|
||||||
// init nfc
|
// init nfc
|
||||||
|
|
||||||
// get public keyring as byte array
|
|
||||||
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
|
||||||
try {
|
|
||||||
mSharedKeyringBytes = ProviderHelper.getPGPPublicKeyRing(this, masterKeyId).getEncoded();
|
|
||||||
|
|
||||||
// Register callback to set NDEF message
|
// Register callback to set NDEF message
|
||||||
mNfcAdapter.setNdefPushMessageCallback(this, this);
|
mNfcAdapter.setNdefPushMessageCallback(this, this);
|
||||||
// Register callback to listen for message-sent success
|
// Register callback to listen for message-sent success
|
||||||
mNfcAdapter.setOnNdefPushCompleteCallback(this, this);
|
mNfcAdapter.setOnNdefPushCompleteCallback(this, this);
|
||||||
} catch(IOException e) {
|
|
||||||
// not much trouble, but leave a note
|
|
||||||
Log.e(Constants.TAG, "Error parsing keyring: ", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,9 +81,19 @@ public class ViewKeyActivityJB extends ViewKeyActivity implements CreateNdefMess
|
|||||||
* guarantee that this activity starts when receiving a beamed message. For now, this code
|
* guarantee that this activity starts when receiving a beamed message. For now, this code
|
||||||
* uses the tag dispatch system.
|
* uses the tag dispatch system.
|
||||||
*/
|
*/
|
||||||
|
// get public keyring as byte array
|
||||||
|
long masterKeyId = ProviderHelper.getMasterKeyId(this, mDataUri);
|
||||||
|
try {
|
||||||
|
mSharedKeyringBytes = ProviderHelper.getPGPPublicKeyRing(this, masterKeyId).getEncoded();
|
||||||
|
|
||||||
NdefMessage msg = new NdefMessage(NdefRecord.createMime(Constants.NFC_MIME,
|
NdefMessage msg = new NdefMessage(NdefRecord.createMime(Constants.NFC_MIME,
|
||||||
mSharedKeyringBytes), NdefRecord.createApplicationRecord(Constants.PACKAGE_NAME));
|
mSharedKeyringBytes), NdefRecord.createApplicationRecord(Constants.PACKAGE_NAME));
|
||||||
return msg;
|
return msg;
|
||||||
|
} catch(IOException e) {
|
||||||
|
// not much trouble, but leave a note
|
||||||
|
Log.e(Constants.TAG, "Error parsing keyring: ", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user