Hello all i am integrating ola money with in my android app now the problem i am facing is that in their docs it is given that first check for whether the app is installed and for that they have given below code to see that, now i am having ola cabs app installed in my android device but this function is returning false i dont know what i am doing wrong, if somebody has integrated ola in android please tellme how is it working for you
private boolean check_olacabs() {
try {
context.getPackageManager().getApplicationInfo("com.test.olacabs", 0);
return true;
} catch (Exception e) {
return false;
}
}
Thank you in advance
Replace your code with this.
private boolean check_olacabs() {
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo("com.olacabs.customer", PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
Related
I already add the search box and everything works well on every device with google maps installed, but when I try in a device with no google maps installed on it, the function doesn't work. I'm confused and try to add a waze deep links just in case if the device doesn't have google maps app so it might have waze. But waze deep link only works to direct to waze app. Any ideas or solution? I'm kinda confused cause not all Android device install google maps
hey Iganov you are right not all Android device install google maps. So you can check if the device is installed the maps application then only enable your search filed to work.
so you can create function to check as below
boolean GoogleMaps(String apk) {
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo(apk, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
}
return false;
}
then you can call it in your on create activity as below
boolean appavialble = GoogleMaps("com.check.application");
if(appavialble ) {
//do your searching condition here
} else {
//application not found force to download it or show alert
Uri.Builder uriBuilder = null;
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
uriBuilder =
Uri.parse("market://details").buildUpon().appendQueryParameter("id",
"com.check.application");
intent.setData(uriBuilder.build());
startActivity(intent);
}catch (Exception e){
system.out.println("error in connection");
}
}
Hope this helps.
I implement a drawing route app on GoogleMaps and that is working but first I need to check for GoogleMaps availablity on Android or not. If the app does not exist, the user should be directed to Google Play Store to install GoogleMaps.
How can I prompt the user to install it?
Try this:
private boolean isPackageInstalled(String packagename, PackageManager packageManager) {
try {
packageManager.getPackageInfo(packagename, 0);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
It attempts to fetch information about the package whose name you passed in. Failing that, if a NameNotFoundException was thrown, it means that no package with that name is installed, so we return false.
in your case
public void someMethod() {
// ...
String googleMapsPackageName = "com.google.android.apps.maps"
PackageManager pm = context.getPackageManager();
boolean isInstalled = isPackageInstalled(googleMapsPackageName, pm);
if(isInstalled)
// go to maps
else
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + googleMapsPackageName)));
// ...
}
Im currently developping an app in China. I have a small problem, on the chinese phones Google Maps is initially not installed but i need it for the application. For the users its no problem to install it but i want them to have a choice which market to use.
public void someButtonClicked(View v) {
if (!isGoogleMapsInstalled()){
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps"));
startActivity(intent);
}
}
public boolean isGoogleMapsInstalled()
{
try
{
ApplicationInfo info = getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0 );
return true;
}
catch(PackageManager.NameNotFoundException e)
{
return false;
}
}
this is what i have and actually it only opens the play store but i cannot decide which store to use.
As last sorry for my bad English.
In my application i need to check if on my devices is present "Amazon Appstore". How can I do this?
Guide Me. I have no idea. Thanks.
Try this
private boolean isAppInstalled(String packageName) {
PackageManager packageManager = getPackageManager();
boolean installed = false;
try {
packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
installed = true;
} catch (PackageManager.NameNotFoundException e) {
installed = false;
}
return installed;
}
Just get the package name and use package manager to get all the apps instead and check one by one with the package name you have. You can get package name from the google play link of the app you need.
Try to see here if could helps you: http://www.coderzheaven.com/2012/03/28/how-to-check-whether-an-application-is-installed-in-your-android-phone-2/
I am currently working on a project that i am trying to add an icon making competition and the winner will receive a special app plugin that only the contest winner will get and i would like my app to check if the package(special app plugin) exists on the users device and if it does i would like the app to display an alternate display on run-time.Would i use "if"
and "else" statements to achieve this and if so how would i go about this and Thanks in advanced.
Note:I have successfully made the app load a different layout depending on the android version so i have a little bit of an idea but need some help.
Check this to know app is installed or not..
public class Example extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Put the package name here...
boolean installed = appInstalledOrNot("com.Ch.Example.pack");
if(installed)
{
//This intent will help you to launch if the package is already installed
Intent LaunchIntent = getPackageManager()
.getLaunchIntentForPackage("com.Ch.Example.pack");
startActivity(LaunchIntent);
System.out.println("App already installed om your phone");
}
else
{
System.out.println("App is not installed om your phone");
}
}
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 ;
}
}
Well if your plugin has a unique name(i am sure it should) you can check it.
Please read the post linked below for checking whether the plugin exists or not
Link : https://stackoverflow.com/a/6758962/1542720
Hope this helps !
you can change your xml file according to your requirement in onCreate()..
as i did in my code, for the different density i used different xml file.
if (metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM) {
setContentView(R.layout.activity_main);
} else if (metrics.densityDpi == DisplayMetrics.DENSITY_LOW) {
setContentView(R.layout.activity_main_small);
} else {
setContentView(R.layout.activity_main_large);
}