I have been trying to use an intent to open a link to a kml file using the browser. That way when it goes to the link it will download and open the file in Google Maps (or Google Earth). However, when I click on it in the emulator nothing seems to happen. Any ideas?
package shc_BalloonSat.namespace;
import android.content.Intent;
import android.net.Uri;
public class dl_viewKML
{
void downloadFile()
{
String encodedURL = "http://" + "www.wktechnologies.com/shc_android_app/data.kml";
Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(encodedURL));
startActivity(webIntent);
}
private void startActivity(Intent webIntent)
{
// TODO Auto-generated method stub
}
}
Eclipse doesn’t show up any problems and it doesn’t show up anything in LogCat.
For the method
startActivity()to start yourIntentyou have to either call it from the class or subclasses(like Activity, FragmentActivity) ofContextor get a reference to the context and call it.Because your class
dl_viewKMLisn’t a subclass ofContextyou have to get a reference to the context. You can do this by adding a constructor with aContextparameter like in this:In your
Activitywhere you instantiate thedl_viewKMLclass you will do something like this:or