Reputation: 93
I want to open uber app from my app.But I have not got proper code for it.please suggest some code.I have Searched several website but not got proper code.please provide some code to open uber app from my app.
Upvotes: 1
Views: 4288
Reputation: 10620
I find this is a better way of launching other apps inside our android apps.
// Pojo Model to handle application info
public class AppInfo {
private boolean isInstalled;
private ApplicationInfo applicationInfo;
public AppInfo(boolean isInstalled, ApplicationInfo applicationInfo) {
this.isInstalled = isInstalled;
this.applicationInfo = applicationInfo;
}
public boolean isInstalled() {
return isInstalled;
}
public void setInstalled(boolean installed) {
isInstalled = installed;
}
public ApplicationInfo getApplicationInfo() {
return applicationInfo;
}
public void setApplicationInfo(ApplicationInfo applicationInfo) {
this.applicationInfo = applicationInfo;
}
}
// Check Uber is installed or not
private AppInfo isUberAppsAvailable() {
final PackageManager pm = getPackageManager();
//get a list of installed apps.
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
int size = (null != packages && !packages.isEmpty()) ? packages.size() : 0;
for(int index = 0; index < size; index++) {
ApplicationInfo packageInfo = packages.get(index);
String packageName = (null != packageInfo) ? packageInfo.packageName : null;
if(null != packageName && packageName.equalsIgnoreCase(CJRConstants.PACKAGE_INFO_UBER)){
return new AppInfo(true, packageInfo);
}
}
return new AppInfo(false, null);
}
// Launch Uber App.
private void launchAppByPackage() {
AppInfo uberAppInfo = isUberAppsAvailable();
boolean isUberInstalled = (null != uberAppInfo
&& null != uberAppInfo.getApplicationInfo()
&& uberAppInfo.getApplicationInfo().enabled) ? uberAppInfo.isInstalled() : false;
if(isUberInstalled) {
ApplicationInfo uberObj = uberAppInfo.getApplicationInfo();
Intent LaunchIntent = getPackageManager()
.getLaunchIntentForPackage(uberObj.packageName);
startActivity(LaunchIntent);
} else {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.ubercab")));
}
}
Upvotes: 0
Reputation: 798
You can try the following code
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo("com.ubercab", PackageManager.GET_ACTIVITIES);
String uri = "uber://?action=setPickup&pickup=my_location";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(uri));
startActivity(intent);
} catch (PackageManager.NameNotFoundException e) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.ubercab")));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.ubercab")));
}
}
Upvotes: 5
Reputation: 641
For Opening Uber App you need to be integrate Uber Sdk in your App.Check the link below https://github.com/uber/rides-android-sdk
Upvotes: 3
Reputation: 13555
You need to do like this in your Manifest,that is working for me.
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|keyboard|screenSize"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="yoursitedomain.com"
android:scheme="http" />
<data
android:host="www.yoursitedomain.com"
android:scheme="http" />
</intent-filter>
</activity>
Upvotes: 0