Deep link not opening specified Activity but opens other Activity - android

I have created a DynamicLink programatically which includes sub-domain syntax, some title and preview Image. I have also specified the IntentFilter which should open that activity when clicked. But when the link is clicked it open another Activity which also have Deep link. page.link domain is provided by google itself in Firebase Console
The code for creating Dynamic Link is
String e="https://learnandroid.page.link/?link=https://learn.android/&apn=com.learnandro&amv=16&st=Please view the ContentEvent&si="+some Image Url+"&afl=https://play.google.com/store/apps/details?id=app Package name";
Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance()
.createDynamicLink()
.setLongLink(Uri.parse(e))
.buildShortDynamicLink()
.addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
#Override
public void onComplete(#NonNull Task<ShortDynamicLink> task) {
Uri get=task.getResult().getShortLink();
Intent sh=new Intent(Intent.ACTION_SEND);
sh.setType("text/plain");
sh.putExtra(Intent.EXTRA_TEXT,"Vi ew the Amazing Event "+get);
startActivity(Intent.createChooser(sh,"View"));
}
});
The Intent filter for Activity is given as
<activity android:name=".content.Home"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<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="learn.android"
android:scheme="https" />
</intent-filter>
</activity>
But when the link generated is clicked it opens some Another activity.

If you have deeplink in multiple activities then you should use android:pathPattern to differentiate them from each other.
Here is sample code
<data
android:host="learn.android"
android:pathPattern="/home"
android:scheme="https" />
and add /home to your link
String e="https://learnandroid.page.link/?link=https://learn.android/home/&apn=com.learnandro&amv=16&st=Please view the ContentEvent&si="+some Image Url+"&afl=https://play.google.com/store/apps/details?id=app Package name";

You can try below snippet :
val data: Uri? = intent?.data
if (Uri.EMPTY != data)
{
val id = intent.data?.getQueryParameter("ID")
intent = Intent(this, ActivityName::class.java)
startActivity(intent)
finish()
}
In getQueryParameter, you need to pass KEY name which contains data in URL
Define this set of code in Activity which is defined in Manifest file

Related

flutter how to open txt file with open with dialog to specific page?

I'm new on flutter and never used intent filter. so far I have everything working in my app. but I'm stuck in importing the file to app by open with dialog. I need the user when it click on the file it will go to the page and display the information in the file. I'm using ImportFile plugin and it work fine but it make it harder for the users to put the file they receive.
my app is list it in the open with dialog but when i click it, it just open the app I want it to open the app and view the text in the view text page not the homepage
AndroidManifest.xml
<
intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
<data android:pathPattern="*.*\\.txt" />
</intent-filter>
MainActivity.java
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent
}
}
new MethodChannel(getFlutterView(), "app.channel.shared.data").setMethodCallHandler(new MethodChannel.MethodCallHandler() {
#Override
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
if (methodCall.method.contentEquals("getSharedText")) {
result.success(sharedText);
sharedText = null;
}
}
});
}
void handleSendText(Intent intent) {
sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
}
Thank you in advance
FlutterView has a setInitialRoute method you can use to specify a non-default route on launch.

Android Firebase Dynamic links not working in Facebook messenger properly

I integrated my application with dynamic links from firebase successfully. But when I share a short link with SocialMetaTagParameters and click on the link in messenger it opens the browser and it should redirected to my application, but it is entering in infinite loop in the browser.
I found similar issue created in google groups:
https://groups.google.com/forum/#!topic/firebase-talk/nOOcOwmxl58
This is my code to create short link:
Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(link))
.setDynamicLinkDomain(mContext.getString(R.string.firebaseAppCode))
// Set parameters
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
.setIosParameters(new DynamicLink.IosParameters.Builder("com.xxxx.xxxx").build())
.setSocialMetaTagParameters(
new DynamicLink.SocialMetaTagParameters.Builder()
.setTitle(title)
.setDescription(description)
.setImageUrl(Uri.parse(imageUrl))
.build()
)
.buildShortDynamicLink()
.addOnCompleteListener((Activity) mContext, new OnCompleteListener<ShortDynamicLink>() {
#Override
public void onComplete(#NonNull Task<ShortDynamicLink> task) {
if (task.isSuccessful()) {
// Short link created
Uri shortLink = task.getResult().getShortLink();
ShareApp(mContext, shortLink.toString());
} else {
Utils.ShowToast(mContext, "Sharing failed, Try again");
}
}
});
This is my code to share the short dynamic link:
public static void ShareApp(Context mContext,String link) {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT,link);
mContext.startActivity(Intent.createChooser(share, "Share..."));
}
This is code in manifest :
<activity
android:name=".UI.Home.Consultants.ViewConsultantProfileActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="Profile"
android:screenOrientation="portrait"
android:theme="#style/AppTheme"
android:windowSoftInputMode="stateHidden">
<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="consultrustconsultant"
android:scheme="http"/>
<data
android:host="consultrustconsultant"
android:scheme="https"/>
</intent-filter>
</activity>
Note:
if I removed SocialMetaTagParameters, the link is working properly and when click on the link its redirected to my application

Enable deep linking for android for various structured urls

I've already enabled deep linking & it opens app from url. However it opens only the main url i.e. m.example.com & not m.example.com\products\iphone-5s\.
I'm using WebView to load my mobile website into an Android app.
Here's a code of xml file:
<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="m.example.com"
android:pathPrefix="/"
android:scheme="http" />
</intent-filer>
Java file:
private String url='m.example.com';
#Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
mainWebView.loadUrl(url);
}
Can anybody help to resolve this?
Get the URL link with this code, right after Uri data = intent.getData();
String link = intent.getDataString();
Then, set simple if/else
if (link == null) {
mWebView.loadUrl("yourMainURL");
} else {
mWebView.loadUrl(link);
}

How to launch an app using a deeplink in android

I want to launch app using my own app but not by giving the package name, I want to open a custom URL.
I do this to start an application.
Intent intent = getPackageManager().getLaunchIntentForPackage(packageInfo.packageName);
startActivity(intent);
Instead of package name is it possible to give a deep-link for example:
"mobiledeeplinkingprojectdemo://product/123"
Reference
You need to define a activity that will subscribe to required intent filters:
<activity
android:name="DeepLinkListener"
android:exported="true" >
<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="host"
android:pathPattern="some regex"
android:scheme="scheme" />
</intent-filter>
</activity>
Then in onCreate of your DeepLinkListener activity you can access the host, scheme etc.:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent deepLinkingIntent= getIntent();
deepLinkingIntent.getScheme();
deepLinkingIntent.getData().getPath();
}
Perform check on path and again fire a Intent to take the user to corresponding activity. Refer data documentation for more help.
Now fire a Intent:
Intent intent = new Intent (Intent.ACTION_VIEW);
intent.setData(Uri.parse(DEEP_LINK_URL));
Don't forget to handle the exception. If there is no activity that can handle the deep link, startActivity will return an exception.
try {
context.startActivity(
Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(deepLink)
}
)
} catch (exception: Exception) {
Toast.makeText(context, exception.localizedMessage, Toast.LENGTH_LONG).show()
}

OAuth + Twitter on Android: Callback fails

My Android application uses Java OAuth library, found here for authorization on Twitter. I am able to get a request token, authorize the token and get an acknowlegement but when the browser tries the call back url to reconnect with my application, it does not use the URL I provide in code, but uses the one I supplied while registering with Twitter.
Note:
1. When registering my application with twitter, I provided a hypothetical call back url:http://abz.xyc.com and set the application type as browser.
2. I provided a callback url in my code "myapp" and have added an intent filter for my activity with Browsable category and data scheme as "myapp".
3. URL called when authorizing does contain te callback url, I specified in code.
Any idea what I am doing wrong here?
Relevant Code:
public class FirstActivity extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
OAuthAccessor client = defaultClient();
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(client.consumer.serviceProvider.userAuthorizationURL + "?oauth_token="
+ client.requestToken + "&oauth_callback=" + client.consumer.callbackURL));
startActivity(i);
}
OAuthServiceProvider defaultProvider()
{
return new OAuthServiceProvider(GeneralRuntimeConstants.request_token_URL,
GeneralRuntimeConstants.authorize_url, GeneralRuntimeConstants.access_token_url);
}
OAuthAccessor defaultClient()
{
String callbackUrl = "myapp:///";
OAuthServiceProvider provider = defaultProvider();
OAuthConsumer consumer = new OAuthConsumer(callbackUrl,
GeneralRuntimeConstants.consumer_key, GeneralRuntimeConstants.consumer_secret,
provider);
OAuthAccessor accessor = new OAuthAccessor(consumer);
OAuthClient client = new OAuthClient(new HttpClient4());
try
{
client.getRequestToken(accessor);
} catch (Exception e)
{
e.printStackTrace();
}
return accessor;
}
#Override
protected void onResume()
{
// TODO Auto-generated method stub
super.onResume();
Uri uri = this.getIntent().getData();
if (uri != null)
{
String access_token = uri.getQueryParameter("oauth_token");
}
}
}
// Manifest file
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".FirstActivity"
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:scheme="myapp"/>
</intent-filter>
</activity>
</application>
Twitter does not honor callbacks requested in OAuth requests (Twitter API Announce) and will only redirect to the callback URL specified in the Application Settings (note that "localhost" is not allowed).
I assume you checked Oauth-callback-on-android question.
Android guesswork--
After a bit of reading up, I see Android browser redirects MyApp:/// to your application and I'm guessing Twitter doesn't like this bespoke URI prefix. I'm no android developer but one suggestion I might make is to get "www.myapp.com" on the web and have a re-redirect there.
So have your OAuth return to http://www.myapp.com/redirect.aspx?oauth_token=abc and have that page redirect to myapp:///oauth_token=... (the desired result)
In my case, i have this working:
String authURL = m_provider.retrieveRequestToken (m_consumer, CALLBACK_URL);
And in the Manifest:
<activity android:configChanges = "keyboardHidden|orientation" android:name = "xxxx.android.xxxxx">
<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" android:host="tweet" />
</intent-filter>
In this case the callback url will be: myapp://tweet
It looks to me like you're doing the correct thing and Twitter is screwing up by always accepting your registered callback URL. Is there any way to change the registered URL? Maybe you could re-register and try an Android callback next time, see what happens.
My problem was that I was trying to log in with the same account I made the Twitter app. After I logged in with my personal profile the call back works (so far).

Categories

Resources