How to open a specific facebook page from my app? - java

I'm developing a material design app.
I want to open my app's facebook page when user clicks on the 'like on facebook' text (layout) in my app.
I've managed to open the facebook app but I am unable to figure out how can I open my page directly!
Here's what I've done so far:
LinearLayout linearLayoutFacebookContainer = (LinearLayout) findViewById(R.id.facebook_container);
linearLayoutFacebookContainer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final Handler handler3 = new Handler();
handler3.postDelayed(new Runnable() {
#Override
public void run() {
Intent facebookIntent = getPackageManager().getLaunchIntentForPackage("com.facebook.katana");
if (facebookIntent != null) {
// We found the activity now start the activity
facebookIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
facebookIntent.setData(Uri.parse("https://www.facebook.com/HumaneHelper/"));
startActivity(facebookIntent);
} else {
// Bring user to the market or let them choose an app?
facebookIntent = new Intent(Intent.ACTION_VIEW);
facebookIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
facebookIntent.setData(Uri.parse("https://www.facebook.com/HumaneHelper/"));
startActivity(facebookIntent);
}
}
}, 200);
}
});
Please let me know.
I'm a beginner, please cooperate.
Thanks in advance.

fb://page/{id} is the way to go:
final String url = "fb://page/" + facebookID
Intent facebookAppIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
facebookAppIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(facebookAppIntent);
Are you sure you are using the ID number of your Facebook page and NOT the username?
What I mean is that if, for example, you want to open the Facebook page of Facebook itself (i.e. https://www.facebook.com/facebook) you have to use:
fb://page/20531316728
Since 20531316728 is the ID of the Facebook page (while facebook is the username).
If you don't know the ID of your Facebook page, you can retrieve it opening:
https://graph.facebook.com/{username}
Courtesy: Open Facebook page via Facebook app

Related

"market://details?id=" + appPackageName opens the app not the playstore page

i asked a question on how should i open the playstore page using an app link on my app. i got an answer to use "market://details?id=" + appPackageName to open the play store app but instead of opening the playstore page its re opening my app. whats the fix?
enter code here
protected void Updateclick(View view) {
String appPackageName="io.kodular.samithuaz.smartQ";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
}
Try this.You need to specify proper store URI for the different stores.
take reference link
protected void Updateclick(View view) {
final String appPackageName = getPackageName();
try {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
}
what i was using was an image click that why it didnt worked. when i used a button click it worked.

issues in integrating gmail login in android app?

i want to make a swiggy type app. i have integrated gmail login in my login screen and it changes to dashboard activity on success but when i click on account tab it goes back to dashboard screen instead of account activity. pls help......
login screen
dashboard
if you want any portion of code just comment and i will update
//login screen part
//check if already signed in using google
account = GoogleSignIn.getLastSignedInAccount(this);
if(account!=null) {
finish();
Intent intent = new Intent(this, DashboardActivity.class);
startActivity(intent);
return;
}
//onclicklistener added
//method
private void googleSignin() {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
onActivity result(//params provided){
if(googleLogin){
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
googleLogin = false; //set to false so that it can be set true again if login is actually successful
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}
}
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
// Signed in successfully, show authenticated UI.
sessionManager.setLogin(true);
googleLogin = true;
Intent intent = new Intent(this,DashboardActivity.class);
intent.putExtra("googleLogin", googleLogin);
startActivity(intent);
finish();
}
//Dashboard part
Intent i = new Intent(DashboardActivity.this ,MyAccountActivity.class);
i.putExtra("googleLogin", googleLogin);
startActivity(i);
//myaccount part
if(googleLogin){
GoogleSignInAccount acct = GoogleSignIn.getLastSignedInAccount(this);
if (acct != null) {
String personName = acct.getDisplayName();
//System.out.println(personName); working fine
account_name.setText(personName);
String personEmail = acct.getEmail();
//System.out.println(personEmail); fine
account_email.setText(personEmail);
account_mobile.setText("+91 1234567890");
// System.out.println(googleLogin);
// System.out.println(fbLogin);
}
}
solved this problem.
the issue was gmail was not able to provide account details for use when i tried to display them in MY ACCOUNT activity that i integrated in my app, thats why it kept on getting crashed. the code was correct thats why it wasnt giving any error i even tried logging it. there it showed correct details but still it wasnt displaying the result in text views.
so what i did was use shared preferences. everytime the user logs in using gmail, the details are stored in them and i retrieve it in MY ACCOUNT activity and yes it displayed the results correctly.
let me know if you need any more help.

Intent ACTION_SEND doesn't show every browser

I have a button which fires a ACTION_SEND intent when clicked as below:
private static final String WEB_URL = "https://www.google.ca/";
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, WEB_URL);
intent.setType("text/plain");
startActivity(Intent.createChooser(intent, "CHOOOOOSE"));
}
Currently, it has some other apps, 'Copy to clipboard', and 'Add to Firefox' which can be used to open the link in Firefox. However, I want to let a user to decide which browser app to use to open the link but 'Add to Firefox' seems to be the only option right now when this device I am using has 'Chrome' and 'Internet' applications as well.
Ultimately, what I want is a share button, and on a click event, it shows all installed browser app like chrome, firefox, 'internet', etc., 'Copy to clipboard', and any other apps(<- these are not necessary, though).
Showing all browser apps, and a button to 'Copy to clipboard' is what I essentially want.
The 'WEB_URL' string is always going to be a proper url.
How do I achieve this?
EDIT
To sum up:
I want to have a list of apps shown by 'Intent.createChooser()' whose list consist of ALL browser apps AND a 'Copy to clipboard' option.
I tried using Intent.ACTION_VIEW with intent.setData(Uri.parse(url)) but then in this case, it doesn't have the 'Copy to clipboard' option.
Solution
I was able to achieve what I wanted above after some research.
The key is to use 'Intent.EXTRA_INITIAL_INTENTS' and a custom Activity.
SomeActivity's onClick Event
private static final String WEB_URL = "https://www.google.ca/";
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(WEB_URL));
Intent clipboardIntent = new Intent(SomeActivity.this, CopyToClipboardActivity.class);
clipboardIntent.setData(Uri.parse(WEB_URL));
Intent chooserIntent = Intent.createChooser(intent, "Custom Title...");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {clipboardIntent});
startActivity(chooserIntent);
}
Add 'CopyToClipboardActivity' to Manifest
<activity android:name=".activities.CopyToClipboardActivity"
android:exported="false"
android:icon="#drawable/someIcon"
android:label="#string/copy_to_clipboard"
android:theme="#android:style/Theme.NoDisplay"/>
CopyToClipboardActivity.java
public class CopyToClipboardActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Uri uri = getIntent().getData();
if (uri != null) {
copyTextToClipboard(uri.toString());
Toast.makeText(this, "Link copied to clipboard", Toast.LENGTH_SHORT).show();
}
// Finish right away. We don't want to actually display a UI.
finish();
}
private void copyTextToClipboard(String url) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("URL", url);
clipboard.setPrimaryClip(clip);
}
}

How to open "save to android pay" url from android app?

Now I'm in the following situation: our server sends ready-for-use JWT hash for current user card, but there are seems to no way to open "save to android pay" url from android app button: there are only web applications integration tutorial: https://developers.google.com/save-to-android-pay/reference/s2w-reference
So, I have to some way render this html: <g:savetoandroidpay jwt="JWT" onsuccess="successHandler" onfailure="failureHandler" /> into button and handle javascript callbacks from Java.
Or, maybe, there are some another way?
Uri androidPayUri = Uri.parse("https://www.android.com/payapp/savetoandroidpay/" + jwt);
Intent intent = new Intent(Intent.ACTION_VIEW, androidPayUri);
...
Here you can find an example JWT to test:
https://developers.google.com/save-to-android-pay/reference/s2w-reference
I found the "email link" way to do this, it can be used for Android app too:
addToAndroidPay.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.android.com/payapp/savetoandroidpay/" + token));
startActivity(intent);
}
});

Create Session with Android Java Firebase

I am using email and password. I have create user and authenticate user but I don't know how to add a session for this user.
For example, if the user logs into his/her account. He/she is able to delete the application's process on their phone when they do not want to use the app, then get rid of the app's process and the session is should still be ongoing, therefore when they go back to their application they should still be logged in until he/she logs out (unauth).
I am having trouble making a session for a logged in user. I believe a token must be used but I have no idea how I should use it.
Login Activity:
Firebase user_data = new Firebase("https://myapp.firebaseio.com");
user_data.authWithPassword(login_email.getText().toString(), login_pwd.getText().toString(), new Firebase.AuthResultHandler() {
#Override
public void onAuthenticated(AuthData authData) {
System.out.println("User ID: " + authData.getUid() + ", Provider: " + authData.getProvider());
Toast.makeText(getBaseContext(), "Login success!", Toast.LENGTH_LONG).show();
Intent toMainActivity = new Intent(getApplicationContext(), MainActivity.class);
startActivity(toMainActivity);
}
#Override
public void onAuthenticationError(FirebaseError firebaseError) {
// there was an error
System.out.println("ERROR.........................................");
}
});
Heres a simple scenerio:
User logs in. (From Login class is being Intent to Main activity class)
User does not log out but delete app's process.
Later User decides to use the app.
My problem: When click on app, it brings the user back to the Login page whereas it should brought the user to the Main Activity page.
Updated - Initialization
I have initialize it's still not saving the logged in state.
My problem: When click on app, it brings the user back to the Login page whereas it should brought the user to the Main Activity page.
Here's the Main Activity page:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Firebase.setAndroidContext(this);
setContentView(R.layout.activity_main);
Firebase user_data = new Firebase("https://myapp.firebaseio.com");
user_data.addAuthStateListener(new Firebase.AuthStateListener() {
#Override
public void onAuthStateChanged(AuthData authData) {
if (authData != null) {
System.out.println("Authentication is currently working"); //this did print
} else {
System.out.println("Failed authentication");
}
}
});
AuthData authData = user_data.getAuth();
if (authData != null) {
System.out.println("The state is: " + authData); //this did print
} else {
System.out.println("Failed");
}
I check the authentication and they seem to be fine but when I delete the process after logging in at the Main Activity it jumps back to the Login page when I reload the app.
The results for monitoring the auth data above:
working auth
Authentication is currently working
state
The state is: AuthData{uid='simplelogin:3', provider='password', token='***', expires='1426758087', auth='{provider=password, uid=simplelogin:3}', providerData='{email=du16493#gmail.com, isTemporaryPassword=false}'}
Authentication is currently working
SOLVED
Just add the intent if authentication is currently running and it should straight back into the Main activity when the app first loads up on your phone at your first activity you called.
Here's the Login Activity page:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Firebase.setAndroidContext(this);
setContentView(R.layout.activity_main);
Firebase user_data = new Firebase("https://myapp.firebaseio.com");
user_data.addAuthStateListener(new Firebase.AuthStateListener() {
#Override
public void onAuthStateChanged(AuthData authData) {
if (authData != null) {
System.out.println("Authentication is currently working"); //this did print
Intent toMainActivity = new Intent( getBaseContext(), MainActivity.class);
startActivity(toMainActivity);
} else {
System.out.println("Failed authentication");
}
}
});
AuthData authData = user_data.getAuth();
if (authData != null) {
System.out.println("The state is: " + authData); //this did print
} else {
System.out.println("Failed");
}
In order for authentication sessions to be persisted across application restarts, you'll need to initialize the Firebase Android client library with you Android context:
From https://www.firebase.com/docs/android/guide/setup.html:
The Firebase library must be initialized once with an Android context.
This must happen before any Firebase reference is created or used. You
can add the Firebase setup code to your Android Application's or
Activity's onCreate method.
#Override
public void onCreate() {
super.onCreate();
Firebase.setAndroidContext(this);
// other setup code
}
The Firebase client will automatically be authenticated on subsequent application cold starts. To check authentication state, see Firebase Android: Monitoring Authentication.

Categories

Resources