PLACES_API_ACCESS_NOT_CONFIGURED with unrestricted key - android

I am trying to implement places autocomplete widget in my app, but when I open the widget it instantly closes and outputs in the logcat:
E/Places: Autocomplete widget closing due to PLACES_API_ACCESS_NOT_CONFIGURED
It correctly identifies the key in the AndroidManifest.xml. The API key is unrestricted, so that can't be the problem.
My code:
place.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
Intent intent =
new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
.build(getActivity());
startActivityForResult(intent, 1);
} catch (GooglePlayServicesRepairableException e) {
Toast.makeText(getActivity(), "GooglePlayServicesRepairableException",
Toast.LENGTH_LONG).show();
} catch (GooglePlayServicesNotAvailableException e) {
Toast.makeText(getActivity(), "GooglePlayServicesNotAvailableException",
Toast.LENGTH_LONG).show();
}
}
});

So if anyone is facing the same issue, I solved it by going to the API Dashboard and enabling Places SDK for Android. Only enabling the Places API is not enough and the error messages and instructions weren't clear to me.

Thanks. Add following to the AndroidManifest.xml
<meta-data
android:name="com.google.android.places.API_KEY"
android:value=<your api key>/>

Related

Default Messenger app is not Opening

I am working on Messages and issue which i am facing here is default messenger app is not opening in Lenovo K8 Note (7.1.1) on tapping the button and this issue occurs only in this device.I analysed forums but i didnt get a proper solution.Suggest me how to resolve this issue.
chat.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
Intent sms = new Intent(Intent.ACTION_VIEW);
sms.setType("vnd.android-dir/mms-sms");
sms.putExtra("sms_body_popup",
getResources()
.getString(R.string.custom_refer_message_chat)
+ "\n" + str_url);
startActivity(sms);
} catch (Exception e) {
Toast.makeText(
getApplicationContext(),
getResources()
.getString(R.string.no_default_apps),
Toast.LENGTH_LONG).show();
}
}
});
To answer your question, Can i expect some code snippet for your query.

Google Place API for Android: can't select place with the picker of Place Picker

I added to my android application Place Picker. When you know the address of the place you want to pick and fill the research bar, it works.
But I want that the user has the possibility to choose the place of his choice in using the red picker and this part doesn't work.
When you pick a place with the red picker and click "Select this location" like here.
We can't select the place. The "Select" button is greyed out. Like you can observe here.
Of course I have enabled the Google Place Android API and Google Maps Android API on the Google Developer Console.
I searched the reason (and a solution) on stackoverflow. I found some posts saying to put the API key that we can found on the google developer console inside:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
I did it but no positive result.
Then I tried to do again the implementation of Place Picker from scratch, without success.
This is the code where I use Place Picker:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_location);
Button chooseLocationButton = (Button) findViewById(R.id.choose_location);
PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
try {
final Intent intent = intentBuilder.build(this);
chooseLocationButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivityForResult(intent, REQUEST_PLACE_PICKER);
}
});
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
// TODO handle exception!
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
// TODO handle exception!
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_PLACE_PICKER) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(data, this);
String toast = String.format("Place: %s", place.getName());
longitude = place.getLatLng().longitude;
latitude = place.getLatLng().latitude;
Toast.makeText(this, toast, Toast.LENGTH_LONG).show();
}
}
}
I don't find anymore solution to try on the internet. It's why I write this question. Does anybody have any idea why this doesn't work?
Thank you.
I think you haven't enabled "Google Places API for Android" in your API console, Enable it. I have faced same problem once. I solved using the above solution.

Android can't find method removeAccount

I have implemented accounts for my app following this tutorial http://blog.udinic.com/2013/04/24/write-your-own-android-authenticator/
Every aspect of the implementation works great except when I try to remove the account with the following code:
public void logout(View view) {
// remove account and restart app
stopService(new Intent(this, ServerSync.class));
Account account = AccountManager.get(this).getAccountsByType(Constants.ACCOUNT_TYPE)[0];
final AccountManagerFuture<Bundle> future = AccountManager.get(this).removeAccount(account, this, new AccountManagerCallback<Bundle>() {
#Override
public void run(AccountManagerFuture<Bundle> future) {
try {
future.getResult();
} catch (Exception e) {
e.printStackTrace();
} finally {
Intent intent = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getBaseContext().getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(intent);
}
}
}, null);
}
When called this produces
NoSuchMethodError: android.accounts.AccountManager.removeAccount
and the app crashes.
I have followed the Android documentation
http://developer.android.com/reference/android/accounts/AccountManager.html
and my app has the correct permissions etc. I even tried overriding getAccountRemovalAllowed in my AccountAuthenticator, forcing it to return true.
Is there some other information missing from the Android documentation?
the version of removeAccount you are using was introduced with the api leve 22 and you are probably using it on a version of Android older than it. You should check the current version at runtime and use the deprecated version of removeAccount for devices with version of Android older than 22
removeAccount (Account account, AccountManagerCallback callback, Handler handler)
if (Build.VERSION.SDK_INT < 22) {
AccountManager.get(this).removeAccount(account, new AccountManagerCallback<Bundle>(){....}, null)
} else {
// the version you are already using
}

chromecast "failed to start application: no application is running" after called startSession()

I'm testing playing online video using chromecast.
After onRouteSelected(), I create the ApplicationSession and attach a MediaProtocalMessageStream;
Then I called mSession.startSession(); with no APP_ID, so I assume the build-in app inside chromecast play the video for me. This code works perfect and I can play online mp4 videos without writing my own receiver.
But, When I try to leave the video play app, I can't go back anymore, there is always an error message comes from onSessionStartFailed() which says
StartSessionTask failed with error: failed to start application: no
application is running
I don't remember how the first time I got into the video play app, which I don't leave for few day.
But I do know how I leave it, Here is what I did before I can never startSession again:
open Youtube app, get a deviced connected
play some youtube videos
disconnected from a chormecast, then the chromecast return to the starting page
So, doesn't anybody know what's going on here? How to open the build-in video app again?
By the way, My chromecast get a system update just after I return to the starting page, I don't know if google update something cause startSession() fail.
Below is the code I startSession and attach a mediaStream.
mSession = new ApplicationSession(mCastContext, mSelectedDevice);
ApplicationSession.Listener listener = new ApplicationSession.Listener() {
#Override
public void onSessionStarted(ApplicationMetadata appMetadata) {
mChannel = mSession.getChannel();
mStream = new MediaProtocolMessageStream();
mChannel.attachMessageStream(mStream);
if (mStream.getPlayerState() == null) {
ContentMetadata metaData = new ContentMetadata();
metaData.setTitle("Test Video");
String url = "http://www.auby.no/files/video_tests/h264_720p_hp_5.1_6mbps_ac3_planet.mp4";
try {
mCommand = mStream.loadMedia(url, metaData, true);
mCommand.setListener(new MediaProtocolCommand.Listener() {
#Override
public void onCompleted(MediaProtocolCommand arg0) {
onSetVolume(0.5);
}
#Override
public void onCancelled(MediaProtocolCommand arg0) {
}
});
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
#Override
public void onSessionStartFailed(SessionError error) {
Log.d("TEST", "Session Started failed");
}
#Override
public void onSessionEnded(SessionError error) {
Log.d("TEST", "Session Started end");
}
};
mSession.setListener(listener);
try {
mSession.startSession();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
You will have to use your own app id and own receiver. Google's default receiver doesn't play video streams anymore (it used to). It only handles Chrome tab mirroring now.

Facebook with Android: unexpected NullPointerException

I have some code that connects my app to Facebook. When you log in you proceed to the next activity. If you are already logged in when you start the app you miss out the log in section. On the following page I want to be able to log out, every time I press logout I get a null pointer. Can anyone help?
My code for log out is:
private void logout() {
try {
facebookConnector.getFacebook().logout(getApplicationContext());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
The code that is run when the app is started to check if the person has logged on is:
if (facebookConnector.getFacebook().isSessionValid()) {
Intent i = new Intent(facebook.this, facebook2.class);
startActivity(i);
finish();
}
A print screen of my error can be seen here:
Any help would be great. If you need more info please comment and I will provide asap.
facebookConnector.getFacebook() seems to return null

Categories

Resources