Android Question Monetize with Bitcoin, donate button code?

cyiwin

Active Member
Licensed User
Hello all, I would like to add a Bitcoin donation button in my settings but I'm confused on how to do it. When the donate button is pressed, I would like it to search for a Bitcoin wallet that is installed on the users device and open it. Pre-enter a small amount into the users wallet and from there it would be up to the user to decide if they want to donate that amount and send it.

Right now I'm reading about the wonderful world of intents, ugh. I don't want anyone to go out of their way to figure this out for me but if someone has already done this would you be willing to post your code?

If nobody posts and I figure it out, I'll come back and post mine.

Thanks
 

cyiwin

Active Member
Licensed User
Well, I have something that seems to work. I don't know how to tell Android to open any user installed Bitcoin wallet, so I made a list of common wallets to look for. On my Galaxy S3, if any of these package names where found, it opens the wallet. I had two wallets on my phone and it still asked me which wallet I wanted to open. Example, if the intent used package name "com.airbitz" it still asks me if I want to open my Airbitz or Mycelium wallet. So I think that's good.

Make sure you're using the phone library for Package Manager.

Maybe someone will write some better code and post here later...

B4X:
Sub Get_Bitcoin_Donation
Try   
    Dim pm As PackageManager
    Dim package_list As List
    Dim name As String
    package_list = pm.GetInstalledPackages
   
    For i = 0 To package_list.Size - 1
        If package_list.Get(i) = "com.mycelium.wallet" Then    name = "com.mycelium.wallet"
        If package_list.Get(i) = "com.airbitz" Then    name = "com.airbitz"
        If package_list.Get(i) = "it.greenaddress.cordova" Then name = "it.greenaddress.cordova"
        If package_list.Get(i) = "com.hivewallet.androidclient.wallet" Then name = "com.hivewallet.androidclient.wallet"
        If package_list.Get(i) = "piuk.blockchain.android" Then name = "piuk.blockchain.android"
        If package_list.Get(i) = "de.schildbach.wallet" Then name = "de.schildbach.wallet"
        If package_list.Get(i) = "com.coinbase.android" Then name = "com.coinbase.android"
        If package_list.Get(i) = "com.xapo" Then name = "com.xapo"
    Next
   
    If name = "" Then 'client doesn't have any of the listed wallets installed
        Msgbox("Thanks for your interest, you can download a Bitcoin Wallet from the Play Store.", "No Bitcoin Wallet found")
    Else
        'Log(pm.GetApplicationIntent(name))
        Dim bit_intent = pm.GetApplicationIntent(name) As Intent
        bit_intent.Initialize(bit_intent.ACTION_VIEW, "bitcoin:1J2ByuqPwCB1RkWHpEjT2RxWrHTqajCeQF?amount=.001")
        If bit_intent.IsInitialized Then StartActivity(bit_intent)
    End If
Catch
    Log(LastException.Message)
End Try
End Sub
 
Top