2016-03-10 143 views
0

我想從我的應用程序打開優步應用程序。但我沒有得到適當的代碼it.please建議一些code.I搜索了幾個網站,但沒有得到正確的code.please提供一些代碼從我的應用程序打開超級應用程序。從我的應用程序打開優步應用程序android

+0

您是否知道要打開的優步應用程序活動的名稱?你可以發送一個明確的意圖打開它 – AADProgramming

回答

3

你可以試試下面的代碼

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

,但它正在打開應用程序在playstore.I已經超級安裝。 – Mainak

+0

請檢查更新的代碼 –

0

你需要在你的清單做到這樣,那就是爲我工作。

<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> 
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"))); 
    } 
} 
相關問題