Rapid Subscribe Android App

Rapid Subscribe Android App
Rapid Subscriber

Recent Posts

Deep linking in Android Webview | Create a Browsable activity with Android Webview

Deep linking in Android Webview | Create a Browsable activity with Android Webview





To create full Android WebView Click here

In this post, we will learn, how to open External Url link in our webview activity.

Sometimes, someone send us a Url link and we want to open that url in our webview activity, because we don't want to copy and paste that Url in our webview to open, we will handle Intent and some code in our manifest file to open that url directly.

code in java file, (use that code just before loading your Url
 Intent intent = getIntent();  
     Uri data = intent.getData();  
     if(data != null)  
     {  
       url = data.toString();  
     }  

Some more code from Webview Activity for more understanding
 public class MainActivity extends AppCompatActivity {  
   WebView mywebview;  
   String url = "https://www.instagram.com/harpreet_s2509/?igshid=q297jkyrgs2"; //default Url
   }  
   @SuppressLint("ClickableViewAccessibility")  
   @Override  
   protected void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.activity_main);  
   
     mToolbar = findViewById(R.id.toolbar);  
     progressbar = findViewById(R.id.progressbar);  
   
     mydb = new DatabaseHelper(this);  
   
     if (getIntent().getExtras() != null) {  
       url = getIntent().getStringExtra("urlkey");  
     }  
   

     Intent intent = getIntent();  
     Uri data = intent.getData();  
     if(data != null)  
     {  
       url = data.toString();  
     }  

   
     mywebview = findViewById(R.id.webview);  
     mywebview.loadUrl(url);  
   
   
     tooltext = findViewById(R.id.toolbartext);  
     setSupportActionBar(mToolbar);  
     setTitle(null);  
   
     WebSettings settings = mywebview.getSettings();  
   
     settings.setJavaScriptEnabled(true);  
     settings.setDisplayZoomControls(false);  
     settings.supportZoom();  
     settings.setSupportZoom(true);  
     settings.setBuiltInZoomControls(true);  
     settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); 
     settings.setLoadWithOverviewMode(true);  
     settings.setUseWideViewPort(true);  
     settings.setDomStorageEnabled(true);  
     settings.setAppCacheEnabled(true);  
     settings.setLoadsImagesAutomatically(true);  
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {  
       settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);  
     }  
   
     mywebview.clearHistory();  
     mywebview.clearCache(true);  
     registerForContextMenu(mywebview);  

Do some code in Android manifest also with your Webview Activty
 <application  
     android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">  
     <activity android:name=".History"></activity>  
     <activity android:name=".Downloads" />  
     <activity android:name=".BookList" />  
     <activity android:name=".Srchvw" />  
     <activity android:name=".testfile" />  
     <activity android:name=".SplashActivity" />
  
     <activity android:name=".MainActivity">  
       <intent-filter>  
         <action android:name="android.intent.action.VIEW" />  
         <action android:name="android.intent.action.MAIN" />  
   
         <category android:name="android.intent.category.LAUNCHER"/>  
         <category android:name="android.intent.category.DEFAULT"/>  
         <category android:name="android.intent.category.BROWSABLE"/>  
   
         <data android:scheme="http"/>  
         <data android:scheme="https"/>  
         <data android:host="*"/> <!-- * means get all type of URLS -->  
   
       </intent-filter>  
     </activity>  


 
Follow us for more posts like this, 
Subscribe to Harpreet studio on Youtube  
Like Harpreet Studio on Facebook  
Follow me on Instagram 

7 comments:

  1. Enjoyed reading the article above , really explains everything in detail,the article is very interesting and effective. buy facebook likes

    ReplyDelete
  2. Sir send application source code

    ReplyDelete
  3. Wow I really enjoyed to read that all i will always follow You thanks for the great article.
    It conatains so good knowledge. Full of informative article.
    Here My website for seedbox

    ReplyDelete
  4. This written piece gives fastidious understanding yet.social media

    ReplyDelete
  5. You are writing some interesting and Best content I also bookmark this URL...You guys are writing some Amazing tips. This article really helped me a lot. Thanks for sharing this. Side hustle

    ReplyDelete
  6. Imports and libraries I have copied all tipe of the same post sitill getting errors

    ReplyDelete