I am trying to intercept a url so that my application opens up when user accesses the URL. I am following this answer in a related question https://stackoverflow.com/a/2958870
I've added the following in AndroidManifest.xml
<activity
android:name="com.myapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<data android:scheme="http" android:host="myapp.com"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And have the following in onCreate of MainActivity.java
Uri data = getIntent().getData();
//String scheme = data.getScheme();
//String host = data.getHost();
if (data == null)
Log.d("Data is null", "");
else
Log.d("Data is not null", "");
When I launch the app in the emulator I am noticing that the "Data is null" debug message is coming. I had to comment out the scheme and host because that was causing my application to fail on load time and the reason for I guess was because data was null.
Am I missing something or doing something wrong?
Edit: I've tried splitting the intent-filter like this:
<activity
android:name="com.myapp.MainActivity"
android:label="#string/app_name" >
<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:host="myapp.com" android:scheme="http" />
</intent-filter>
</activity>
Also, when I just have one intent-filter (below) my app does not even launch on the emulator when I press run in android studio.
<activity
android:name="com.myapp.MainActivity"
android:label="#string/app_name" >
<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="myapp.com" android:scheme="http" />
</intent-filter>
</activity>
Try this intent filter instead:
<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="myapp.com" android:scheme="http" />
</intent-filter>
This is an implicit intent, but I tried it and it worked for me. I think you need the android.intent.category.BROWSABLE category.
Related
I have implemented android deep link code in my app, and it works for some devices, but not for all.
The main problem is, when I open web url from my app its showing option for open this url (chorme and myApp), then, after complete the work of web pages, its not showing any option to back to my App again. But for some device its showing the option for back to my app.
I can't figure out what is the problem. I have tried so many solution from internet, but nothing can work. If anyone has any solution that works for all android device, please help.
Here is my Manifest code
<activity
android:name=".activity.SplashActivity"
android:exported="true"
tools:ignore="ExtraText">
<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:host="www.example.com"
android:scheme="https" />
<data
android:host="www.example.com"
android:scheme="http" />
<data
android:host="example.com"
android:scheme="https" />
<data
android:host="example.com"
android:scheme="http" />
<!-- note that the leading "/" is required for pathPrefix -->
</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:host="app"
android:scheme="example" />
</intent-filter>
//------------------------------------------//
</activity>
I want to open app directly without giving propmt open with browser or open with app.
I followed some links on stackoverflow did exactly what they did but still no luck.
Please help to get it fixed.
<activity
android:name="com.zappfresh.android.Activity.login.SplashActivity"
android:label="Zappfresh"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="zappfresh.onelink.me"
android:pathPrefix="/T0HX"
android:scheme="https" />
</intent-filter>
</activity>
I've implemented OneSignal to send push notifications to my Android app. I've mainly implemented everything using their REST API and didn't do much code work in my app. I've followed (and literally copied the code as there was no need for much changes) this documentation.
The problem is, when I'm using my app in foreground (mainactivity of my app) and I send a notificaition (which is supposed to launch the updateactivity), the activity opens on top of the current activity. Now, even when I'm tapping Exit from my app's menu, it's closing the activity on the top, however, the activity on the bottom is still there. So, basically, users have to exit from the app twice.
I have declared all activities as <singleTask> in the manifest.
Here's the ApplicationClass.java needed and used by OneSignal:
package com.application;
import android.app.Application;
import com.onesignal.OneSignal;
#SuppressWarnings("unused")
public class ApplicationClass extends Application
{
#Override
public void onCreate()
{
super.onCreate();
OneSignal.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.init();
}
}
And here's my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.application"
android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name=".ApplicationClass"
android:allowBackup="true"
android:fullBackupContent="#xml/backup_descriptor"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="AllowBackup">
<activity
android:name=".SplashActivity"
android:theme="#style/Splash"
android:launchMode="singleTask">
<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:host="domain.tld"
android:scheme="http"
android:pathPattern="/*"/>
</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:host="domain.tld"
android:scheme="https"
android:pathPattern="/*"/>
</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:host="www.domain.tld"
android:scheme="http"
android:pathPattern="/*"/>
</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:host="www.domain.tld"
android:scheme="https"
android:pathPattern="/*"/>
</intent-filter>
</activity>
<activity
android:name=".SplashActivity2"
android:theme="#style/Splash"
android:launchMode="singleTask">
<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="domain.tld"
android:scheme="http"
android:pathPrefix="/folder"/>
</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:host="domain.tld"
android:scheme="https"
android:pathPrefix="/folder"/>
</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:host="www.domain.tld"
android:scheme="https"
android:pathPrefix="/folder"/>
</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:host="www.domain.tld"
android:scheme="http"
android:pathPrefix="/folder"/>
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:launchMode="singleTask"/>
<activity
android:name=".UpdateActivity"
android:launchMode="singleTask"/>
<activity
android:name=".ErrorActivity"
android:launchMode="singleTask"/>
</application>
</manifest>
So, what to do to so that the new activity that opens because of the notification gets like merged into the current activity so that, when a user tries to exit, he/she can exit the app in one go?
I am new to Android development...
I have an application which uses a library to upload data to a website. I want to make additions to the application to be able to read NFC tags.
I started out creating a small, separate application to get the hang of NFC. That app works fine. Now, I need to bring in some of that code into this other application which depends on the aforementioned library.
The problem is, UNLESS I add an application node to the AndroidManifest.xml in the LIBRARY specifying the NFC intents, the intents do not fire.
[Snippet from library manifest mentioned above]
<application
android:supportsRtl="true"
android:allowBackup="true">
<activity
android:name=".MainActivity"
android:label="My App..."
android:supportsRtl="true">
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
[The main application contains this application node in its manifest]
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.microsoft.azure.storage.samples.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="#xml/nfc_tech_filter" />
</activity>
</application>
Now comes the problem.... when a tag is detected, android tries to launch the activity from the library manifest file. Since that activity doesn't exist, I get a ClassNotFoundException. I tried specifying MainActivity class from the application for the android:name of the application node in the LIBRARY manifest, but:
I can't compile the code.
It would be extremely poor practice even if that worked...
How do I get the NFC intents to fire without having to add intent-filter nodes in the library manifest?
Thank you!
I have implemented deep linking in my app. I added this intent filter in my manifest file, and the deep linking is working fine.
<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.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="xxxxxxxx"
android:scheme="xxxxxxxx" />
</intent-filter>
The problem is that through deep linking, when i click on my App, it is showing similiar kinds of apps.
It is happening when Open by DEFAULT is not set
But when the open by default is set then everything is working fine.
Try this way ..
Suppose when user call http://example.com that time my Mainactivity open then all required attribute define inside mainactivity.
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<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:scheme="http"
android:host="example.com"/>
</intent-filter>