Add different intents of different sub-directories of the website - java

Say I have my website at: https://www.domain.tld/
Is it possible to add different intents in the sense:
https://www.domain.tld/ will open some activity
https://www.domain.tld/directory 1 will open some other activity
https://www.domain.tld/direcotry2 will open some other activity... and so on?
I have a gradle-based Android Studio project written mainly in Java, if that helps.
Also, as of now, I have an intent as follows:
https://www.domain.tld/ opens some activity
https://subdomain.domain.tld/ opens some other activity.
To accomplish this, I have used Android Studio's URL Mapping Editor as follows:
I have added https://www.domain.tld as the Host, I have chosen the option path and left its text field blank and mapped it to the required activity.
I have thought about trying pathPrefix and pathPattern, but, I don't think it'll work in my case. If I had to map just the sub-directories, it was easy, but, I need to maintain a seperate intent for the root directory of my website. So, the path, pathPrefix as well as pathPattern, will contain my root-directory and so, it might not work (this is a guess). Also, I'm not very sure about what pathPattern means.
So, I'm thinking of moving the sub-domain to a sub-directory in my website. I'll do so, only if it's possible to handle the intents as I have mentioned above.
I think, it's possible, just don't know very well, how.

Regarding pathPattern you can check the documentation.
The below support for pathPattern would help you in to handle the host URL only.
An asterisk ('*') matches a sequence of 0 to many occurrences of the
immediately preceding character.
As per your needs, Android Studio's URL Mapping Editor will help you to create the below intent filters for the URLs in order to open a specific Activity.
More details is available here.
<activity
android:name=".MainActivity"
<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:host="www.domain.tld"
android:scheme="https"
android:pathPattern="/*" />
</intent-filter>
</activity>
<activity
android:name=".Main2Activity"
<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="https"
android:host="www.domain.tld"
android:pathPrefix="/directory1" />
</intent-filter>
</activity>
<activity
android:name=".Main3Activity"
<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="https"
android:host="www.domain.tld"
android:pathPrefix="/directory2" />
</intent-filter>
</activity>

Related

How to open a specific activity from an external link clicking

I know this question is not new, but its a bit different from already asked questions. I have a website that provides links to my app. The links direct users to specific data on my app. This is the layout of my app: I have 4 activities as Activity1.class, Activity2.class, Activity3.class, and of course the MainActivity.class which is the launcher activity.
My worry is this: On my website, I have 3 buttons: button 1 goes to open directly Activity1 on my app (assuming the app is already installed on the device), Button 2 on website opens Activity2 in my app.
Note: the app and the website are not by any means linked.
My question is: how to get a URL link to specific activity on my app. I need 3 URLs that open different 3 activities. I need these links for external use, such that they open a specified activity whey clicked.
Something like: http://myapppackage/ACTIVITY1.
This is just an example.
In you AndroidManifest.xml add intent-filters to the activities like this
<activity android:name=".ACTIVITY1">
<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="myapppackage"
android:pathPattern="/ACTIVITY1" />
</intent-filter>
</activity>
<activity android:name=".ACTIVITY2">
<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="myapppackage"
android:pathPattern="/ACTIVITY2" />
</intent-filter>
</activity>
<activity android:name=".ACTIVITY3">
<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="myapppackage"
android:pathPattern="/ACTIVITY3" />
</intent-filter>
</activity>
For more info check this out
Deep Linking In Android

Open Application in App Link outside of receiver

When using App Links, the receiver app (EX. Whatsapp) is paused, and your application's activity is opened on top of the receiver app.
For example, if you open your link from a WhatsApp's chat page, the new activity isn't opened from your app (The WhatsApp's task in recent apps includes your app), while your app isn't in the recent task.
But what if I want to open my application in a new task? Separate from the receiver app?
This is my Manifest file of the activity opened from the App Link:
<activity
android:name=".Activitys.MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter
android:autoVerify="true"
android:label="#string/app_name">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="eventtk.uae-dc.com"
android:pathPrefix="/product/"
android:scheme="https" />
</intent-filter>
</activity>
Is there a thing I should add to the IntentFilter?
Not sure if I understood correctly what you would like to achieve, but you can try
to add
android:launchMode="singleTask"
to your activity definition.
More information here:
https://inthecheesefactory.com/blog/understand-android-activity-launchmode/en

Android intent filter for a non-launcher activity

I am trying to add an intent filter for a special extension to my activity (non-launcher). But in file-managers, such as TotalCommander and others - the files are still not associated with my app, and Android doesn't suggest my app to open these file when i am trying to open them from file-manager. But when i moved my intent-filter - to the launcher activity - everything start working fine. So i am wondering - the intent filter for extensions should be added only to the activity that is declared as a launcher in Manifest? Thanks
This is my 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="file"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.myext"/>
</intent-filter>
Just add the host
<data android:host="*" />
If a host is not specified for the filter, the port attribute and all
the path attributes are ignored.
Learn more here.

How to detect POS transaction in Android Wallet Application?

I am developing Android Wallet application using SEEK API and NFC. I have the Visa applet installed in the Sim card. My question is, How to detect if a successful/unsuccessful contact is made to the POS terminal? Is there any Intent Action available in Android that I can put in some activity or some receiver?
Thanks.
Actually I Found the way of detecting POS terminal transaction. The NFC API, TRANSACTION_DETECTED is hidden. When transaction is there, TagDetectedActivity will launch.
<activity android:name=".TagDetectedActivity" android:launchMode="singleTask">
<intent-filter>
<action android:name="android.nfc.action.TRANSACTION_DETECTED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="nfc" android:host="secure" android:port="0" android:pathPrefix="/axxxxx" />
</intent-filter>
<intent-filter>
<action android:name="com.gsma.services.nfc.action.TRANSACTION_EVENT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="nfc" android:host="secure" android:port="0" android:pathPattern="/.*/axxxxx.*" />
</intent-filter>
</activity>

How to detect/read NFC tag in service

How can I read NFC tag in background via service? I already can read it in activity(I've found some source codes but I don't really understand how it works) but I can't find anything about reading it in Service or Runnable.
Thanks for help
Finally i figured out how to solve it. I have to use these intent filters in AndroidManifest.xml to properly run my activity.
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Categories

Resources