I am trying to connect to Alexa Voice Service from an Android app following the directions on this page: https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/docs/authorizing-your-alexa-enabled-product-from-an-android-or-ios-mobile-app
Bundle options = new Bundle();
String scope_data = "{\"alexa:all\":{\"productID\":\"" + PRODUCT_ID +
"\", \"productInstanceAttributes\": {\"deviceSerialNumber\":\"" + PRODUCT_DSN + "\"}}}";
options.putString(AuthzConstants.BUNDLE_KEY.SCOPE_DATA.val, scope_data);
options.putBoolean(AuthzConstants.BUNDLE_KEY.GET_AUTH_CODE.val, true);
options.putString(AuthzConstants.BUNDLE_KEY.CODE_CHALLENGE.val, CODE_CHALLENGE);
options.putString(AuthzConstants.BUNDLE_KEY.CODE_CHALLENGE_METHOD.val, "S256");
mAuthManager.authorize(APP_SCOPES, options, new AuthorizeListener());
First, I don't know what APP_SCOPES should be. I set it to:
protected static final String[] APP_SCOPE = new String[]{"profile", "postal_code"};
but I get an error from the server
AuthError cat= INTERNAL type=ERROR_SERVER_REPSONSE - com.amazon.identity.auth.device.AuthError: Error=invalid_scope error_description=An unknown scope was requested
What am I doing wrong and how can I do this right?
The APP_SCOPE is : "alexa:all"
The PRODUCT_DSN can be anything you want, "1234" as per suggestion from Joshua Frank (https://forums.developer.amazon.com/forums/message.jspa?messageID=18973#18973)
The PRODUCT_ID is the ID in the AVS Developper Portal (https://developer.amazon.com/edw/home.html#/avs/list)
The CODE_CHALLENGE the Client Secret in the Security Profile of your application (should be already hashed in S256)
The problem is not with the APP_SCOPES variable, it is actually with the PRODUCT_ID, PRODUCT_DSN variables passed in the scope data.
I faced this exact same issue and have raised a query in amazon developers forum on what needs to be passed in those variables - Alexa authentication issue using beta SDK
Once the PRODUCT_ID, PRODUCT_DSN & CODE_CHALLENGE variables are determined then the authentication should be pretty much straight forward.
The APP_SCOPE should be "alexa:all"
I have searched quite a bit without luck so far.
The Android Geocoder returns the android.location.Address object.
The city, as far as I understood, should be returned in getLocality().
It seems within USA this works well, outside not.
I am writing an international app and struggle to find a solution to find out the city of a geolocation.
Here the output from Czech Republic/Prague :
Address[addressLines=
[0:"Psohlavců 1764/2",
1:"147 00 Prague-Prague 4",
2:"Czech Republic"],
feature=2,
admin=Hlavní město Praha,
sub-admin=Prague,
locality=null,
thoroughfare=Psohlavců,
postalCode=147 00,
countryCode=CZ,
countryName=Czech Republic,
hasLatitude=true,
latitude=50.0276543,
hasLongitude=true,
longitude=14.4183926,
phone=null,
url=null,
extras=null]
locality is null, the city is within sub-admin !
The address itself is ok, so the geocoder server seems to know the city.
Here some ore random EU examples but locality works partly:
Address[addressLines=[0:"Nad lesem 440/34",1:"147 00 Prague-Prague 4",2:"Czech Republic"],feature=34,admin=Hlavní město Praha,sub-admin=Prague,locality=null,thoroughfare=Nad lesem,postalCode=147 00,countryCode=CZ,countryName=Czech Republic,hasLatitude=true,latitude=50.02424,hasLongitude=true,longitude=14.4117568,phone=null,url=null,extras=null]
Address[addressLines=[0:"Hauner Straße 4",1:"84431 Heldenstein",2:"Germany"],feature=4,admin=null,sub-admin=null,locality=Heldenstein,thoroughfare=Hauner Straße,postalCode=84431,countryCode=DE,countryName=Germany,hasLatitude=true,latitude=48.2540274,hasLongitude=true,longitude=12.3413535,phone=null,url=null,extras=null]
Address[addressLines=[0:"Igler Straße",1:"6020 Innsbruck",2:"Austria"],feature=Igler Straße,admin=Tyrol,sub-admin=Innsbruck,locality=Innsbruck,thoroughfare=Igler Straße,postalCode=6020,countryCode=AT,countryName=Austria,hasLatitude=true,latitude=47.2465698,hasLongitude=true,longitude=11.4054237,phone=null,url=null,extras=null]
Address[addressLines=[0:"Durnberg 24",1:"5724 Stuhlfelden",2:"Austria"],feature=24,admin=Salzburg,sub-admin=Zell am See District,locality=null,thoroughfare=Durnberg,postalCode=5724,countryCode=AT,countryName=Austria,hasLatitude=true,latitude=47.3233373,hasLongitude=true,longitude=12.4960482,phone=null,url=null,extras=null]
Address[addressLines=[0:"U Roháčových kasáren 14",1:"100 00 Prague 10",2:"Czech Republic"],feature=14,admin=Hlavní město Praha,sub-admin=Prague,locality=Prague 10,thoroughfare=U Roháčových kasáren,postalCode=null,countryCode=CZ,countryName=Czech Republic,hasLatitude=true,latitude=50.0704092,hasLongitude=true,longitude=14.4673473,phone=null,url=null,extras=null]
Maybe the fault is on me, but to me it seems like depending on the country and area the city will be found in different fields.
However, the address itself mostly seems to be good enough to send a postal letter.
Has someone written a clever function which tries to make more sense out of the Geocoder results ? It's a pity to see that Google has the information stored but does not provide it properly.
Going to close my question, solved it with a workaround.
Using the suggestion from dannyroa
String city="unknown";
if (address.getLocality() != null) city=address.getLocality();
else
if (address.getSubAdminArea() != null) city=address.getSubAdminArea();
This could be further extended by getting the city information out of the second address line.
removing the postal code and taking the remainder, but this information is not unique within a city and could change depending on the district/zone.
Looking for some help regarding querying in different verions of Android. I have the following code that returns a cursor of bookmarks. I am trying to filter the browser to return only urls that are actual bookmarks, not just browser history. It works on version 3.1 but on my new Nexus 7, it will not filter by bookmark, but instead returns all browser history in the cursor. Any insight is much appreciated. I think I have run into issues with filtering and content resolver query's not paying attention to selection parameters but can't seem to find any info. Thanks.
String[] mColumnStrings =
{
Browser.BookmarkColumns.TITLE,
Browser.BookmarkColumns.URL,
Browser.BookmarkColumns._ID,
Browser.BookmarkColumns.BOOKMARK
};
try{
bookmarksCursor = getActivity().getContentResolver().query(Browser.BOOKMARKS_URI, mColumnStrings, Browser.BookmarkColumns.BOOKMARK+ " = 1 ", null , Browser.BookmarkColumns.URL + " ASC");
getActivity().startManagingCursor(bookmarksCursor);
return bookmarksCursor;
Its working fine for me...I tested it on AVD...actually Android 4.1 already have some default bookmarks...print the Browser.BookmarkColumns.BOOKMARK as well to verify weather the results are bookmarked or not...
You can use this method specifically for your to varify...
private void varify(Cursor bookmarksCursor) {
bookmarksCursor.moveToFirst();
while(bookmarksCursor.moveToNext()) {
Log.v("title", bookmarksCursor.getString(0));
Log.v("url", bookmarksCursor.getString(1));
Log.v("id", bookmarksCursor.getString(2));
Log.v("bookmark", bookmarksCursor.getString(3));
}
}
Hope this works...
If you decide that this answers your question, please mark it as "accepted". This will raise both your and my reputation score.
I am developing app which add contact info to android contact list .to How to add postal address to contacts in android programmatically ?
It's been a while that this has been asked but maybe someone else is still interested in it. How to add a contact with address info:
import static android.provider.ContactsContract.Data;
import static android.provider.ContactsContract.Intents.Insert;
private void createContactIntent() {
Intent contactIntent = new Intent(ContactsContract.Intents.Insert.ACTION, ContactsContract.Contacts.CONTENT_URI);
contactIntent.setType(ContactsContract.Contacts.CONTENT_TYPE);
contactIntent.putExtra(Insert.NAME, "Sergio Mendes");
contactIntent.putExtra(Insert.COMPANY, "Company One");
contactIntent.putExtra(Insert.POSTAL, "Street 1, 9999 City, Country");
contactIntent.putExtra(Data.IS_SUPER_PRIMARY, 1);
startActivity(contactIntent);
}
Note that some devices like Samsung S5 / A5 will put the whole address into the "street" field. If you have any optimizations for this let me know.
Postal address are stored like all the other info in the DATA table with a
MIMEtype == ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE
Please google ContactsContract.CommonDataKinds.StructuredPostalto find all the info.
If you need to know how to edit a contact in general I would suggest you to have a look to the SampleSyncAdapter in the Android SDK. It is a sync adapter so you don't need to study everything but updateContact in ContactManager is a good point to start with.
iam just practicing with phone gap for android app. I found a piece of code in docs.phonegap.com, regarding adding contacts
function onDeviceReady()
{
alert('onDeviceReady: PhoneGap1');
var myContact = navigator.contacts.create({"displayName": "Test User"});
alert('onDeviceReady: PhoneGap2');
myContact.gender = "male";
console.log("The contact, " + myContact.displayName + ", is of the " + myContact.gender + " gender");
}
When i run this i am getting only the alert box and the name is not added in my contacts. How to add the contacts....
Please tell me how to add data and open the device default contacts...
Simon Mac Donald has written a great blog post on contacts with PhoneGap and Android.
http://simonmacdonald.blogspot.com/2011/09/saving-contacts-with-phonegap-android.html
It should help you out as there are a few steps to it.
The quick answer for those of you searching, is that you have to call
myContact.save()
in order to persist the contact that you just created.