If you have created an Android Application with Twitter App integration, i.e. say the user can send tweets of highest scores earned while playing your game app. Then before sending a tweet out its better to detect if the Twitter application is being present on the device.
To check if the Twitter app is installed we first need to know what is the package name of the app, you can get it to form PlayStore link for Twitter for Android.
Package name : com.twitter.android
ApplicationInfo class is used to get information about an app that is being installed on the device. This information is collect from the AndroidManifest.xml <application> tag.
getApplicationInfo() method will retrieve all the information for the package/application name passed. It returns the ApplicationInfo object that contains details about the package.
⚠️ This package throws PackageManager.NameNotFoundException
public boolean isTwitterInstalled() {
try {
boolean twitterInstalled = false;
PackageInfo packageInfo = getPackageManager().getPackageInfo("com.twitter.android", 0);
String getPackageName = packageInfo.toString();
if (getPackageName.equals("com.twitter.android")) {
Toast.makeText(this, "Twitter App is installed on device!", Toast.LENGTH_LONG).show();
twitterInstalled = true;
}
} catch (PackageManager.NameNotFoundException e) {
Toast.makeText(this, "Twitter App not found on device!", Toast.LENGTH_LONG).show();
}
}
- Change Android Toast background color
- Maven : java.lang.ClassNotFoundException: Xmx512m
- This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) Lint Error
- Android Alert Dialog with Checkboxes example
- Android Error Generating Final Archive - Debug Certificate Expired
- How to add Newline to text in Android TextView
- Read Text file from SD Card : Android Programming
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException
- ActivityManager Warning: Activity not started, its current task has been brought to the front
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error
- Android Developers Bluetooth Tutorial
- java.lang.ClassNotFoundException android.support.v7.widget.Toolbar [Fix]
- Android: Save Data in local Db using Android Room
- Channel 50 SMSes received every few minutes Android Phones
- 21 Useful Android Emulator Short-cut Keyboard Keys
- Changing Android Intent Tittle using java code
- Android : No Launcher activity found! Error
- How to change TextView or EditText Text Color on Focus and on Press
- How to display Toast on Button Click : Android
- Android : Execute some code after back button is pressed
- Stop android adb service from command prompt or terminal
- [Soluiton] You already have the latest version of Android Studio installed
- Create Custom Android AlertDialog
- Android R Cannot Be Resolved To A Variable
- How to make Android EditText not editable
- incorrect line ending: found carriage return (\r) without corresponding newline (\n) - Android
- Upload Pdf file using PHP Script - PHP
- Fix zsh: permission denied: script.sh - zsh
- 3 Commands to stop Nginx Server - Linux
- Steps to Compare Two files in Sublime Text Side-by-Side - Sublime-Text
- Android : IOException: Unable to open sync connection! - Android
- Send Email using SharePoint PowerShell command, SMTP server - SharePoint
- How to install pip on macOS using terminal command [Python] - Python