open or browse application or activity on hyperlink click and get value from url
Create MainActivity.jave file
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView deepLinkUrl = (TextView) findViewById(R.id.deep_link_url); Intent intent = getIntent(); Uri data = intent.getData(); if ((data != null) && (data.getQueryParameter("faqid") != null)) { Toast.makeText(this, data.getQueryParameter("faqid") + "", Toast.LENGTH_SHORT).show(); } else if ((data != null) && (data.getQueryParameter("sectionid") != null)) { Toast.makeText(this, data.getQueryParameter("sectionid") + "", Toast.LENGTH_SHORT).show(); } else { deepLinkUrl.setText("Deep link received - " + data); } if(data != null) { deepLinkUrl.setText("Deep link received :- faqid = " + data.getQueryParameter("faqid")+" sectionid = "+data.getQueryParameter("sectionid")); } } }
Create activity_main.xml file
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.deeplink.MainActivity"> <TextView android:id="@+id/deep_link_url" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" /> </RelativeLayout>
Set code in manifest, on pariticular activity
<activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> <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="www.example.com" android:pathPrefix="/gizmos" /> </intent-filter> </activity>
Exmple Deeplink Url:- http://www.example.com/gizmos?faqid=111§ionid=222
No comments:
Post a Comment