I would like to integrate a "Donate via Bitcoin" button in an Android application's PreferenceScreen.
There are a few Bitcoin clients for Android running around, and Bitcoin wiki defines a URI scheme that is supposed to be used for BTC payments.
I have tried the following code
findPreference(getString(R.string.preference_donateBitcoin)).setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
String url = getString(R.string.pref_donateBitcoin_uri);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
return false;
}
});
withou a BTC installed on phone. I've tried to launch the intent with the following URI: bitcoin:19iSEgNkJnEUtNDuuTkkZrU44PVKYMVfhz?amount=1
expecting Android telling me that no handler is installed.
Instead I got an ActivityNotFoundException
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=bitcoin:19iSEgNkJnEUtNDuuTkkZrU44PVKYMVfhz?amount=1 }
My question is about correctly handling (read "best practices") URI schemes unknown to device.
- How do I check that a certain URI scheme can be handled at least by one application? (if more, I suppose a choice screen)
- With reference to Bitcoin but without reference to any specific client, what should the best Intent be when paying via Bitcoin? How to handle the case when no BTC client is installed?
[Edit]: the question is wrong because I messed up my phone backups and presumed the Bitcoin Wallet app was installed when it was not.