Clueless Noob

  • Replies:26
  • OpenNot stickiedUnanswered
  • Forum posts: 17

Jun 27, 2011, 10:34:36 PM via Website

I'm a complete noob, so I apologise in advance if my questions reveal my total ignorance of what I am doing. :-)

I am trying to build apps to point to each of my websites. Just like appsgeyser.com, but with no advert, and with my certificate. I have spent all day on it, but have finally managed to get Java SDK,Eclipse, and Android SDK Manager running on my PC. OMG... I can't believe how hard it was!

I have two questions... in the hope of kindness (or pity!).

1. Can someone post the code I need to send the user to my site when they click the app? I guess it is simple... for you... but not for me. I can then just change the URL for each site I have.

2. I have some 'hello world' code in Eclipse, and can run it in the emulator. BUT, how do I make an APK file from that? How do I get from the code to the apk?


I know I have to sign it with my certificate after that, but that's a battle for another day.

If I can get these two questions sorted, I think I might make it through... perhaps.

Can someone help? Please?

Reply
  • Forum posts: 775

Jun 28, 2011, 12:12:30 AM via Website

Hi Nicola,

For question 1, I would use an intent to open their browser with the link you want. Instead of lots of code to try to make your app display the webpage it's self, just use an intent to bring the browser up. Here's some sample code:

Uri uri = Uri.parse( "http://www.mywebsite.com" );
startActivity( new Intent( Intent.ACTION_VIEW, uri ) );

Pretty simple, eh? You could put this code in your main activity, then let the activity close.

For question 2, you need to start with creating a project in eclipse. Then after coding the app, you build the project. There's two ways to build it, as a debug build or a release build. The debug build does the signing with a debug certificate for you, and is used to make a quick build for testing. You can do a debug build and then run it in the emulator. To make the actual release that you would upload to the market, you need to make your own certificate and build your project as a release. I'm sorry I can't be more specific on the in's and out's of eclipse, I don't use it really. Here's some helpful links:

Managing projects in eclipse: http://developer.android.com/guide/developing/projects/projects-eclipse.html
Compiling and signing / release build; with eclipse: http://developer.android.com/guide/publishing/app-signing.html#ExportWizard
Creating your certificate/private key: http://developer.android.com/guide/publishing/app-signing.html#cert
Signing your app with your key: http://developer.android.com/guide/publishing/app-signing.html
Publishing your app on the google market: http://developer.android.com/guide/publishing/publishing.html
Web apps (although this is different from just displaying a webpage I think): http://developer.android.com/guide/webapps/index.html
Google developer guide fundamentals: http://developer.android.com/guide/topics/fundamentals.html

— modified on Jun 28, 2011, 12:16:27 AM

Nicola Weaver

Reply
  • Forum posts: 17

Jun 28, 2011, 12:26:21 AM via Website

Wow... thanks so much.

So all I really need is this?
Uri uri = Uri.parse( "http://www.mywebsite.com" );
startActivity( new Intent( Intent.ACTION_VIEW, uri ) );

That is so straight forward, even I can get it. :-)


With (2) the problem I am having is that I cannot see any option to actually create an APK file. I see the sample java code in the window of Eclipse, which looks like this

================
package com.example.helloandroid2;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HelloAndroid2Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
=============================

And I see some build options at the top.... but nothing seems to happen when I click them.

I see no way of creating a compiled APK file...


Am I missing something really obvious?

I think I may be. The code looks ok, but I can't convert it to a file, and I get stuck there.

Reply
  • Forum posts: 775

Jun 28, 2011, 1:39:42 AM via Website

Yep, that couple lines of code should open their browser with your webpage. Probably next important thing you want your app to do is close cleanly. Or maybe not, you could experiment with programming here, maybe try to get it to ask them if they'd like to share your app in an email or facebook post. Here's some info on that subject: http://labs.emich.be/2010/01/23/how-to-send-to-twitter-or-facebook-from-your-android-application/ It's done with Intents as well.

I see now how to "build for release" with eclipse. It under the export options...
http://developer.android.com/guide/publishing/app-signing.html#ExportWizard
Read the part on "Compile and sign with Eclipse ADT"

I don't use eclipse myself, but for the new/beginning android developer I would suggest using eclipse. Here's an article on how I develop without eclipse if your interested: http://www.androidpit.com/en/android/wiki/view/Developing_Android_Apps_without_Eclipse

— modified on Jun 28, 2011, 1:40:08 AM

Nicola Weaver

Reply
  • Forum posts: 17

Jun 28, 2011, 10:28:30 AM via Website

Thanks so much! Direction like that is exactly what I needed.

:-)


One thing which I'm not sure on is this: "Probably next important thing you want your app to do is close cleanly". Is that done through code as well, like the two lines you gave me? Or is closing some other method?

What I thought I would do is build the simplest version I possibly can and get it working. Then, maybe revisit and look at facebook/etc.


Thanks again. Appreciated.

Reply
  • Forum posts: 775

Jun 28, 2011, 7:10:19 PM via Website

Look at this info on the android life cycle... http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle
Android is different than most os's your used to, it's designed so that apps dont really close when their finished, but when memory is needed. Some say this is a good thing, some a bad thing. In certain apps you may wont it to close completely, it's up to you. I would not really worry about closing your app for now, since it's small, just let the android os take care of it.

I think it's a good idea to build a simple version first. I'd even release it to the market as soon as possible. You can update your app at anytime, and the updates usually bring a new infusion of downloads; because the market will put your app at the top of the "just in" section with each update. You don't wanna update it every day and annoy your users with frequent re-downloads, but an update now and then with useful content is good.

Nicola Weaver

Reply
  • Forum posts: 17

Jun 29, 2011, 6:10:08 PM via Website

Thanks again for your much appreciated advice. I will indeed follow it.

My need could not be more simple. I just want the app to open my website! I can't believe just achieving that is so difficult... but then again, I am not really a techie. It took me a day to get Eclipse and the other stuff installed.

So far, I create a package, and stick this in the Eclipse code window:

package com.example.weblink;
Uri uri = Uri.parse( "http://www.mywebsite.com" );
startActivity( new Intent( Intent.ACTION_VIEW, uri ) );

But it gives all sorts of error messages... syntax errors on each line. So I don't even get to run it in the emulator to see if it works. Why?

Sorry: I am a bit embarressed by this, because I just know I am doing something dumb. I know it. :-(

Reply
  • Forum posts: 775

Jun 29, 2011, 10:46:23 PM via Website

You need a complete activity, those lines alone will not compile. I'd use a template for now till you get a better understanding. Here is a real easy to follow tutorial / template: http://www.anddev.org/novice-tutorials-f8/hello-android-your-first-application-t31.html


In the OnCreate section of the tutorials code, replace this code:

// We want to view some very simple text, so we need a TextView
TextView tv = new TextView(this);
// Put some text to the newly created TextVIew
tv.setText("Hello Android - by: anddev.org n" +
"This is soooo simple =D ");
// Tell our App to display the textView
this.setContentView(tv);

With the code to open your webpage:

Uri uri = Uri.parse( "http://www.mywebsite.com" );
startActivity( new Intent( Intent.ACTION_VIEW, uri ) );

Don't be embarressed, gotta start some where ;)

— modified on Jun 29, 2011, 10:53:31 PM

Nicola Weaver

Reply
  • Forum posts: 17

Jun 30, 2011, 9:09:23 PM via Website

Thank you so much. I am going to have a real go at this tomorrow. I would never have got anywhere near to this point without your help. :-)

Reply
  • Forum posts: 775

Jun 30, 2011, 10:18:36 PM via Website

Nicola Weaver
Thank you so much. I am going to have a real go at this tomorrow. I would never have got anywhere near to this point without your help. :-)

Your welcome ;)

Reply
  • Forum posts: 17

Jul 3, 2011, 6:49:47 PM via Website

I'm afraid I'm back.... :*)

My code looks like this:

-------------------------------------------------------
package org.anddev.firstapp;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class First_app extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Uri uri = Uri.parse( "http://www.mywebsite.com" );
startActivity( new Intent( Intent.ACTION_VIEW, uri ) );
}
}
-------------------------------------------------------------------

But there are two lines with red crosses next to them: the Uri and the Start Activity

The first red cross says "Uri cannot be resolved to a type, and Uri cannot be resolved"

The second says "Intent cannot be resolved to a type, The method startActivity(Intent) in the type Activity is not applicable for the arguments (Intent) and Intent cannot be resolved to a variable"

It happened yesterday and I thought if I tried again today I might have had some inspiration as to what to do. I haven't.

I'm sorry... do you know what I've done wrong?

Reply
  • Forum posts: 17

Jul 3, 2011, 7:36:39 PM via Website

I have just clicked the red cross for each, and took a punt by then clicking on 'importing' a couple of things. This changed the code.

It now looks like this:

-----
package org.anddev.firstapp;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;

public class First_app extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Uri uri = Uri.parse( "http://www.mywebsite.com" );
startActivity( new Intent( Intent.ACTION_VIEW, uri ) );
}
}
----------------------------------------

Does that look right?

When I click run though, a phone emulator thing comes up with ANDROID_ on it, but nothing else happens.

Erm... what do you think?

It is a bit scary but a bit exciting: am I getting there?

Thanks if you can help again. :-)

Reply
  • Forum posts: 775

Jul 3, 2011, 8:49:23 PM via Website

Importing those missing classes was the right way to do it, good catch there. As far as the emulator commng up with only "Android", it's most likely just taking a while. The android emulator has some speed issues, I've heard it take as long as 15mins to start up on slower computers. Try running the app again with the emulator and give it at least a good 10 mins to start up. Here are some tips on what you can do to speed up the emulator some: http://stackoverflow.com/questions/1554099/slow-android-emulator

It may be easier to run/debug the app on an actual device if you have one. Here's some info on running on an actual device: http://developer.android.com/guide/developing/device.html

Nicola Weaver

Reply
  • Forum posts: 17

Jul 3, 2011, 10:22:55 PM via Website

Thanks very much for getting back to help me.

I waited 20 minutes and it still didn't happen. Here is what it says:

[2011-07-03 20:53:37 - first_app] Android Launch!
[2011-07-03 20:53:37 - first_app] adb is running normally.
[2011-07-03 20:53:37 - first_app] Performing org.anddev.firstapp.First_appActivity activity launch
[2011-07-03 20:53:37 - first_app] Automatic Target Mode: launching new emulator with compatible AVD 'my_avd'
[2011-07-03 20:53:37 - first_app] Launching a new emulator with Virtual Device 'my_avd'
[2011-07-03 20:53:38 - first_app] New emulator found: emulator-5554
[2011-07-03 20:53:38 - first_app] Waiting for HOME ('android.process.acore') to be launched...

I'm starting to think that it may be something to do with the version of Android I picked (2.1)? Maybe not.... I wonder if there is another way to do it, like make the APK file and then test it?

Or putting it another way... I'm stuck again. Sorry :*)

Reply
  • Forum posts: 775

Jul 4, 2011, 6:13:16 AM via Website

What exactly is shown on your emulator screen? On the emulator I use, when it starts up, it doesn't just open the app itself. I have to unlock it (slide the unlock button over like on a phone that has gone into lock mode). Then I open the apps list and click the app in there to run it. Have you tried this?

If you have an actual android phone you could test it on you could do a release build (export) and copy it to the phone with the usb cable. Or I think you can do a debug build and run it on the phone instead of the emulator. http://developer.android.com/guide/developing/building/building-eclipse.html#RunningOnDeviceEclipse look at the info on "Running on a device". And this info for installing the usb driver for your phone on windows: http://developer.android.com/guide/developing/device.html

Nicola Weaver

Reply
  • Forum posts: 17

Jul 4, 2011, 5:53:39 PM via Website

Wow... I just ran it today, having changed nothing, and it sort of worked! Maybe it needed a re-boot. Exciting!!!!!

But when I say worked, I mean the emulator fired up and showed a telephone.

But when I slid the lock to open the app screen I got this:



OMG.... now I am officially out of my depth, :-(

Could it just be that it is trying to jump out of the emulator to the website the App forwards to... and the emulator doesn't like that idea? Yes, it's a wild guess!

Help?

:-)

— modified on Jul 4, 2011, 10:38:55 PM

Reply
  • Forum posts: 17

Jul 5, 2011, 8:40:59 PM via Website

The more I think about it, the more I think I may be right in that the emulator fails because it cannot jump to the website. I thought I would therefore try this:
"If you have an actual android phone you could test it on you could do a release build (export) and copy it to the phone with the usb cable"

I eventually got it on my Android phone, and guess what? I got exactly the same error message was with the emulator!

Sorry to be a pest.... can you help? What is wrong with it? Here is the code again:

-----
package org.anddev.firstapp;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;

public class First_app extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Uri uri = Uri.parse( "http://www.yahoo.com" );
startActivity( new Intent( Intent.ACTION_VIEW, uri ) );
}
}
-----

I think what you have said already is absolutely great for anyone like me who finds this thread. I can't be the only one so clueless. I hope. :*)

I fear I will never fix that error on my own. :-(

— modified on Jul 5, 2011, 9:33:03 PM

Reply
  • Forum posts: 775

Jul 6, 2011, 12:41:06 AM via Website

Hi Nicola,

Looks like you got it to run on the emulator but there is some error somewhere. The emulator actually can pull up webpages; if the computer running it is connected to the internet. You can test and see by opening the emulator and clicking the web app (globe icon) and it should pull up some webpages if it's able.

Most likely there is some mix up somewhere. Make sure the package name, and activity name you specified when you created the project match your code. The package name is declared on the first line of your code:

package org.anddev.firstapp;

Every code file you create for this app should have the package declared on the first line. BTW, I would not use org.anddev as the prefix to your packages, you can make it anything such as com.weaver.firstapp. Just make sure it matches the eclipse project properties and the code. Also make sure the activity name you provided when you created the project matches the activity on this line of your code:
public class First_app extends Activity {
It is case sensitive and I would try it without the _ underscore too. Each code file/class does not neccessarily have to have an activity line, but you need it in at least your main activity code/class.

Make sure you rebuild the project before you run it in the emulator after you check these things.

Also you can try debugging the error message your getting....
I'm not exactly sure how you do it with eclipse, what I do is open the command prompt and type: adb debug
while the emulator is running.

This brings up a command line window of the emulator debug output. When the emulator hits your code error, it will tell you which lines your getting the error on. You need to include the android/tools folder in your path, to use the adb. If you need more help with debugging let me know. If you could post the line number and error message your getting from the debug command window, I may be able to help more.

Nicola Weaver

Reply
  • Forum posts: 17

Jul 7, 2011, 7:37:13 PM via Website

Thank you yet again. :-)

I fiddled for an hour or so and eventually got it to work by renaming different things. I am not sure how at this point, so I will try to build from scratch to prove to myself that I can.

Then.... horror of horrors... I will try to work out how to 'sign' it, so I can upload it to the app market. I have a feeling I will be back...

Thanks again though for all your help. I would never have got past base one!

Reply
  • Forum posts: 17

Jul 7, 2011, 8:03:32 PM via Website

One quick question though.... when I upload my apk file to my phone, its avatar is the little Android huy. How do I get my own picture on there? Is that something I add to the source code somewhere?

UPDATE: I actually worked it out!

For any people who read this thread, who may be almost as clueless as me, you just change the icon.png file in the folder called /res.

Now... I will try to work out how to sign it!

:-)

— modified on Jul 8, 2011, 2:44:12 PM

Reply
Recommended articles