从我的应用程序android打开Uber应用程序

时间:2016-03-10 10:20:03

标签: android

我想从我的应用程序打开超级应用程序。但我没有得到正确的代码。请提示一些代码。我已经搜索了几个网站但没有得到正确的代码。请提供一些代码从我的应用程序打开超级应用程序

4 个答案:

答案 0 :(得分:4)

您可以尝试以下代码

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

答案 1 :(得分:2)

要打开Uber App,您需要将Uber Sdk集成到您的App中。查看https://github.com/uber/rides-android-sdk下面的链接

答案 2 :(得分:0)

你需要在你的Manifest中这样做,这对我有用。

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

答案 3 :(得分:0)

我发现这是在我们的Android应用程序中启动其他应用程序的更好方法。

// 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")));
    }
}