Does every android phone has streetview application by default? - android

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.

Related

Android get list of non Play Store apps

As a safety measure I would like to get the list of apps that aren't installed from the Play Store. Is there a way to do this?
The packageManager contains a method getInstalledApplications but I don't know which flags to add to get the list. Any help would be appreciated.
Edit: Here is an code example of v4_adi's answer.
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);
if (packageManager.getInstallerPackageName(packInfo.packageName) == null)
{
apps.add(packInfo.packageName);
}
}
return apps;
}
This is a good start, however this also returns a lot off pre-installed Android and Samsung apps. Is there anyway to remove them from the list? I only want user installed apps from unknown sources.
The following link has answer to your question
The PackageManager class supplies the getInstallerPackageName method that will tell you the package name of whatever installed the package you specify. Side-loaded apps will not contain a value.
How to know an application is installed from google play or side-load?
Originally I thought it would be enough to retrieve the apps that weren't installed via the Google Play Store. Later I found that I also needed to filter out the pre-installed system applications.
I found the last part of the puzzle in another post: Get list of Non System Applications
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;
}

Check whether whatsapp installed or not for particular mobile number

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;
}

How to check if an android device has Google Play installed?

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;
}

Determine that android package is preinstalled by vendor

I wonder whether there is a way to know that my app is preinstalled by vendor (and not installed from Android Market). Application is also available in Android Market and can be updated from there.
One solution is to create a file in the local file system (we can build a special app version for vendor). But there is a case that application can be updated from the market before its first run, and file is not created.
So is there any other way? Probably, installation path?
Also it's interesting whether Android Market app checks this preinstalled app for updates automatically like it's performed for Google Maps.
You have to get the ApplicationInfo of your package (with the PackageManager) and then check its flags.
import android.content.pm.ApplicationInfo;
if ((ApplicationInfo.FLAG_SYSTEM & myApplicationInfo.flags) != 0)
// It is a pre embedded application on the device.
For a more complete example, one could use this:
private String getAllPreInstalledApplications() {
String allPreInstalledApplications = "";
PackageManager pm = getPackageManager();
List<ApplicationInfo> installedApplications = pm
.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo applicationInfo : installedApplications) {
if (isApplicationPreInstalled(applicationInfo)) {
allPreInstalledApplications += applicationInfo.processName + "\n";
}
}
return allPreInstalledApplications;
}
private static boolean isApplicationPreInstalled(ApplicationInfo applicationInfo) {
if (applicationInfo != null) {
int allTheFlagsInHex = Integer.valueOf(
String.valueOf(applicationInfo.flags), 16);
/*
If flags is an uneven number, then it
is a preinstalled application, because in that case
ApplicationInfo.FLAG_SYSTEM ( == 0x00000001 )
is added to flags
*/
if ((allTheFlagsInHex % 2) != 0) {
return true;
}
}
return false;
}

How to check telephony and camera availability for SDK version < 5

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

Categories

Resources