Android Question Run a bing/google/etc. search query from service?

redincali

Member
Hello. I'm not sure how to say what I'm trying to do, with a few words, so I'll start from the beginning...

Bing.com has a rewards program. You earn points and spend them when you've collected enough. You gain 1 point for every 2 searchs you do. With a max of 15 points a day by using Bing search. So I created an app that randomly generates letters and uses them as the search phrase. It works fine when the user runs it manually. I also made it do an autorun daily at a time they specified. For now, in order for it to run, the screen has to be turned on then back off after it finishes the searches. It does work this way, but only when I have my lockscreen disabled.

So, what I'm trying to figure out is how to do this by using a service module. I tried using an HttpJob. I think it was accessing the url I told it to, but wouldn't count its search towards my reward points. I know when I use a WebView, I have to set its UA to a desktop because the rewards from Bing only accepts pc/desktop searches, not mobile. So I'm not sure if thats my problem or if I'm just doing it incorrectly. I also tried setting the username/password properties, but still no luck.

If I could get any help, it would be much appreciated. Thank you.
 

redincali

Member
Yes, Bing needs to be logged in either with a facebook account or a Microsoft one. When I run it manually, the webview is signed in and stays signed in, but when with it not signed in, it will allow you to gain up to 5 points as a quest. Does the httputil use different cookies then the webview even though they're from the same app?

I'm not at my PC right now, but this is what i basically have...

B4X:
'Global code
Dim hClient as HttpClient
Dim hReq as HttpRequest
Dim sCount as Int 'for counting searches done


'Service Start code
sCount = 0
hClient.Initialize("hClient")
hReq.InitializeGet(bingSrchURL & randomSearch)
hReq.SetHeader("User-Agent", UAforDesktop)
hClient.Execute(hReq, 1)


hClient_ResponseSuccess(Response as HttpResponse, TaskId as Int)
ToastMessageShow("Search " & sCount & " done", False)
If sCount = 10 then Return 'stops searches after 10 finish
account = sCount + 1
hClient.Execute(hReq, 1)
End Sub
 
Last edited:
Upvote 0

redincali

Member
Thanks Erel. I will be purchasing b4a soon, just hard times atm. Which is why i want to develop, to make some cash. Hopefully Ill be able to figure it out then. Thank again.
 
Upvote 0
Top