Merge pull request #393 from schwedenmut/Register-andOTP-as-intent-receiver

Implemented intent-filter to receive otpauth requests
This commit is contained in:
Jakob Nixdorf 2019-10-31 09:36:58 +01:00 committed by GitHub
commit 20a4512699
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 5 deletions

View file

@ -27,6 +27,13 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="otpauth" android:host="totp" />
<data android:scheme="otpauth" android:host="hotp" />
</intent-filter>
<intent-filter>
<action android:name="org.shadowice.flocke.andotp.intent.SCAN_QR" />
<action android:name="org.shadowice.flocke.andotp.intent.ENTER_DETAILS" />

View file

@ -277,18 +277,33 @@ public class MainActivity extends BaseActivity
setupDrawer();
checkIntent();
if (savedInstanceState != null){
setFilterString(savedInstanceState.getString("filterString", ""));
}
}
private void checkIntent() {
Intent callingIntent = getIntent();
if (callingIntent != null && callingIntent.getAction() != null) {
if (callingIntent.getAction().equals(INTENT_SCAN_QR)) {
scanQRCode();
} else if (callingIntent.getAction().equals(INTENT_ENTER_DETAILS)) {
ManualEntryDialog.show(MainActivity.this, settings, adapter);
} else if (callingIntent.getAction().equals(Intent.ACTION_VIEW) && !requireAuthentication) {
try {
Entry entry = new Entry(getIntent().getDataString());
entry.updateOTP();
entry.setLastUsed(System.currentTimeMillis());
adapter.addEntry(entry);
adapter.saveEntries();
Toast.makeText(this, R.string.toast_intent_creation_succeeded, Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(this, R.string.toast_intent_creation_failed, Toast.LENGTH_LONG).show();
}
}
}
if (savedInstanceState != null){
setFilterString(savedInstanceState.getString("filterString", ""));
}
}
@Override
@ -321,6 +336,7 @@ public class MainActivity extends BaseActivity
updateEncryption(null);
} else {
populateAdapter();
checkIntent();
}
}
}

View file

@ -10,7 +10,7 @@
<string name="button_settings">Settings</string>
<string name="button_all_tags">All tags</string>
<string name="button_no_tags">No tags</string>
<!-- Custom formatting -->
<string name="format_custom_period">%d s</string>
@ -61,6 +61,8 @@
<string name="toast_entry_exists">This entry already exists</string>
<string name="toast_invalid_qr_code">Invalid QR Code</string>
<string name="toast_encryption_key_empty">Encryption key not loaded</string>
<string name="toast_intent_creation_failed">Invalid intent-provided code</string>
<string name="toast_intent_creation_succeeded">Intent-provided code added</string>
<!-- Dialogs -->
<string name="dialog_title_auth">Authenticate</string>