App crashes on opening deep link from the app - android

I have a requirement where i need to launch the deep link from the app.
This is my deep link.
https://n9zv0.app.link/63yWc1w1
Now when i try to open this link from app, it crashes with following error message.
No Activity found to handle Intent : android.intent.action.VIEW
Code:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://o5kn2.app.link/63yW7yM7C5"));
startActivity(browserIntent);

There is no browser app in the device to open the link. To handle this issue:
Resolve beforehand if an app exists:
if (intent.resolveActivity(getPackageManager()) == null) {
// show no app available to user
} else {
// start activity
}
Handle with exception:
try{
// your intent here
} catch (ActivityNotFoundException e) {
// show message to user
}
or alternatively open in webview activity to display.

Make sure to make update an Activity to handle deeplinks, in AndroidManifest you have added IntentFilter with Viewable action.
<activity
android:name=".MyActivity">
<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.abc.com"
android:scheme="https" />
<data
android:host="www.abc.com"
android:scheme="http" />
</intent-filter>
</activity>

Related

Deep liking does not work on gmail app and works on other browsers

https://example.com/public/change_phone?email_recovery_code=F08fjfU39Ea6RSlDzM8ZZJFVwyjAE
<activity android:name=".view.activity.sign_in_new_number.SignInNewNumberActivity">
<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="example.com"
android:pathPrefix="/public/change_phone"/>
</intent-filter>
</activity>
I used the manifest setting's like above but it does not work for Gmail app, the URL does not redirect me on my app just open's the link in Gmail app
if splash screen is the first screen in your app..then use this on onCreate() of your splash activity :
First get the url you are getting through deep linking
Intent intent = getIntent();
Uri data = intent.getData();
if (!isTaskRoot()) {//this will resume your app from last loaded screen if you pressed home button earlier
Log.e("splashfin", "hello");
if (data != null) {
//open that activity through your url or do what ever you want
}else{}
}else{
if(data!=null){
//open that activity through your url or do what ever you want
}
}

How to avoid deep linking loop?

In my android app, I implemented a deep link so that when the user accessed my website, it offers to open it via my mobile app.
<activity
android:name=".MyActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
<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="myhost"
android:pathPrefix="/myprefix"
android:scheme="http" />
<data
android:host="myhost"
android:pathPrefix="/myprefix"
android:scheme="https" />
</intent-filter>
</activity>
Some of the features in my website is not implemented in the mobile. That's why I'm opening the browser for the user whenever they want to access that certain feature.
try {
Uri intentData = Uri.parse(url);
Intent httpIntent = new Intent(Intent.ACTION_VIEW);
httpIntent.setDataAndType(intentData, "text/plain"); //NON-NLS
startActivity(httpIntent);
} catch (Exception e) {
//print error that user has no browser
}
The problem I'm having is that, after opening the browser, chrome is asking the user whether they want to open the url via chrome or my app. I want to avoid that because I'm the one redirected them to the browser.
This thread is the only one I found related to my question, unfortunately it has no answer.

Force to open link in browser for fallback

I have an intent-filter that open all links with host "xyzxyz.com/value".
In the manifest I set an Activity to receive it:
<activity
android:name=".ui.LinkOpenerActivity"
android:label="#string/app_name" >
<intent-filter 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:scheme="http"
android:host="xyzxyz.com" />
</intent-filter>
</activity>
So when the user click on a "xyzxyz.com/value" link it open the app, that execute certain operations based on the "value" in the URL.
What I would like to do is to open the default browser in case the "value" have an incorrect value.
I tried with
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlReceivedFromIntent));
startActivity(browserIntent);
but it end up in an infinite loop, because it open again my app... any suggestion to fallback in the default browser and open http://xyzxyz.com/value in it?
Solved with Intent chooser:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(
Intent.createChooser(browserIntent, null)
);
finish();
By using context.getPackageManager().queryIntentActivities you can get the list of the activities that are able to resolve your intent. You can then filter out yours and pick another one explicitly by using Intent.setClassName (or force a chooser by using Intent.createChooser)

Activity not appearing on Chooser dialog when using Implicit Intent

I would like to start MyBrowser, an application that show web pages like the built-in Browser app, from another application, IntentsLab.
I followed Launch custom android application from android browser to setup the intent, and also the official Intent and Intent-filters guide which does says "You need to include CATEGORY_DEFAULT to receive implicit intents".
So my intent-filter is so written:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.categroy.DEFAULT" />
<data android:scheme="http" />
</intent-filter>
The code of the parent activity in IntentsLab to start the new activity is:
Intent baseIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
String title = "Use Browser";
Intent chooserIntent = Intent.createChooser(baseIntent, title);
if(chooserIntent != null) startActivity(chooserIntent);
The MyBrowser application does not show up on the chooser dialog. However, when I created an Activity inside the IntentsLab and added to it a same intent-filter, this activity shows up in the chooser dialog. Is there anything wrong with the code? Or is there any difference between implicit intent towards Activities in a same Application with those in a different one?
Provided my AndroidManifest.xml for the MyBrowserActivity. It works perfectly for me. Even I am doing the coursera Android programming class :)
<activity android:name=".MyBrowserActivity" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- TODO - Add necessary intent filter information so that this
Activity will accept Intents with the
action "android.intent.action.VIEW" and with an "http"
schemed URL -->
</activity>

Dropbox Core API for Android: Not returning after Authentication

I am developing two android applications:
the first is a normal application with a launcher and so on
the other is a application only with a viewer activity (see the manifest):
<activity
android:name=".MyActivity"
android:icon="#drawable/icon"
android:label="#string/dropbox" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.dropbox.client2.android.AuthActivity"
android:configChanges="orientation|keyboard"
android:launchMode="singleTask" >
<intent-filter>
<data android:scheme="db-XXXXX" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The plan is, that the first application does not need internet permissions and the second is some kind of add-on to the first.
The second application should sync a file with Dropbox (with the Core API, not with the Sync API).
From my first app, I start 'MyActivity' from the second app like this:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("my.package","my.package.MyActivity"));
intent.putExtra("filePath", "/myFile.txt");
startActivityForResult(intent, SYNC_REQUEST);
That works. The Activity comes up and there, if not authorized yet, the user must press a button. Then the following code will be executed
AndroidAuthSession session = buildSession();
mApi = new DropboxAPI<AndroidAuthSession>(session);
mApi.getSession().startAuthentication(MyActivity.this);
If the user does not have dropbox installed, the browser will pop up.
Now my troubles begin:
As soon as the user presses 'Accept' or 'Decline', the browser does not disappear. It stays open and MyActivity does not get resumed (onResume is not called!).
I found out, that adding
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
before starting MyActivity from my first application will solve the problem, but then I can not listen/wait for the result of MyActivity.
I am frustrated. Can anyone help me or give me some advise?
Thanks!
When you are using startAuthentication method. It will automatically start the AuthActivity. you do not need to call startActivity() explicitly. Then in onResume method of your activity write this code :
#Override
protected void onResume()
{
super.onResume();
if (if dropBoxAPI!= null && dropboxAPI.getSession().authenticationSuccessful())
{
try {
dropboxAPI.getSession().finishAuthentication();
oAuth2Token = dropboxAPI.getSession().getOAuth2AccessToken();
}
catch (IllegalStateException ie)
{
ie.printStackTrace();
}
}
}

Categories

Resources