2014-10-07 91 views
0

我正在製作一個按鈕,當我點擊它時,它直接從瀏覽器中獲取我的東西,我希望它可以轉到instagram應用程序,如果它不在我的手機,它應該去瀏覽器。Instagram去瀏覽器

我嘗試了兩種,兩者都帶我直接在瀏覽器

第一碼:

inslink.setOnClickListener(new OnClickListener() { 

@Override 
public void onClick(View arg0) { 

    try { 
    Uri uri = Uri.parse("http://instagram.com/natgeo"); 
    Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
    startActivity(intent); 
    } 

    catch (Exception e) { 
     Uri uri = Uri.parse("http://instagram.com/natgeo"); 
     Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
     startActivity(intent); 
    } 
    } 
}); 

第二個代碼:

inslink.setOnClickListener(new OnClickListener() { 

@Override 
public void onClick(View arg0) { 

    if (uri.contains("https://i.instagram.com/")) { 
    String natgeo = "natgeo"; 
     String uri = "instagram://Page/" + natgeo; 
     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); 
     startActivity(intent); 

    } else { 
     String natgeo = "natgeo"; 
     String uri = "https://i.instagram.com/" + natgeo; 
     Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); 
     startActivity(i); 
      } 
    } 
}); 

回答

1

Instagram的應用程序不處理路徑-prefix natgeo。

<activity android:name=".activity.UrlHandlerActivity" android:exported="true" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation|screenSize"> 
     <intent-filter> 
      <action android:name="android.intent.action.VIEW" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.BROWSABLE" /> 
      <data android:scheme="http" android:host="instagr.am" android:pathPrefix="/p/" /> 
      <data android:scheme="https" android:host="instagr.am" android:pathPrefix="/p/" /> 
      <data android:scheme="http" android:host="instagram.com" android:pathPrefix="/p/" /> 
      <data android:scheme="https" android:host="instagram.com" android:pathPrefix="/p/" /> 
      <data android:scheme="http" android:host="instagram.com" android:pathPrefix="/_u/" /> 
      <data android:scheme="https" android:host="instagram.com" android:pathPrefix="/_u/" /> 
      <data android:scheme="http" android:host="instagram.com" android:pathPrefix="/_uid/" /> 
      <data android:scheme="https" android:host="instagram.com" android:pathPrefix="/_uid/" /> 
     </intent-filter> 
    </activity> 

所以,這些是網址的前綴,其Instagram的應用程序處理:
http://instagr.am/p/
https://instagr.am/p/
http://instagram.com/p/
https://instagram.com/p/

閱讀下面的XML,它從Instagram的應用程序的AndroidManifest.xml文件的http://instagram.com/_u/
https://instagram.com/_u/
http://instagram.com/_uid/
https://instagram.com/_uid/

相關問題