Android - Facebook Intent to visit a certain Facebook page? [duplicate] - java

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Open Facebook page from Android app?
Does the Android Facebook app have Intents that other apps can use to start the Facebook app and goto a specific page?
For example, when someone clicks a certain button in my app, I want them to be taken to Facebook to a specific company's public Facebook page. Starting a web browser activity for this is easy, but more than likely the user is not logged in the browser etc...
I was thinking it would be nice if I could instead use an Intent (if one exists...) to start up the Facebook app and take the user to the specific page in the app. That way the user is already logged in and can interact with the page, Like it, etc...
Does an Intent like this exist? If so, where would I find more information on it? I've been looking through Facebook's developer documentation but I'm not seeing anything about this.

Go to https://graph.facebook.com/<user_name_here> (https://graph.facebook.com/fsintents for instance)
Copy your id
Use this method:
public static Intent getOpenFacebookIntent(Context context) {
try {
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/<id_here>"));
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<user_name_here>"));
}
}
This will open the Facebook app if the user has it installed. Otherwise, it will open Facebook in the browser.

Related

How do I know if the app has been downloaded from Google Play once

I have an Android mobile application that works with the membership system.
There are links to other mobile applications and games in my application.
With Packet Manager, I can check whether the application in the link is installed on the phone. My goal is to check whether users have downloaded the game and mobile applications on the device by clicking the links in my application.
If they downloaded the application in the given link once (first time), they will earn 10 points. If they download the same application many times, they will be considered as one time.
I wanted to ask you that If users download an app more than once, how do I count it just one time?
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
public void go(View view) {
boolean installed = appInstalledOrNot("com.dousoftware.pubgtyolar");
//loaded
if (installed) {
Toast.makeText(this, "Loaded", Toast.LENGTH_SHORT).show();
} else {
Intent viewIntent = new Intent("android.intent.action.VIEW",
Uri.parse("https://play.google.com/store/apps/details?
id = com.dousoftware.pubgtyolar "));
startActivity(viewIntent); Toast.makeText(this, "Not Loaded", Toast.LENGTH_SHORT).show();
}
}
The short answer is: you can't.
There is no way to know, locally, on an Android device, how many times the user installed or uninstalled an app.
The long answer is that there may be some workarounds, each with its own advantages and disadvantages.
While your app is installed, you could register to ACTION_PACKAGE_ADDED and ACTION_PACKAGE_REMOVED broadcasts.
These will be called every time the user installs or removes any app.
They have EXTRA_PACKAGE_NAME that contains the app package name.
This however, presents some problems:
This will only work while your app is installed and the user has opened your app at least once.
You will receive this broadcast for any app, and will have to filter the results yourself.
If the user clears data or uninstalls and reinstalls your app, you will lose count.
Another way, and how most apps do it, is by using a referral framework.
One example is Iron Source which will let you set up rewards for installing and using different apps.
If the other app is also yours, you can simply use Firebase.
Note however, that referral tracking compromises user privacy, so you have to be careful to comply with any local laws such as GDPR.
Also, using these frameworks may cost money.
If user click link
Check that user don't have this application
Redirect to store page.
Set in the config file that this link has been clicked
If user install application and Script triggers (eg on app opening) add points. Add points only if Link has been marked as clicked.
Mark the link in config file as used to not give more points from the same app.
You can store this data on your server to avoid eg uninstalling abuse
Simply save somewhere information that link has been used

How an app open custom action after install

Suppose an user wants to download a music from example.com. User goes to example.com from browser and clicks "download sample.mp3".Now instead of downloading the sample.mp3,the browser downloads an android app. When the user installs the app, the app downloads exactly the same 'sample.mp3' that the user clicked from the browser.
So, how do i make an app like this? Note: i can use download Api to download a music inside onCreate of the app without any views or anything.
But the key challenge here is to get the data that the user clicked in the browser (when my app was not even installed). Is it do-able somehow?
You can use firebase dynamic links for that.
You can pass the songId with the link and google play will pass that link into the app after installation. There you can extract the songId and start downloading the song.
One more advantage of the dynamic link is that google play will check if your app is already installed or not. If it is already installed then it will open the app directly else it will redirect to playstore page of the app.
To extract the songId in the app you can use below code:
FirebaseDynamicLinks.getInstance()
.getDynamicLink(getIntent())
.addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
#Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
// Get deep link from result (may be null if no link is found)
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
}
// Handle the deep link. For example, open the linked
// content, or apply promotional credit to the user's
// account.
}
})
.addOnFailureListener(this, new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.w(TAG, "getDynamicLink:onFailure", e);
}
});

How do I show all the Online users of my App in Android Studio linked with Firebase? [duplicate]

This question already has answers here:
Get Last Seen in chats application
(2 answers)
Online users in firebase chat app
(2 answers)
Closed 3 years ago.
I want to make an Online App in Android, and when you log in you can see a ListView of all the Users logged in the App. My problem is that I do not know how to show, for example, all the emails of the people who logged in with Google Account. I know how to do It with the people who register and log in with the app. But I want to do It with the Google Accounts.
Right now, when You login, It shows you your profile data like name, email, ID... etc. with this code:
private void handleSignInResult(GoogleSignInResult result) {
if (result.isSuccess()) {
GoogleSignInAccount account = result.getSignInAccount();
nameTextView.setText(account.getDisplayName());
emailTextView.setText(account.getEmail());
idTextView.setText(account.getId());
Glide.with(this).load(account.getPhotoUrl()).into(photoImageView);
}
else {
goLogInScreen();
}
but now, I want that when you login, appears in a ListView all the users online. Could you help me?
The solution for that is not to call user information for views directly from GoogleSignForResult. Instead of that the better practice for that will be making separate table in Firestore / Realtime called as Users (for example) and after User register save his info in that table and put a flag that he registered as Google user or email registration or other type of registration. And only after that when each user have flag of recognition you could inflate your list and show the type of registration.
So change the logic it will make that step more flexible for you

Google Play Games Android Sign In Getting Error Code 4

I am currently working on an Android app in which I want to use Google Play Games services (Achievements, Leaderboards, ...). After many iterations I finally got the code working to show the Google Play Games Login promt. The problem is now that after the user signs in it takes a while and then throws error code 4 with error message being empty. After doing a lot of research nothing really helped me solving this problem.
I have tried starting it directly out of Android Studio, installing the app manually or over Google Play, all on multiple devices, nothing worked.
Here's some code if required:
private static GoogleSignInClient mGoogleSignInClient;
...
#Override
protected void onCreate(Bundle savedInstanceState) {
...
mGoogleSignInClient = GoogleSignIn.getClient(this, new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).requestIdToken(getResources().getString(R.string.app_id)).build());
signInSilently(); // Can't be tested yet.
// isSignedIn() and loginDeclined are both false
if(!isSignedIn() && !loginDeclined) startSignInIntent();
}
...
private void startSignInIntent() {
startActivityForResult(mGoogleSignInClient.getSignInIntent(), RC_SIGN_IN);
loginDeclined = true;
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
// resultCode = 0
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task =
GoogleSignIn.getSignedInAccountFromIntent(intent);
try {
GoogleSignInAccount account = task.getResult(ApiException.class);
// Now this never happens :(
System.out.println("SUCCESS!");
} catch (ApiException apiException) {
System.out.println(apiException.getStatusCode() + " + " + apiException.getMessage());
// statusCode is 4, message is "4: "
String message = apiException.getMessage();
if (message == null || message.isEmpty()) {
message = "Error signing in to Google Play Games";
}
new android.app.AlertDialog.Builder(this)
.setMessage(message)
.setNeutralButton(android.R.string.ok, null)
.show();
}
}
}
Make sure that you use the SHA1 key.
The command "keytool -list -keystore [path to debug keystore]" may display a SHA-256 key.
To get your SHA1 key you can follow these steps:
Open your project
Click on "Gradle" (on the right side)
Choose your module
Tasks -> android -> (double click) signingReport
image: get your SHA1 key
After searching on the internet for hours and checking every step from the troubleshooting section in the google play game services documentation (https://developers.google.com/games/services/android/troubleshooting), I filled out the "OAuth Consent Screen" form and it finally worked.
Log in to the Google Play Console
Go to Game Services
Go to your game
On the Game Details page scroll all the way down to the linked API console project
Click the link to the linked API console project
Click "OAuth Conset Screen" in the left side bar
Choose external
Fill out the form and upload an icon
Send for verification
After that my Google Play Game Services Sign In worked instantly.
Please check the following details for GPG Sign in issues:
Make sure that you have followed the instructions to create your client IDs and configure the games services.
Your meta data Tag in manifest should match with your application's numeric ID, and it should only contain the numbers. Also double check your package name. Do not use the sample app package name. Use your own.
The certificate with which you are signing your game should match the certificate fingerprint associated to your client ID.
The last important thing, Check that test accounts are enabled. I keep forgetting this step.
Make sure that the fingerprint from App signing certificate matches with the linked apps from Game services. You can also verify these details by navigating to your Google API console -> Select your app -> Credentials -> OAuth 2.0 client IDs.
The other thing I noticed that, if the app is released, then you need to install the app from the Play Store for these credentials to work. If the app is not yet released, then make sure you are using the debug fingerprint and that matches in your Games services (Debug fingerprint).
As far as you have these fingerprints in place, you should be fine. If you are still having issues, I would recommend to go through the code lab to get step by step help on how to to extend an existing Unity game to run on an Android device and integrate Play Game Services.
https://codelabs.developers.google.com/codelabs/playservices_unity/index.html?index=..%2F..%2Findex#0
Or here are the sample apps to help with quick test -
https://github.com/playgameservices/android-basic-samples.
You can also help us with the logcat to better understand the issue.
Recently, I faced the problem when i was trying to write the user data on his drive using the saved game api. And i figured out the problem. Below are my observation hope it will help in general scenario:
You can test the play games api in debug build by adding testers in your play console.
If you want to test on signed apk, then you need to generate the SHA1 key by using your "app.keystore" keystore file and add the android app with this SHA1 key in play game services particular for that app. Now you would be able to get the expected result.(It was the problem in my case)
If you want to store the data on user drive, then you need to enable "saved games" api in play game services.
In my case everything looked fine but get error code, then i check Google Play Console> Play Game Service and publish the changes. The key is publishing things that i made.

How to kill Android process if user opens youtube [duplicate]

This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
How to restrict Android device to not open some specific site e.g.youtube, facebook
I am writing an application and a feature is that if the user opens youtube.com then not allow him to do this.
So I planned to kill the Android process if the user try to open it. I know that this code kills the process
android.os.Process.killProcess(pid);
but How can I get pid(process id) of process if it open youtube. The problem is to get process id which opens youtube.
I am writing an application and a feature is that if the user opens youtube.com then not allow him to do this.
Fortunately, malware authors have limited ability to do things like this.
So I planned to kill the Android browser process if the user try to open it.
Fortunately, this is impossible, at least on Android 2.1+.
I know that this code kills the process
Only if you have rights to kill that process. Fortunately, you do not have rights to kill that process.
If it is a webview they are opening the url in then you could use the public boolean shouldOverrideUrlLoading (WebView view, String url) this gives the host application a chance to take over the control when a new url is about to be loaded in the current WebView.
example:
WebViewClient yourWebClient = new WebViewClient()
{
// Override page
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
// This line we let me load only pages inside Firstdroid Webpage
if ( url.contains("youtube") == true )
//Load new URL & override URL Link
return true;
// Return false to not override url loading.
return false;
}
};

Categories

Resources