I'm currently testing gps locations in Android(with SDK Tools rev 21.0.1. I tried the standard procedure:
Create an emulator with GPS enabled(tried multiple version, from 2.1 to 4.2)
Start the emulator
telnet to localhost:5554
Type geo fix long lat
In theory, this should set the gps to .
But the following signs indicate the location is not properly set:
1. When I go to maps.google.com or open Google map, it always complains that cannot decide my location and they always ask me to switch on wifi.
2. The GPS never seems to be activated -- no icons on the status bar.
Also, I tried DDMS(which is deprecated and of course I tried Monitor as well). Nothing seems to happen.
I went previous links pointed here:
Location not being updated on new geo fix in android emulator
Android - Unable to get the gps location on the emulator
GPS on emulator doesn't get the geo fix - Android
But all those links do not seem to help. There are some bug report on android project page:
http://code.google.com/p/android/issues/detail?id=13046
but it was a pretty old issue and a final solution wasn't reached.
I'm wondering if anyone else has experienced similar issue and please offer some help. Thanks.
hope You will see icon and it will work.working on mine. APi Level 10
package com.example.locationsddf;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
LocationManager lm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView tv = (TextView) findViewById(R.id.tv);
lm = (LocationManager) getSystemService(LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
#Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onLocationChanged(Location arg0) {
tv.setText("Latitude: "+arg0.getLatitude()+" \nLongitude: "+arg0.getLongitude());
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.locationsddf"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="5"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.locationsddf.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
When icon is notified then you can just simply get the location by lm.getLastKnowLocationit will work
Sometimes there are issues with AVD itself. Try switching to another CPU architecture. I had similar issues and that was resolved by switching between ARM and Intel. Sometimes AVD with Google services enabled also helped
Also play around with "Allow Mock Locations" in Developers options
As an alternative, you could try this client:
https://github.com/RomanTheLegend/Pokemon_NoGo/tree/master/Sources/PokemonNoGo
I wrote it to play Pokemons, but it works with any GPS-based app. All it does is accept coordinates from desktop client and mocks main system GPS provider - LocationManager.GPS_PROVIDER
Last but not least: in AVD you can replay .kml files. There are many services which could help you generate one. Or just install "Lockito" and generate fake coordinates from Android
Related
I have been checking out and reading about Google Now on Tap (from http://developer.android.com/training/articles/assistant.html).
It was very interesting to find from that article that Now on Tap is based on Google's Assist API bundled with Marshmallow and it seems possible for us to develop our own assistant (the term Google used in the article to refer to app like Now on Tap) using the API.
However, the mentioned article only very briefly discusses how to use Assist API and I couldn't find any additional information about how to use it to develop a custom assistant even after spending a few days searching for it on the Internet. No documentation and no example.
I was wondering if any of you have experience with Assist API that you could share? Any help appreciated.
Thanks
You can definitely implement a personal assistant just like the Google Now on Tap using the Assist API starting Android 6.0. The official developer (http://developer.android.com/training/articles/assistant.html) guide tells exactly how you should implement it.
Some developers may wish to implement their own assistant. As shown in Figure 2, the active assistant app can be selected by the Android user. The assistant app must provide an implementation of VoiceInteractionSessionService and VoiceInteractionSession as shown in this example and it requires the BIND_VOICE_INTERACTION permission. It can then receive the text and view hierarchy represented as an instance of the AssistStructure in onHandleAssist(). The assistant receives the screenshot through onHandleScreenshot().
Commonsware has four demos for basic Assist API usage. The TapOffNow (https://github.com/commonsguy/cw-omnibus/tree/master/Assist/TapOffNow) should be enough to get you started.
You don't have to use the onHandleScreenshot() to get the relevant textual data, the AssistStructure in onHandleAssist() will give you a root ViewNode which usually contains all you can see on the screen.
You probably need to also implement some sorts of function to quickly locate the specific ViewNode that you want to focus on using recursive search on the children from this root ViewNode.
There is a complete example here but it's too complicated to start.
This is my example works on android 7.1.1
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.eaydin79.voiceinteraction">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:theme="#style/AppTheme" >
<service
android:name="voiceInteractionService"
android:permission="android.permission.BIND_VOICE_INTERACTION" >
<meta-data
android:name="android.voice_interaction"
android:resource="#xml/interaction_service" />
<intent-filter>
<action android:name="android.service.voice.VoiceInteractionService" />
</intent-filter>
</service>
<service
android:name="voiceInteractionSessionService"
android:permission="android.permission.BIND_VOICE_INTERACTION" >
</service>
</application>
</manifest>
this is interaction_service.xml file stored in res\xml folder
<?xml version="1.0" encoding="utf-8"?>
<voice-interaction-service xmlns:android="http://schemas.android.com/apk/res/android"
android:sessionService="com.eaydin79.voiceinteraction.voiceInteractionSessionService"
android:recognitionService="com.eaydin79.voiceinteraction.voiceInteractionService"
android:supportsAssist="true" />
voiceInteractionService.java
package com.eaydin79.voiceinteraction;
import android.service.voice.VoiceInteractionService;
import android.service.voice.VoiceInteractionSession;
public class voiceInteractionService extends VoiceInteractionService {
#Override
public void onReady() {
super.onReady();
}
}
voiceInteractionSessionService.java
package com.eaydin79.voiceinteraction;
import android.os.Bundle;
import android.service.voice.VoiceInteractionSession;
import android.service.voice.VoiceInteractionSessionService;
public class voiceInteractionSessionService extends VoiceInteractionSessionService {
#Override
public VoiceInteractionSession onNewSession(Bundle bundle) {
return new voiceInteractionSession(this);
}
}
voiceInteractionSession.java
package com.eaydin79.voiceinteraction;
import android.app.VoiceInteractor;
import android.content.Context;
import android.os.Bundle;
import android.service.voice.VoiceInteractionSession;
import android.media.AudioManager;
public class voiceInteractionSession extends VoiceInteractionSession {
voiceInteractionSession(Context context) {
super(context);
}
#Override
public void onShow(Bundle args, int showFlags) {
super.onShow(args, showFlags);
//whatever you want to do when you hold the home button
//i am using it to show volume control slider
AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
if (audioManager != null) audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_SAME, AudioManager.FLAG_SHOW_UI);
hide();
}
}
I am using Google API V2 in an Android application.
I want to get my current location and add a marker on it.
I am using my friend device. when I run the code, it shows me my-friend's house location. I am really shocked why.
could anyone please help me getting my current location..
Thats because you're first loading the LastKnownLocation, because it's your friends phone it will show your friend last known location (his house).
The code looks fine, I think you have to wait untill it finds the real location.
(make sure you got all permissions, and gps is on)
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
When you call locationManager.getLastKnownLocation(provider) your are retrieving the last location of the GPS that can be like you say when your friend was at home.
If you want to have the location where you are at, you should call requestSingleUpdate for just one time update or requestLocationUpdates for a continuous update.
An example for the one time update with a button listener:
btnupdate.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
locationManager.requestSingleUpdate(criteria, new LocationListener() {
#Override
public void onLocationChanged(Location location) {
}
#Override
public void onProviderEnabled(String provider) {
}
#Override
public void onProviderDisabled(String provider) {
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}, getMainLooper());
}
});
This implements a listener for the LocationManager, that gives you the posibility to do some actions depending of the Location status.
In your case, you have implemented the listener on the activity, so just try calling:
locationManager.requestSingleUpdate(criteria, this);
This request just single update to show your present location
I am coming with an answer to my question. I don't know if it will work with all people facing the same problem. I just tried to restart the mobile device. After it restarts, it gets the correct current location. So it was a hardware problem though I thought it is something in the code..
I've seen pictures of this elsewhere, but from some time back where the answer is generally "this is a known issue with Android 2.3" I'm using 4.4, so that's definitely not the answer.
I have about the simplest program ever: "Hello, Android". When I launch the emulator, it load up in portrait mode. Using Fn-Ctrl-F11 (Mac), the emulator rotates to landscape mode. But the application and the phone controls do not redraw - the whole thing just looks sideways.
Here's the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.helloandroid"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.test.helloandroid.Hello"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
and the Activity XML file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Hello" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</LinearLayout>
I'm building with Eclipse, the ADT bundle build v22.3.0-887826, although I can't imagine that matters for something this trivial.
My emulator is for device Galaxy Nexus, Android 4.4 API level 19. I've tried this with Hardware keyboard present marked and unmarked. I found reference to a "keyboard lid support" setting which I haven't seen anywhere - this comment is from 3/12 & so may be outdated.
This is my first Android app, so I'm a complete novice at debugging in this environment. TIA for any suggestions on what I'm missing.
EDIT: Adding code for hello.java
package com.test.helloandroid;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class Hello extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.hello, menu);
return true;
}
}
If you are beginner,you should go through this reference document to know about Activity lifecycle.
Here,I'm including few Log and Toast to make it easier to understand the process happens when you rotate the screen.
Example:
package com.test.helloandroid;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class Hello extends Activity {
private static final String TAG = "Hello";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello);
Log.d(TAG, "onCreate");
Toast.makeText(this, "onCreate", Toast.LENGTH_SHORT).show();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.hello, menu);
return true;
}
#Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume");
Toast.makeText(this, "onResume", Toast.LENGTH_SHORT).show();
}
#Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause");
Toast.makeText(this, "onPause", Toast.LENGTH_SHORT).show();
}
}
I hope it will be helpful !!
Apparently,everything old is new again: orientation change bug in 4.4
"The more they overthink the plumbing, the easier it is to stop up the drain."
It's good to know that I've not missed something obvious; OTOH this is a pretty obvious FAIL on the part of google's quality assurance... did bill gates sneak in there while no one was looking? Or are they greedy & trying to sell phones for testing by mucking up the emulators? Looks like there's a device in my future.
Edit :
Reference : Answered by CommonsWare,the Framework Engineer of Android.
Impossible to rotate the emulator with android 4.4
So i've just started to use the new Sony Xperia Tablet S Small App SDK. I'm no realy noob, developed many personal apps before but this has got me stumped.
I've loaded up the Sample project in Eclipse (all correctly configured), sorted some of the errors out, compiled to my device and when I launch the Small App from the launcher at the bottom of the device, it force closes - it's the same with every sample/app that I tried making with the SDK.
I'm attached below my MainApplication.java and AndroidManifest.xml in the hope that someone may be able to see where the issue lies. Don't understand as it's created as per the book. Any help really is appreciated please.
MainApplication.java:
package com.sony.thirdtest;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.view.View;
import android.widget.Toast;
import com.small.sonyapptest.R;
import com.sony.smallapp.SmallAppWindow;
import com.sony.smallapp.SmallApplication;
public class MainApplication extends SmallApplication {
private Configuration mConfig;
#Override
public void onCreate() {
super.onCreate();
mConfig = new Configuration(getResources().getConfiguration());
setContentView(R.layout.activity_main);
setTitle(R.string.app_name);
SmallAppWindow.Attributes attr = getWindow().getAttributes();
attr.minWidth = 200;
attr.minHeight = 200;
attr.width = 400;
attr.height = 300;
attr.flags |= SmallAppWindow.Attributes.FLAG_RESIZABLE;
getWindow().setAttributes(attr);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(MainApplication.this, R.string.hello, Toast.LENGTH_SHORT).show();
}
});
}
#Override
public void onDestroy() {
super.onDestroy();
}
#Override
public void onStart() {
super.onStart();
}
#Override
public void onStop() {
super.onStop();
}
#Override
protected boolean onSmallAppConfigurationChanged(Configuration newConfig) {
int diff = newConfig.diff(mConfig);
mConfig = new Configuration(getResources().getConfiguration());
// Avoid application from restarting when orientation changed
if ((diff & ActivityInfo.CONFIG_ORIENTATION) != 0) {
return true;
}
return super.onSmallAppConfigurationChanged(newConfig);
}
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.small.sonyapptest"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="com.sony.smallapp.permission.SMALLAPP" />
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name">
<uses-library android:name="com.sony.smallapp.framework" />
<service
android:name="com.small.sonyapptest.MainApplication"
android:exported="true" >
<intent-filter>
<action android:name="com.sony.smallapp.intent.action.MAIN" />
<category
android:name="com.sony.smallapp.intent.category.LAUNCHER" />
</intent-filter>
</service>
</application>
</manifest>
It seems that there is nothing wrong with your code. So I think the problem is with how you build the project. More exactly, how the small apps framework is included: it shouldn't be!
If you simply add the jar (from the Sony SDK) via "Java build path" -> "Add external Jar", then the classes of the api jar will be included with the application. The problem is those are only stub classes, so you can get one of two possible exceptions.
A simple and quick way to get around this (and still using the standard android sdk, and not switch to the Sony SDK) is the following:
Create a java project, and call it "SmallAppApi" for example
Inside the java project add the small app jar via "Add external jar"
In the last tab in the "Java build path" screen, called "Order and Export" make sure the small app jar is exported.
In the android project, in the "Java build path" screen, in "Projects" tab simply add the java project SmallAppApi (and remove the small app jar).
With this setup the small app jar will be used only when building. This worked fine for me.
In the service tag change android:name="com.small.sonyapptest.MainApplication" to android:name="MainApplication"
Thanks for the responses, all working now after chaning the service tag to just MainApplication.
I try to use the DDMS location mockup with a very simple Log.i() call in the functions of all LocationListener attributes. When I start the program I get the Log.i() message for onStatusChanged() in my LogCat, so I think that I registered the listener correctly. But when I put a location into the VM using the DDMS menus in Eclipse I get nothing. No change in LogCat, Console, or inside the VM. As if nothing happened at all.
How can I even start to find the problem?
Here is the code for my simple GPS Event logger:
public class gpsActivity extends Activity {
private static final String TAG="gpsActivity";
private static TextView label;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
label = (TextView) findViewById(R.id.label);
LocationManager manager = (LocationManager) this
.getSystemService(LOCATION_SERVICE);
LocationListener listener = new LocationListener() {
#Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
Log.i(TAG, "onStatusChanged: "+arg0);
}
#Override
public void onProviderEnabled(String arg0) {
Log.i(TAG, "onProviderEnabled: "+arg0);
}
#Override
public void onProviderDisabled(String arg0) {
Log.i(TAG, "onProviderDisabled: "+arg0);
}
#Override
public void onLocationChanged(Location location) {
Log.i(TAG, "onLocationChanged");
}
};
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2, 0,
listener);
setContentView(R.layout.main);
}
}
and here the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackage.example.gps"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".gpsActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Also as another side note, I am using a German Windows XP and found out that there are problems with GPS packages, because in a German system the number format for 1/2 is not 0.5 but 0,5 which leads to errors in the GPS parser grammar. But also changing my systems number format to English(US) didn't change that I don't get any message, exception or result at all.
Be sure that your device/emmulator is selected in the device menu of DDMS.
EDIT:
Oops. I should have seen these earlier:
You are using NETWORK_PROVIDER. In order to receive mock locations from DDMS (and I think also the command line through geo), you must register the GPS_PROVIDER. Your code works by changing the last line of the onCreate method:
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2, 0,
listener);
NETWORK_PROVIDER is signals through the phone network (e.g 3G) or WIFI
There where 3 problems involved. Because finding all of them took more then 12 hours of pure research time please excuse that I won't even try to find the according sources again.
The problems involved where:
You should use Google API <version> as target and not Android <version> because there are nesssesary things not activated in the latter.
You should send the updates via telnet and not DDMS because DDMS creates some uncertain, undocumented and not logged results, especially if you are using a non-US version of Windows.
The time zone in your emulator is automatically chosen, but maybe to the wrong locale (as mine is Germany, for example). You can switch it off inside a running emulator in the Android settings and also choose your correct locale. This only seems to appear in older versions of Android.
Good luck to everybody who tries his way to this kind of errors!