簡體   English   中英

我的瀏覽器中的Android打開網址

[英]Android open url in my browser

通過單擊鏈接可打開默認瀏覽器,是否可以使單擊時打開我的應用程序-瀏覽器(如果已安裝,如果未安裝,則打開默認瀏覽器)? 我的代碼:

   String url = intent.getStringExtra("url");
   if (!url.startsWith("http://") && !url.startsWith("https://")) url = "http://" +   url;
   Intent i = new Intent(Intent.ACTION_VIEW);
   i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   i.setData(Uri.parse(url));
   context.startActivity(i);

解決方案是在清單中定義方案,例如:

    <activity
        android:name=".MyMainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <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="myapp" /> <!-- see this -->
        </intent-filter>
    </activity>

Activity添加以下內容

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // Handle intent extras
}

網絡瀏覽器中的鏈接類似於: myapp:open_url = http://www.google.fi

然后,您可以從Intent Extras中解析該網址,然后在WebView中將其打開

這也是一個有趣的帖子: http : //danielmuller.asia/2013/02/android-open-an-app-from-web-link-or-fallback-to-market/

您應將應用程序深層鏈接集成到您的android應用程序中,以便通過單擊瀏覽器中的鏈接來打開您的應用程序

http://googlewebmastercentral.blogspot.in/2014/06/android-app-indexing-is-now-open-for.html

https://developers.google.com/app-indexing/webmasters/app?utm_source=wmc-blog&utm_medium=referral&utm_campaign=apps-for-all

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM