how to check whether user has whatsapp installed or not???
I want app like whenever I click on users number it should display message whether that user has whatsapp or not...
please help me.I have listview of contacts info means name and number..I want to check whether that particular number has whatsapp installed or not on click of listview item????
Use packagemanager to get the installed app info:
for whatsapp package name is com.whatsapp
boolean installed = appInstalledOrNot("com.whatsapp"); //the method returns boolean value here
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
boolean app_installed;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
}
catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
public static boolean isInstalled(String packageName) {
if (StringUtils.equalsNull(packageName)) {
return false;
}
PackageManager pm = ContextProvider.getApplicationContext()
.getPackageManager();
List<PackageInfo> list = pm
.getInstalledPackages(PackageManager.PERMISSION_GRANTED);
for (PackageInfo p : list) {
if (packageName.equals(p.packageName)) {
return true;
}
}
return false;
}
Related
I am trying to check if the device has Google Play installed or not in my app, but seems there is no way to do that. I followed the post HERE but still doesn't work, always return true even i was testing with an emulator, it has com.android.vending installed. So am i checking the wrong package name? Any ideas for that?
Thanks in advance!
Follow Dcoumentation to check if the device has Google Play Service available.
In Short, simply:
// Getting status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
// Showing status
if(status==ConnectionResult.SUCCESS)
//Google Play Services are available
else{
//Google Play Services are not available
}
Hope this will help you :)
Finally, found a way to check Google Play installed, here is the code:
public static boolean isPackageInstalled(Context context) {
PackageManager pm = context.getPackageManager();
boolean app_installed = false;
try {
PackageInfo info = pm.getPackageInfo("com.android.vending", PackageManager.GET_ACTIVITIES);
String label = (String) info.applicationInfo.loadLabel(pm);
app_installed = (!TextUtils.isEmpty(label) && label.startsWith("Google Play"));
} catch(PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
Does every android phone with 2.3 and above has streetview by default or one have to download the streetview and install it. The reason I am asking is that I am using streetview in my application and I use
private boolean isIntentAvailable(Intent intent) {
final PackageManager packageManager = mapView.getContext().getPackageManager();
List<ResolveInfo> list =
packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
to see if streetview application is available in the device. The problem is that in one of mobile with android 4.1.1 streetview is available but still this method throws false for that. But it works in most of the devices that I have tested like in all Samsung , HTC and sony mobiles.
Not all android devices have Google apps. It depends of the constructor
[EDIT :]
to check if an app is installed, you may use :
appInstalledOrNot("com.google.android.apps.maps")
using the method:
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 ;
}
I read somewhere that all version of Maps have Street View, but I really can not confirm this, I am not sure.
I have to detect programatically weither google apps and google services are installed on a device or not.
A first solution is to use the packagemanager :
private static final String GooglePlayStorePackageNameOld = "com.google.market";
private static final String GooglePlayStorePackageNameNew = "com.google.vending";
void someMethod() {
packageManager = getApplication().getPackageManager();
List<PackageInfo> packages = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
for (PackageInfo packageInfo : packages) {
if (packageInfo.packageName.equals(GooglePlayStorePackageNameOld) ||
packageInfo.packageName.equals(GooglePlayStorePackageNameNew)) {
googlePlayStoreInstalled = true;
break;
}
}
}
But is there something more reliable ?
I find an other way in testing the result of a market intent
PackageManager pm = getPackageManager();
Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=dummy"));
List<ResolveInfo> list = pm.queryIntentActivities(market, 0);
if (list != null && list.size() > 0)
mMarketInstalled = true;
else
mMarketInstalled = false;
What do you think about this solution ?
Standard way of checking camera and telephony hardware availability works only since SDK >= 5:
PackageManager pm = this.getPackageManager();
boolean hasTelephony=pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
boolean hasCamera=pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
My problem that I need to runtime define availability of telephony and camera in SDK 3 (Android 1.5)
Any ideas?
P.S. I understand that Android 1.5 is very outdated, but still I do have bunch of customers running these devices, so I have to keep compatibility with them.
Well, I have found solution - very odd but it's working.
Basically method tries to get telephony service if it's null - it returns false, if it's not null (e.g. for HTC Flyer TelephonyManager is not null) method tries to run PackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY) using reflection, since this method is not available for old versions of SDK.
Here is a code:
private Boolean hasTelephony;
public boolean hasTelephony()
{
if(hasTelephony==null)
{
TelephonyManager tm=(TelephonyManager )this.getSystemService(Context.TELEPHONY_SERVICE);
if(tm==null)
{
hasTelephony=new Boolean(false);
return hasTelephony.booleanValue();
}
if(this.getSDKVersion() < 5)
{
hasTelephony=new Boolean(true);
return hasTelephony;
}
PackageManager pm = this.getPackageManager();
Method method=null;
if(pm==null)
return hasCamera=new Boolean(false);
else
{
try
{
Class[] parameters=new Class[1];
parameters[0]=String.class;
method=pm.getClass().getMethod("hasSystemFeature", parameters);
Object[] parm=new Object[1];
parm[0]=new String(PackageManager.FEATURE_TELEPHONY);
Object retValue=method.invoke(pm, parm);
if(retValue instanceof Boolean)
hasTelephony=new Boolean(((Boolean )retValue).booleanValue());
else
hasTelephony=new Boolean(false);
}
catch(Exception e)
{
hasTelephony=new Boolean(false);
}
}
}
return hasTelephony;
}
More or less the same approach is workable for checking of camera availability
How to get exactly "Unknown Sources" application list on Android?
what is flag to used? If it is not this method,what are others method? and
How to programmically?
PackageManager pm = this.getPackageManager();
final List<PackageInfo> appinstalled = pm
.getInstalledPackages(what is flag??); //
Sorry for my bad English.
Thank you.
Someone else may have a better solution, but here's the best I could come up with...
Iterate through all installed packages, comparing each one against a known "good" package that has a good signature, with checkSignatures(int, int) or checkSignatures(String, String). If the return value of checkSignatures is SIGNATURE_UNKNOWN_PACKAGE, then you've got a package from an unknown source.
Otherwise, it doesn't look like any of the flags to getInstalledPackages are intended to filter for unknown sources.
I know this is an old post but I think the following answer might help you:
https://stackoverflow.com/a/42248268/2212770
public static List<String> getAppsFromUnknownSources(Context context)
{
List<String> apps = new ArrayList<>();
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> packList = packageManager.getInstalledPackages(0);
for (int i = 0; i < packList.size(); i++)
{
PackageInfo packInfo = packList.get(i);
boolean hasEmptyInstallerPackageName = packageManager.
getInstallerPackageName(packageInfo.packageName) == null;
boolean isUserInstalledApp = (packageInfo.applicationInfo.flags &
ApplicationInfo.FLAG_SYSTEM) == 0;
if (hasEmptyInstallerPackageName && isUserInstalledApp)
{
apps.add(packInfo.packageName);
}
}
return apps;
}