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.
Either:
just catch the
ActivityNotFoundException, oruse
PackageManagerandresolveActivity()orqueryIntentActivities()to see if there is anything matching yourIntentYou would have to ask the authors of Bitcoin apps that question, or encourage them to adopt a
Uristandard, if they have not done so already.According to the manifest for the application you list, your
Intentlooks like it should work. At least, using AppXplore, I see an activity forACTION_VIEWforUrivalues with a scheme ofbitcoin. Hence, you may wish to contact the developer of this app and see if you can determine precisely where you are going wrong with your integration.Offer to take the user to the Play Store to install some Bitcoin client you like, via a
market:Uri.