I am trying to implement the single sign on using GMail. Trying using this link https://developers.google.com/accounts/docs/MobileApps sample code. I was unable to get YOUR_AUTHENTICATION_ENDPOINT token key.
Here is my main.activity where I am using YOUR_AUTHENTICATION_ENDPOINT.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflating the menu resource.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Start the WebViewActivity to handle the authentication.
case R.id.login:
Intent intent = new Intent(this, WebViewActivity.class);
intent.setData(Uri.parse(YOUR_AUTHENTICATION_ENDPOINT));
startActivityForResult(intent, 0);
return true;
// Exit.
case R.id.exit:
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
app is while running I am getting this error :
04-02 15:09:12.271: E/Web Console(924): SyntaxError: Parse error at https://mail.google.com/mail/x/cc6i6zigt73b-/?pli=1&f=1&shva=1:1
For a google app-engine hosted account, the login URI is:
https://myapp.appspot.com/_ah/login?continue=REDIRECT
Where, myapp is your app's name and REDIRECT should be set to the domain where you will fetch further authenticated resources from. The cookies will be set accordingly by the authentication mechanism. https://myapp.appspot.com is what I use as the REDIRECT.
EDIT
I'm sorry, but I have misread your question. You wish to authenticate using the web-based authentication. I gave you the endpoint for authenticating with the google account on one's phone. For the web-based login URLs, you can use users.create_login_url() and users.create_logout_url(). More info here: https://developers.google.com/appengine/docs/python/users/loginurls
Related
I have a Recycle view set up that it's populated with user's post from Firebase. I would like to implement a feature that allows user's to remove their own post(Similar to Facebook or Instagram). So far I have written some code that allows a post to be removed, but any user have access to remove it.
//This is how my database is set up
Post
-LlISwmjd0pBXzkNHJGW (random push id)
desc: "Used textbook"
id: "Zk32WqxcCHbR1op6j9inFudFJF23"
image: "image link"
name: "user name"
profileimage: "profile image"
//This method allows a post to be removed
//Creates popup and allows user to delete from RecycleView
public void openOptionMenu(View v, final int position) {
PopupMenu popup = new PopupMenu(v.getContext(), v);
popup.getMenuInflater().inflate(R.menu.options_menu, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu1:
Toast.makeText(getApplicationContext(), "Edit clicked", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu2:
FirebaseDatabase.getInstance().getReference().child("Post").child(randomPostKeyId).removeValue();
postList.remove(position);
adapter.notifyDataSetChanged();
return true;
default:
//default intent
return true;
}
}
});
popup.show();
}
You can set Firebase Security rules so that only the owner can modify/delete the post.
Let's say every post has an attribute that contains User Id of the user who created it, if the name of key was ownerId then it would look like this:
{
// Allow anyone to read data, but only authenticated content owners can
// make changes to their data
"rules": {
"Post": {
"${postId}": {
".read": true,
// or ".read": "auth.uid != null" for only authenticated users
".write": "root.child('Post').child(postId).child('ownerId').val() == auth.uid"
}
}
}
}
Check out https://firebase.google.com/docs/rules for complete ddocumentation.
I'm not sure whether I understood your problem correctly. As per my understanding, you want show the delete option for a post if that post is created by the user interacting.
If thats the case, then add a check in the "openOptionMenu" method to see whether the post.name==currentUser.name. If yes, continue with what ever you are doing right now. Else inflate a new options menu with delete option not present.
Am using the Google+ login feature in my app. The Login functionality is in my LoginActivity, and the logout functionality is called from another activity, an Activity containing Fragments. To be able to call the logout method, the Activity containing the Fragments extends the Login Activity(else the app crashes). These methods are in the Login Activity:
// Initializing google plus api client (from onCreate method of Login Activity)
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
//Called when a connection is successful
public void onConnected(Bundle arg0) {
mSignInClicked = false;
Toast.makeText(this, "User is connected!", Toast.LENGTH_LONG).show();
//Get user's information
getProfileInformation();
Intent intent = new Intent(getApplicationContext(), UtilityActivity.class);
startActivity(intent);
}
When I run the app, the Toast is never dismissed.When I comment out the toast and run the app again, none of the widgets respond. Am thinking the app stays in an onConnected state?.
I don't know why this happening, but am suspecting it's because am calling the onCreate method or the onConnected method twice?
The call to signout is being made from the onOptionsItemsSelected method of the Activity containing the Fragments like this:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch (id) {
case R.id.action_settings:
Toast.makeText(getApplicationContext(), "Settings selected", Toast.LENGTH_LONG).show();
return true;
case R.id.action_logout:
signOutFromGooglePlus();
return true;
case R.id.action_revoke_access:
revokeGplusAccess();
return true;
}
Method called when the signin button is clicked:
private void signInWithGooglePlus() {
if (!mGoogleApiClient.isConnecting()) {
mSignInClicked = true;
resolveSignInError();
}
}
You mention that the issue is occurring in UtilityActivity, which is launched by LoginActivity in onConnect().
Your likely issue (without seeing the code in UtilityActivity) is that UtilityActivity does not have a reference to the connected GooogleApiClient from LoginActivity. So, while you have a valid connection in LoginActivity, you do not in UtilityActivity. Remember, extending LoginActivity doesn't mean you share its fields. It's more like sharing code w/o having to copy/paste.
There are several options on how to proceed - pass a copy of mGoogleApiClient in the Intent that launches UtilityActivity, make the activity that controls login/logout a service that all your other activities can use, pass only the information that UtilityActivity needs in an Intent when launched, have each Activity manage their GoogleApiClient connections directly...
I am having issues with some methods with my app in android. I'm trying to respond to a button pressed by a user. Here is the method:
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_search:
openSearch();
return true;
case R.id.action_settings:
openSettings();
return true;
default:
return super.onContextItemSelected(item);
}
}
I was looking at the docs provided from google about this and it says those methods should be called depending on the user's action. Am I missing something?
The error messages area:
Error:(42, 17) error: cannot find symbol method openSearch()
Error:(46, 17) error: cannot find symbol method openSettings()
Any help would be appreciated!
Thanks
You have not defined the methods openSettings() and openSearch() inside the Activity where you define onOptionsItemSelected.
The result of this is that the compiler will tell you that it cannot find symbol method openSearch() and cannot find symbol method openSettings()
You simply have to add the method declaration inside the Activity:
private void openSettings(){
//Execute relevant code
}
private void openSearch(){
//Execute relevant code
}
The above function doesn't get executed on Button pressed event. It is executed when user selected an item from menu.
At the moment, compiler doesn't know if such method signatures exist in the class. You would need to define the functions inside the class, then use them. I guess it will work fine.
I am attempting to verify if a user is logged in or not, and if not sending them to a log in page. I am using the log in page template from Android Dev. and trying to use an Intent to send either a Boolean or a value ( 1 for logged in 0 for not). Here is the part of the code in LoginActivity with the Intent:
for (String credential : DUMMY_CREDENTIALS) {
String[] pieces = credential.split(":");
if (pieces[0].equals(mEmail)) {
// Account exists, return true if the password matches.
return pieces[1].equals(mPassword);
final boolean logged_in = true;
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.putExtra("log", logged_in);
startActivity(intent);
}
here I am trying as a Boolean and I am getting the error Unreachable code for the line with final boolean Logged_in = true. When I try as an int
int logged_in =1;
I get the same error. All the questions asked on SO state that I needed to use the current class, LoginActivity.this, instead of just this. When I did use just this, I got another error entirely.
How do I send a value to my MainActivity class to show whether they are logged in or not?
return pieces[1].equals(mPassword);
return ends the method routine so everything after is not reachable.
Hi I´m new to Android and Eclipse. I have just following the tutorial from developer.android.com. Right now I´m in adding ActionBar
Right now I´m at this part
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_search:
openSearch();
return true;
case R.id.action_settings:
openSettings();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
I have received an error for openSearch() and openSettings(). It said that The method openSettings() is undefined for the type DisplayMessageActivity. What shoud I do now?
Thanks
openSearch() and openSettings() are methods that the author of the tutorial created in order to perform other operations. Search well into the code, there must be somewhere the declaration of those methods, if the author made them visible.
They should look something like this:
public void openSearch() {
//Do something here.
}
public void openSettings() {
//Do something here.
}
Replacing the //Do something here with the code implementation present in the tutorial.
Im up to the same section as you, they haven't provided the methods but you have to implement them as stated above.
However I found code to open up the device settings using this code in the switch;
case R.id.action_settings:
startActivity(new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS));
return true;
define them.
You're basing your code on an incomplete snippet. That snippet makes no expectation of what it means to search or create settings in your app... that's your job to implement. This snippet is only concerned about showing you how to establish the action bar, not the whole application.
The methods openSearch() and openSettings() should be defined. Use the following code. It'd help..
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch(id){
case R.id.action_search :
startActivity(new Intent(Settings.ACTION_SEARCH_SETTINGS));
return true;
case R.id.action_settings :
startActivity(new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS));
return true;
default :
return super.onOptionsItemSelected(item);
}
}
Maybe you should code those methods?
private void openSearch(){
//your code here
}
private void openSettings(){
//your code here
}
Those two methods are just examples how selecting an option can start an action. The implementation was not provided because it was irrelevant to the example. Note that it is not a tutorial, but a single and un-compile-able example of how to add behavior to an options item.