Make a google search by code - Android Software Development

Hello, I'm trying do something but don't find the way.
My application have a button, wich on click should open the browser showing the google results for a search (Just search a string on google and show it on browser).
How can I do it? I have searched a lot but only find results unrelated with android development
Thanks!

I havent tried this but I think something like this should work:
Code:
String mySearchTerms ="is+android+awesome";
String urlString = "http://www.google.com/search?q="+ mySearchTerms;
Intent i= new Intent( Intent.ACTION_VIEW );
i.setData( Uri.parse( urlString ) );
startActivity ( i );
You could get more fancy and send them to the mobile site too, and URL encode the mySearchTerms string if you want. There should be URL encoding utils in the org.apache package.

Thanks! =)

Related

Learning how to program for Windows Mobile?

I've done some searching, and I know Windows CE uses Win32, which I know to an extent. I was curious if there are any good free resources for learning WinCE-Win32, or if I should simply use my existing books for MFC/Win32. Microsoft's site kinda sketchy, and MSDN not being very useful. I did get Microsoft Embedded Visual C++ working and compiled a test app which worked on my MDA and on the emulator.
i would just start coding
miniMFC and compact .net framework is soo close it's only
some controls and options you dont have
ortherwise it's the same thing
learning by doing and having ones fingers down and dirty
into the code is where you learn the most
Yep, that's just how I learned when I switched to coding for PPCs.
Any way here are a few major differences to start you off:
1) All API's that use strings are in UNICODE. ASCII versions were removed.
2) For most API's that have an 'ext' version the regular version was removed. Example: ExtTextOut - yes, TextOut - no.
3) When dealing with files, all paths must be absolute. No '..\file.x' and 'file.x' will give you the file in device root and not the app directory.
And here is a nice site for pocket PC specific apps:
www.pocketpcdn.com
Has articles on just about everything from making dialogs not full screen to writing today plug-ins.
levenum said:
Yep, that's just how I learned when I switched to coding for PPCs.
Any way here are a few major differences to start you off:
1) All API's that use strings are in UNICODE. ASCII versions were removed.
2) For most API's that have an 'ext' version the regular version was removed. Example: ExtTextOut - yes, TextOut - no.
3) When dealing with files, all paths must be absolute. No '..\file.x' and 'file.x' will give you the file in device root and not the app directory.
And here is a nice site for pocket PC specific apps:
www.pocketpcdn.com
Has articles on just about everything from making dialogs not full screen to writing today plug-ins.
Click to expand...
Click to collapse
I knew about how everything was Unicode. Is there an easy way to create unicode strings? I remember there was something in MFC macro like TEXT() that did something like that, but the specifics are missing. I remember there was a knowledge base article on this, but I can't find it.
Also, what's the difference between the Ext version and the non-ext versions of an app?
EDIT: Unless I'm mistaken, I just need to put my strings in _T("*string*")
Yes, you're right, this is how you write strings in your code:
Code:
WCHAR uniStr[] = L"Unicode string";
or if you are using MFC:
Code:
CString uniStr = _T("Unicode string");
and if you have a ASCII string you want converted to UNICODE
use mbstowcs function. (CString class has a built in conversion)
As for the 'ext' API's they just give you more parameters to better control the result of whatever they are doing. In desktop windows if you didn't want to call a function with 10 parameters you usually had a simpler version of it where some things were default.
Example:
Code:
BOOL TextOut(
HDC hdc, // handle to DC
int nXStart, // x-coordinate of starting position
int nYStart, // y-coordinate of starting position
LPCTSTR lpString, // character string
int cbString // number of characters
); //5 parameters
BOOL ExtTextOut(
HDC hdc, // handle to DC
int X, // x-coordinate of reference point
int Y, // y-coordinate of reference point
UINT fuOptions, // text-output options
CONST RECT *lprc, // optional dimensions
LPCTSTR lpString, // string
UINT cbCount, // number of characters in string
CONST INT *lpDx // array of spacing values
); // 8 parameters
what would be your suggestion for a newbie to learn programming for PPC?
I'm beggining to have interest in doing this but have absolutely no idea where to start.
thanks for any advise.
For complete newbies, I wrote this post a while back:
http://forum.xda-developers.com/viewtopic.php?p=209136#209136
V

VB.net help needed for an app Im halfway through writing.

Ive got to a point where Ive got to the limit of my knowledge.
(admitedly, I no pro, I just dont know how to do this)
Ive got a loop which finds out how many images are in a folder
and it makes a new picturebox for each image, sets the image
property to show that image and gives it a name, height, width,
location and parent.
My problem is I want to add a mouseclick event for each of these
items as I create them. I just dont have a clue how to do this.
Anyone got any ideas?
Ive tried this kinda thing, but it didnt work (stupid compact framework):
Code:
picturebox.MouseClicked += new MouseEventHandler(function_name);
Good Help Forum
http://www.vbforums.com/
It must work... Not sure how it is in VB.NET, but in C# it is this:
... in some method ...
PictureBox pb = new PictureBox();
.. setting properties
pb.Click += new EventHandler(PictureBox_Click);
... end of the method
private void PictureBox_Click(object sender, EventArgs e)
{
... here goes your code, the picturebox clicked is in (sender as PictureBox), event args are in e
}
Thanks for you help
Ive not managed to get anything working properly so far
but I have within the past 10 mins figured out how to get around having to do this ^_^
See, this is a autoload image:
Me.PictureBox1.Image = New System.Drawing.Bitmap("figure2.bmp")
And Example:
http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/2896d5cd-06d1-4a70-a561-a2c3497e325c
I think this wouldn't have been a problem with older VB technology if it had supported WM development. By that I mean it supported object arrays and provided a method with an 'Index'. From what I can see .NET doesn't offer such a luxury.
Your code looks right (syntax); but would I be right in thinking that your loop recreates 'picturebox' each time it loops and you are trying to associate an array of 'picturebox' to a single 'MouseEventHandler' function?
Code:
picturebox.MouseClicked += new MouseEventHandler(function_name);
My method of programming .NET is pretty much trial and error so I can't say for sure, just waffling
This is an example on how i did this with c# and the paint event. You dont want the paint event but it should be easy enough to change.
private void GenerateDynamicControls(string extt)
{
PicBox = new PictureBox();
PicBox.Image = Properties.Resources.phone;
PicBox.Name = "picturebox" + extt.ToString();
PicBox.Width = 75;
PicBox.Height = 75;
PicBox.BackgroundImageLayout = ImageLayout.Center;
flowLayoutPanel1.Controls.Add(PicBox);
PicBox.Paint += new PaintEventHandler(picpaint);
}
private void picpaint(object Sender,System.Windows.Forms.PaintEventArgs e)
{
//Do whatever you need done here
}
//To Create the control do this.
GenerateDynamicControls(namethecontrolsomething);
Hope this helps.
In VB.Net, you need to use AddHandler. Quick search on the tutorial and I found, http://www.thescarms.com/dotnet/EventHandler.aspx
Hope this help.
smart device applcation
Sorry guys but I will use this thread to ask for your help regarding VB.Net.
Does anyone know how to browse the device and select a picture into a picture box?
Example:
I have a form with a picturebox and a button and what I want is by pressing the button to explore my device, choose a picture and update my picturebox with the picture selected.
There are loads of youtube videos with Windows Forms Applications tutorial but I just can not find one for a smart device applcation.
Any help?
Thanks

[Q] Linkify vs TextView vs setMovementMethod

hi,
I'm loading a standard HTML code into a text view and would like to see the links to be possible to click and call the browser (web intent)
from all my readings the following code was supposed to work:
Code:
TextView tx = new TextView(this);
tx.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tx.setText(Html.fromHtml(item.get_text()));
tx.setMovementMethod(LinkMovementMethod.getInstance());
mLayout.addView(tx);
but the fact is.. it does not work!
according to google API example link.java
Code:
TextView t3 = (TextView) findViewById(R.id.text3);
t3.setText(
Html.fromHtml(
"<b>text3:</b> Text with a " +
"link " +
"created in the Java source code using HTML."));
t3.setMovementMethod(LinkMovementMethod.getInstance());
it was supposed to be that simple, in it's declaration text3 have no special tags.
I tried several options using Linkify(tx, Lkinkify.ALL); tx.setClickable(true); tx.setLinksClickable(true); setAutoLinkMask(Linkify.ALL) and regardless of what combination I tried I cannot make those HTML links clickable!
important to note that every time I use setMovementMethod the underline on the links disappear from the TextView
any help please??
Have you tried just putting the html from their example in the fromHTML method? It shouldnt be any different but when stuff doesn't work its good to simplify.
Maybe your item.getText is wonky
From something awesome
Just to "close" the post.
at the end I guess was just some mixed binaries floating in my phones flash.. cause after I unistall the app, re-copy the code from the examples and tried it just worked... go figure.
in case anywant fancy.. the final code is:
Code:
TextView tx = new TextView(this);
tx.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tx.setTextColor(getResources().getColor(R.color.txt));
tx.setLinkTextColor(getResources().getColor(R.color.txt));
tx.setMaxWidth((int) (getResources().getDisplayMetrics().density * 360));
tx.setText(Html.fromHtml(item.text));
tx.setMovementMethod(LinkMovementMethod.getInstance());
TextLayout.addView(tx);
if any forum moderator sees this feel free to close the thread.

Push Notification in Android

Hi,
I wrote an application that gives me the registration id for push notification. I also wrote a server side that sends push notification, but for some reason I am getting id=0:123.... and the notification never sent....
My code is:
void send(string regId)
{
var applicationID = "AIzaSyA-bpa68WzAgRl-ufkhBUAWmg9jTbMZKEo";
var SENDER_ID = "551376547541";
var value = "test";
System.Net.WebRequest tRequest;
tRequest = System.Net.WebRequest.Create("https://android.googleapis.com/gcm/send");
tRequest.Method = "post";
tRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));
tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
// string postData = "{ 'registration_id': [ '" + regId + "' ], 'data': {'message': '" + txtMsg.Text + "'}}";
string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + value + "&data.time=" + System.DateTime.Now.ToString() + "&registration_id=" + regId + "";
Console.WriteLine(postData);
Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
tRequest.ContentLength = byteArray.Length;
tRequest.ContentType = "application/x-www-form-urlencoded";
System.IO.Stream dataStream = tRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
System.Net.WebResponse tResponse = tRequest.GetResponse();
dataStream = tResponse.GetResponseStream();
System.IO.StreamReader tReader = new System.IO.StreamReader(dataStream);
String sResponseFromServer = tReader.ReadToEnd();
lblStat.Text = sResponseFromServer;
tReader.Close();
dataStream.Close();
tResponse.Close();
}
and I am sending:
send("APA91bH4E4zXOHKCMOON3iy85SJbEPlvtuppF4QOyNh88UqjABM3Mddp8B9kgpvXOZdreBHhz6SpjvYmBPwnWJTgApABqKgr9WB2_Lv8kjFRHZGvVMom0k85wEKsS2qfrMNUMaLBxZA5sNrKE7rMHxGVFUlAmLLvqw");
What do I have to do in order to get the notification in my Android ? What this id means ?
I'm sorry but I can't improve your code, but I do know an alternative:
Parse | Push
It's really easy, I found it two days ago and I'm already loving it
Goodluck with your app
Server Side Code
I have used a the below server side code written in PHP to send data to my client device . make sure your device has a google account and firewall protection of anti virus is disabled . Hope this will help . I will advice to use a real device to test the application or you can you bluestacks virtual device
<?php
// Replace with real server API key from Google APIs
$apiKey = "Your API Key";
// Replace with real client registration IDs
$registrationIDs = array( "Your device registration Id");
// Message to be sent
$message = "Test Notification PHP";
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( 'price' => $message )
);
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
//curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_POST, true);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields ));
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
echo $result;
//print_r($result);
//var_dump($result);
?>
It's unclear from your post which push technology you are using (GCM vs C2DM). Presuming you've opted for GCM (since C2D is deprecated), I've got a working example of both client and server code on Github. I can't post links yet, but it's at github.com/rossja/GCMDemo. Like the prior post, I used PHP for the server side language.
I'm not sure where you're seeing the results you're getting: is that ID contained in the intent extra? Is it something that you're seeing in logcat perhaps?
Please put your code into code tags.
MaartenXDA said:
I'm sorry but I can't improve your code, but I do know an alternative:
Parse | Push
It's really easy, I found it two days ago and I'm already loving it
Goodluck with your app
Click to expand...
Click to collapse
Awesome!I was sick thinking of how to do this and this made it so damn easy!
vijai2011 said:
Awesome!I was sick thinking of how to do this and this made it so damn easy!
Click to expand...
Click to collapse
Yup and you could try the other stuff as well, with the login, users and ParseObjects. It's so easy, I just made a chatroom in 30 minutes .
Sent from my awesome fridge
MaartenXDA said:
Yup and you could try the other stuff as well, with the login, users and ParseObjects. It's so easy, I just made a chatroom in 30 minutes .
Sent from my awesome fridge
Click to expand...
Click to collapse
Chatroom in 30mins? Thats just amazing!
vijai2011 said:
Chatroom in 30mins? Thats just amazing!
Click to expand...
Click to collapse
Yup And you could make something so that the users can send feedback, by just letting them make another ParseObject (e.g "Bugs")
MaartenXDA said:
Yup And you could make something so that the users can send feedback, by just letting them make another ParseObject (e.g "Bugs")
Click to expand...
Click to collapse
Ah...nice .But I have my own code for feedback and reporting fc which sends directly to my mail(along with log for fc) which is better in my case
vijai2011 said:
Ah...nice .But I have my own code for feedback and reporting fc which sends directly to my mail(along with log for fc) which is better in my case
Click to expand...
Click to collapse
Ah yeah that might be better. Although you can also send ParseFiles with Parse

Why can't i capture image and video both?Why only one at a time?

hi
I am a newbie android developer.
I did post this in Q&A, where people told me to ask this is the dev section. So i am posting it here, it is a question related to the application I am developing.
Know some fundamentals of Android OS.
Also familiar with Java, just new to Android.
I am building an application where i need to access the camera to click pictures and videos
At this stage, I can do only one thing at a time.(either click image/video, i have both the codes, the intents and everything however i need to change the code and can use only one at a time, for example if video code is executing, i dont see a focus on the screen for image to be captured... however the record button is visible, but when image code is executed i dont see any record button...i do see the focus on the screen for the capture.. )
My code is in the onCreate function, i know this is the function called first in the lifecycle, so i tried putting both code for images and videos in this function, but i can do only one.
here is my
Code:
/*code for images*/
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "MyImages1");
imagesFolder.mkdirs(); // <----
File image = new File(imagesFolder, "IMAGE_001.JPG");
Uri uriSavedVideo = Uri.fromFile(image);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedVideo);// set the image file name
startActivityForResult(intent,CAPTURE_IMAGE_ACTIVI TY_REQUEST_CODE);
/*code for videos
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
File videosFolder = new File(Environment.getExternalStorageDirectory(), "MyVideos1");
videosFolder.mkdirs(); // <----
File video = new File(videosFolder, "video_001.mp4");
Uri uriSavedVideo = Uri.fromFile(video);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedVideo);// set the image file name
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high
startActivityForResult(intent,CAPTURE_VIDEO_ACTIVI TY_REQUEST_CODE);
*/
why can i click image or video only but not both in my application?
guys sorry for the second post..
but please do reply something..
give me some hints..directions as to what I should look for..
so that I can proceed..
You let the Camera.apk do your work. Maybe there is a way, if you take the video yourself: Use the MediaRecorder and Camera classes.

Categories

Resources