Adding search box on map with google api android - android

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.

Related

Integrating Ola money api in android always getting app not installed?

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

Facebook Android App Link

I have a new app and I'm trying to implement it to "Call to Action" facebook page button, but I have no idea what I shall write in the "App link" text box.
They put an example link of: example://location/123456
But I have no idea what it's refering to or what's the App Link of my app.
Tried to find anything about it on the Internet but couldn't find any helpful solution since I have no app links in my app (no products etc)
My goal is that when the user clicks on Facebook "Use App", it will redirect him to the app or the google play store app page if it's not installed..
I'm not talking about open app in my app, im talking about open my app in my facebook page
You can use the next code from the wiki:
/** Open another app.
* #param context current Context, like Activity, App, or Service
* #param packageName the full package name of the app to open
* #return true if likely successful, false if unsuccessful
*/
public static boolean openApp(Context context, String packageName) {
PackageManager manager = context.getPackageManager();
try {
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i == null) {
return false;
//throw new PackageManager.NameNotFoundException();
}
i.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(i);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
Example usage:
openApp(this, "com.google.android.maps.mytracks");
You can read it from here
To post a message in FB, see the next post, maybe it will be useful How to open the Facebook Write Post with some pre defined text and image
You should use Try/Catch. if user have Facebook app, fb://page/12345 link will open in app. Else, Catch code will run.
#Override
public void onClick(View v) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse("fb://page/12345"))); //12345 is Facebook page number
} catch (Exception e) {
//open play link in browser
startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse("http://play.google.com/etc")));
}
}

Open Facebook User Profile Android

When I try to open a Facebook Profile through the official Facebook App i have this error: error loading the biography, the content is not available.
I tried with many codes but nothing. Only if Facebook App is not installed on the device work right with the browser.
Here is the current code:
try
{
Intent followIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/"+id_facebook));
startActivity(followIntent);
final Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
#Override
public void run() {
Intent followIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/"+id_facebook));
startActivity(followIntent);
}
}, 1000 * 2);
}
catch (Exception e)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/"+id_facebook)));
String errorMessage = (e.getMessage()==null)?"Message is empty":e.getMessage();
Log.e("Unlock_ScreenActivity:FacebookAppNotFound" ,errorMessage);
}
UPDATE:
When I give up and i only put the https URI, Android let me choose between Facebook APP and the browser, and i like it! So my question is answered =D
I ran into a similar problem back in the day and found out that when I tried to use the same method as you it only worked if I wanted to view my own profile (or the current logged in user in the Facebook app) but whenever I tried to show someone else's facebook page so I eventually came across this answer:
https://stackoverflow.com/a/24547437/1879664
Long story short, it's no longer possible and the only workaround so far is to make facebook load the web page inside facebook just like you've mentioned but the difference is that without forcing it, if the user can't choose between apps or has already selected another browser as a default app you can no longer open that page through facebook. With this code you can ensure that it will always open that page with the facebook app if it's installed or it would load with your default browser. Here's the code that I use in my apps:
try {
mActivity.getPackageManager().getPackageInfo("com.facebook.katana", 0);
String url = "https://www.facebook.com/profile.php?id=USER_ID"
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href="+url));
}
mActivity.startActivity(intent);
} catch (Exception e) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/profile.php?id=USER_ID"));
mActivity.startActivity(intent);
e.printStackTrace();
}

Let install app from a user chosen store

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.

How to make an Android app that depends on another app?

If I create an app that depends on another app or apps (eg: the Facebook and Twitter apps), yet they are not installed, is there a method of checking for those dependencies and installing them at the same time as my own app?
I did this in my application which requires the zxing scanner app to be installed.
You will want this inside your onclick or ontouch:
try{
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
startActivityForResult(intent, 0);
} catch (Exception e) {
createAlert("Barcode Scanner not installed!", "This application uses " +
"the open source barcode scanner by ZXing Team, you need to install " +
"this before you can use this software!", true);
}
which calls
public void createAlert(String title, String message, Boolean button) {
// http://androidideasblog.blogspot.com/2010/02/how-to-add-messagebox-in-android.html
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
if ((button == true)) {
alertDialog.setButton("Download Now",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Intent browserIntent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("market://search?q=pname:com.google.zxing.client.android"));
startActivity(browserIntent);
}
});
}
alertDialog.show();
}
Then after sorting out all that code out I realise you asked for it to be installed at the same time as your app. Not sure if i should post this code, but it may be helpful
Short answer: No, you cannot automatically install other applications as dependencies.
Longer answer:
Android Market does not let you declare other applications to install as a dependency. As a system, Market appears to be designed for single application installs -- not Linux distro style mega dependency graphs.
At runtime, you can test for installed apps and punt your user over to the Market if so. See the techniques suggested by #QuickNick (testing if an app is installed) and #TerryProbert (punting to market) if that's what you want.
Your best bet is probably to design your app to gracefully degrade if dependencies are not available, and suggest (or insist) that they head over to market to install them.
Start from this:
Intent mediaIntent = new Intent("com.example.intent.action.NAME");
// add needed categories
List<ResolveInfo> listResolveInfo = getPackageManager().queryIntentServices(mediaIntent, 0);
if (listResolveInfo.size() != 0) {
//normal behavior
} else {
//install what you need
}
I give you example of querying services. If you want to check activities, then you will call queryIntentActivities().
I think following the pattern outlined in this post on the Android Developer Blog will help you.
http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html
As TerryProbert points out if you know that the Intent is not available prompt the user to install the missing app.
Here's what I use to return the first mission activity that exists:
try {
Class<?> missionClass = Class.forName(mPackageName+".Mission"+mission);
Method missionDescription;
missionDescription = missionClass.getMethod("missionDescription");
mMissionDescription = (String) missionDescription.invoke(null);
if (mMissionDescription.length() > 0) {
nextMission = mission;
break;
}
} catch (Exception e) {
//DEBUG*/Log.v(this.getClass().getName(), "onResume: Mission no "+mission+" not found: "+e.getMessage());
}
Each mission is held in a separate class, derived from a Mission base class. Derived classes are called Mission1, Mission24 etc.
Not all missions are defined.
The base class has an abstract class missionDescription which returns a string describing the mission.
This code is inside a loop so tests mission=1 to 99, trying to call missionDescription. It returns when the Description for the first mission found is returned.

Categories

Resources