Android Question Monetize with Bitcoin, donate button code?

Discussion in 'Android Questions' started by cyiwin, Mar 2, 2015.

  1. cyiwin

    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.

    basicall and Devan like this.
  2. cyiwin

    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...

    Sub Get_Bitcoin_Donation
    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) = "" Then name = ""
    If package_list.Get(i) = "de.schildbach.wallet" Then name = "de.schildbach.wallet"
    If package_list.Get(i) = "" Then name = ""
    If package_list.Get(i) = "com.xapo" Then name = "com.xapo"
    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")
            Dim bit_intent = pm.GetApplicationIntent(name) As Intent
    If bit_intent.IsInitialized Then StartActivity(bit_intent)
    End If
    End Try
    End Sub
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice