android - how to import com.google.android.maps.MapActivity? - android

I am trying to get google maps to work in my android project. I have already got the md5 key and signed up with google to get the api key, but now when i am trying to display the map, I get an error when importing it. "com.google" has the sqiqly red line under it.
Can anyone help?
Thanks
this is my xml file: (note: i replaced the key with 'my_key' since i didnt want to make it public)
<com.google.android.maps.MapView
android:id="my_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="my_key"/>
and for the java file:
package com.escortme.basic;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import com.google.android.maps.MapActivity; // ERROR
import com.google.android.maps.MapView; // ERROR
import android.os.Bundle;
public class Police_ViewActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.pol_view);
}
public void quit_button_action(View view){
finish();
}
}

It sounds like you don't have the Google APIs referenced by your project. Assuming you're using Eclipse, view the properties of your project and select Android and check that Google APIs is checked rather than simply an Android version.
You may need to download the Google APIs if you haven't already. You can do this through the Android SDK Manager.

Related

GoogleApiClient.ConnectionCallbacks error compile time

should I use google drive bat I can't compile this activity
package com.google.android.gms.drive.sample.demo;
import android.app.Activity;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
/**
* An abstract activity that handles authorization and connection to the Drive
* services.
*/
public abstract class BaseDemoActivity extends Activity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
...
I use Google Plugin for Eclipse to install the library and google APIs
but since compile error
GoogleApiClient cannot be resolved to a type
Follow the Google+ Platform Quickstart for Android in order to install Google Play Services as a library project.
In particular see step 5:
5. Import the Google Play Services library project.
Select File > Import > Android > Existing Android Code Into Workspace and click Next.
Select Browse.... Enter <android-sdk-folder>/extras/google/google_play_services/.
Select google-play-services_lib. Click Finish to import.

Getting Started with the facebook sdk for android

I have been finished step 3 of "Getting Started with the Facebook SDK for Android" from facebook developers support and this is code from the Sample directory :
package com.facebook.samples.profilepicture;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class ProfilePictureSampleActivity extends FragmentActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_picture_sample);
}
}
When I try to run ProfilePictureSample there are some errors like this :
"The import android.os.Bundle cannot be resolved"
"The type android.app.Activity cannot be resolved. It is indirectly
referenced from required .class files"
"The hierarchy of the type ProfilePictureSampleActivity is
inconsistent"
So how can I fix them ? It's strange because if I build a simple activity project with android.os.Bundle works fine.
Probably the problem is the holder api version that the application of this code request because I suppose that android.os.Bundle is for api 17 of android sdk. So it can be resolved by go to "android sdk Manager" and download the version of requested api.

Android Annotations EViewGroup unable to recognize EActivity in Eclipse

I have a class set up as an EViewGroup. In it, I'm trying to reference another Activity set up as an EActivity. For some reason, the import isn't resolving, but it resolves fine if I reference the Activity in question from another EActivity.
The code compiles fine using ant on our Jenkins server, but doesn't compile within Ecipse.
Any ideas?
Here's some code for ViewGroup:
import android.app.Activity;
import android.content.Intent;
import com.googlecode.androidannotations.annotations.Click;
import com.googlecode.androidannotations.annotations.EViewGroup;
#EViewGroup
public class MainMenu extends SlidingMenu
{
public void navigate(Class<? extends Activity> klass)
{
getContext().startActivity(new Intent(getContext(), klass));
toggle();
}
#Click(R.id.textView_bring_it)
public void bringItClick()
{
navigate(ActivityBringIt_.class);
}
}
The compile errors I'm seeing:
The import com.beachbody.p90x.bringit.ActivityBringIt_ cannot be
resolved
The method navigate(Class) in the type MainMenu
is not applicable for the arguments (Class)
ActivityBringIt_ cannot be resolved to a type
Here is my .factorypath file:
<factorypath>
<factorypathentry kind="WKSPJAR" id="/common/compile-libs/androidannotations-2.7.1.jar" enabled="true" runInBatchMode="false"/>
</factorypath>
It seems that ActivityBringIt_ isn't generated. Your compiling errors are just noises because of that.
Mostly AA can't generate subclasses if you have errors in you Android's xml files.
You should take a look on this.
Also, could you copy/paste your .factory file ?
Thanks DayS for pointing me in the right direction. There is a bug in Eclipse causing this issue. The workaround is to import the entire package in question. In my case it is:
import com.beachbody.p90x.bringit.*;
Here is the bug report w/ Eclipse:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=387956

Eclipse cannot import import com.google.android.maps.*?

I am trying the google maps api for android, but eclipse does not import the com.google.android.maps.* files.
Source:
MyMapActivity:
package org.madmax.map;
import android.app.Activity;
import android.os.Bundle;
import com.google.android.maps.*;
public class MyMapActivity extends MapActivity {
private MapView map;
private MapController controller;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
in the Manifest file I have already declared:
<uses-library android:name="com.google.android.maps" />
How do I import the com.google.android.maps.* files?
It is not enough to just have the API SDK installed. From the android maps documentation,
http://code.google.com/android/add-ons/google-apis/maps-overview.html
If you want to add Maps to an existing application, right-click the project in Package Explorer, choose Properties > Android and then select a build target from the list displayed. You must choose the "Google APIs" build target.
(The standard Android packages don't include Google Maps)
Update, found a screenshot online, don't pick a Target with the name "Android x.x" pick the corresponding target that says "Google APIs" for the version of Android you want.
Make sure you have the Google APIs installed in your SDK. Open the SDK manager from the tools directory and use it to install the package.

Add Server classes to android.jar

Right now I am able to get access to the hidden and internal android APIs, but now I want access to things like AlarmManagerService which is in server. I used adb pull system/framework/services.jar changed services.jar to services.zip which unpacked a directory of all the server classes (including AlarmManagerService which I was looking for). My question now is how can I add those server classes to my android.jar file which I can then use in Eclipse?
I hope that makes sense the way I worded it. Let me know if there is any confusion I can clear up.
EDIT: Essentially, when all is said and done, I want to be able to do something like below without any errors:
import com.android.server.AlarmManagerService;
public class TestActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AlarmManagerService ams = new AlarmManagerService(this.getApplicationContext());
ams.setTime(1313);
}
}
ANOTHER EDIT:
I figured this out after looking at all the source code.
Classes like AlarmManagerService just have package visibility which is why it cannot be imported. Some classes are public, but many other com.android.server classes have package constructors so they can't be instantiated.
Here are the com.android.server.* I was able to import and successfully create an object of:
import com.android.server.AttributeCache;
import com.android.server.BootReceiver;
import com.android.server.BrickReceiver;
import com.android.server.ClipboardService;
import com.android.server.ConnectivityService;
import com.android.server.DevicePolicyManagerService;
import com.android.server.DiskStatsService;
import com.android.server.DropBoxManagerService;
import com.android.server.EntropyService;
import com.android.server.InputMethodManagerService;
import com.android.server.LocationManagerService;
import com.android.server.MasterClearReceiver;
import com.android.server.NativeDaemonConnectorException;
import com.android.server.NetStatService;
import com.android.server.NotificationPlayer;
import com.android.server.ProcessMap;
import com.android.server.ProcessStats;
import com.android.server.SystemBackupAgent;
import com.android.server.SystemServer;
import com.android.server.ThrottleService;
import com.android.server.TwilightCalculator;
import com.android.server.Watchdog;
import com.android.server.connectivity.Tethering;
import com.android.server.status.AnimatedImageView;
import com.android.server.status.CloseDragHandle;
import com.android.server.status.DateView;
import com.android.server.status.ExpandedView;
import com.android.server.status.IconMerger;
import com.android.server.status.LatestItemView;
import com.android.server.status.NotificationData;
import com.android.server.status.NotificationLinearLayout;
import com.android.server.status.StatusBarService;
import com.android.server.status.StatusBarView;
import com.android.server.status.StorageNotification;
import com.android.server.status.TickerView;
import com.android.server.status.TrackingPatternView;
import com.android.server.status.TrackingView;
import com.android.server.status.UsbStorageActivity;
android.jar contains only the public API's class files and I think you made changes in 'com.android' package or its internal packages. So to reflect the changes in eclipse you have to add the path explicitly to your service.jar to your project. But remeber this will not reflected at run time, since the emulator or the device you are using have not been updated your changes. And you can't update them by simply modifying the jar file, since the device or emulator uses the image 'system.img' which internally have .dex file as library not the .jar file for internal APIs. To make changes for device/emulator you have to build the whole code and for that you can refer the http://source.android.com/source/index.html.

Categories

Resources