Trouble with init branch.io - java

I use branch.io for work with app link. AndroidManifest has intent-filter for Branch URI scheme:
<intent-filter>
<data android:scheme="***" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Also AndroidManifest has intent-filter for App Links:
<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:scheme="https" android:host="***.app.link" />
<data
android:host="***-alternate.app.link"
android:scheme="https"/>
<data
android:host="***.test-app.link"
android:scheme="https"/>
<data
android:host="***-alternate.test-app.link"
android:scheme="https"/>
LaunchMode for AppLinkActivity is singleTask. I init Branch in Application, in onCreate:
Branch.getAutoInstance(this);
After open AppLinkActivity I get instance and I init session:
Branch branch = Branch.getInstance(getApplicationContext());
branch.initSession((referringParams, error) -> {
LogFileUtil.writeLog("Finish init session");
if (error == null) {
//Кое что делаю
} else {
//Кое что делаю
}
}, this.getIntent().getData(), this);
When I open my app across AppLink referringParams isn't empty. And I can get required data.
But when app is open and I click AppLink from other app, that referringParams is empty. I think the problem is init Branch. How I can fix it?

You need to make sure that you override the onNewIntent() method in your AppLinkActivity. This will ensure that the same intent is returned.
Add the following snippet to your AppLinkActivity:
#Override
protected void onNewIntent(Intent intent) {
this.setIntent(intent);
}

Solution - you need to make AppLinkActivity class main. This activity must have one more intent-filter:
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

Related

Add my browser in the default browser selection list in android?

Following the suggestions from How to add my browser in the default browser selection list in android?. I have specified my Intent in the manifest file:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
<data android:scheme="https"/>
</intent-filter>
I have also added the permission:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
But still my browser is not showing in the default app options for the browser category in the settings.
Do I need to do anything else for my app to show up in the default options for browser?
Try to include the <category android:name="android.intent.category.BROWSABLE" /> in your target activity's intent-filter as developer documentation said:
If the user is viewing a web page or an e-mail and clicks on a link in the text, the Intent generated execute that link will require the BROWSABLE category, so that only activities supporting this category will be considered as possible actions.
It is required in order for the intent-filter to be accessible from a clickable link. Without it, clicking a link cannot resolve to your app.
<activity ...>
<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" />
<data android:scheme="https" />
</intent-filter>
</activity>
.
Additional Tip: (If you want to force your app to be the default browser)
Android App Links on Android 6.0 (API level 23) and higher allow an app to designate itself as the default handler of a given type of link. If the user doesn't want the app to be the default handler, they can override this behavior from their device's system settings.
To enable link handling verification for your app, set android:autoVerify="true" in intent-filter tag:
<activity ...>
<intent-filter android:autoVerify="true">
...
</intent-filter>
</activity>
You need to consider various cases that may be applicable.
Please refer the intent-filters below. Also link is provided at the end.
<activity android:name="BrowserActivity"
android:label="#string/application_name"
android:launchMode="singleTask"
android:alwaysRetainTaskState="true"
android:configChanges="orientation|keyboardHidden"
android:theme="#style/BrowserTheme"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.speech.action.VOICE_SEARCH_RESULTS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<!-- For these schemes were not particular MIME type has been
supplied, we are a good candidate. -->
<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" />
<data android:scheme="https" />
<data android:scheme="about" />
<data android:scheme="javascript" />
</intent-filter>
<!-- For these schemes where any of these particular MIME types
have been supplied, we are a good candidate. -->
<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:scheme="http" />
<data android:scheme="https" />
<data android:scheme="inline" />
<data android:mimeType="text/html"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="application/xhtml+xml"/>
<data android:mimeType="application/vnd.wap.xhtml+xml"/>
</intent-filter>
<!-- We are also the main entry point of the browser. -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<!-- The maps app is a much better experience, so it's not
worth having this at all... especially for a demo!
<intent-filter android:label="Map In Browser">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/postal-address" />
</intent-filter>
-->
<intent-filter>
<action android:name="android.intent.action.WEB_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MEDIA_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
Look at the different types of intent-filters you might need in order to cover all possible cases.
Refer to this link - complete manifest file of froyo browser.
Consider using CATEGORY_APP_BROWSER with your main filter:
Used with ACTION_MAIN to launch the browser application. The activity should be able to browse the Internet.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.APP_BROWSER" />
</intent-filter>
You can do it with Intent-Filter by making your Activity Browsable.using below code in Android manifest File.
You can do it with Launcher Activity.
<activity android:name="BrowsableActivity">
<intent_filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent_filter>
</activity>
And you must provide scheme as http and https for links to be open with your Application.
As mentioned in documentation over developer.android.com
you need to set intent filer as below
<activity ...>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<!-- Include the host attribute if you want your app to respond
only to URLs with your app's domain. -->
<data android:scheme="http" android:host="www.example.com" />
<category android:name="android.intent.category.DEFAULT" />
<!-- The BROWSABLE category is required to get links from web pages. -->
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
You can achieve this programatically, like this:
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
share.setPackage("your.app.package.name");
startActivity(share);
and also it will be good, if you put a check for the app existence on phone.
Happy Coding :)

How to set intent filter for just one file extension?

I'm searching for a solution to set intent filters for just one file extension. I tried many examples on the web and the following is the only one that worked:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:mimeType="*/*"
android:pathPattern=".*\\.life"
android:scheme="file" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:mimeType="*/*"
android:pathPattern=".*\\.life"
android:scheme="content" />
</intent-filter>
The problem is that every file can now be opened with my app, not only the ".life" files. What is wrong in the intent filters? I also tried different MIME-Types and try to add host but then it doesn't work anymore.

I don't want my app to appear on the chooser dialog when opening URL's

I have an action button on my action bar that opens a fixed url when clicked, it works fine, but I dont want my own app to appear on the chooser dialog "complete action using", it should just appears the phone default browsers (like Chrome or Mozilla), actually It appears Chrome and my app as options to open the url. I implemented this code from here: http://developer.android.com/intl/es/guide/components/intents-common.html
This is my code:
//Manifest.xml
<activity
android:name="pepubli.com.Controlador.Ciudad_Escogida"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http"/>
<category android:name="android.intent.category.DEFAULT" />
<!-- The BROWSABLE category is required to get links from web
pages. -->
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
//Ciudad_Escogida.Java
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == R.id.web_page){
Uri webpage = Uri.parse("http://www.pepubli.com");
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
return super.onOptionsItemSelected(item);
}
remove this line from your application manifest.
<category android:name="android.intent.category.BROWSABLE" />
also remove
<data android:scheme="http"/>
and replace
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
to
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
so your intent filter should be like
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

Open .txt attachment from email in Android App

I've defined an intent-filter in my AndroidManifest.xml so that it should show my app as an option to open text files:
<activity
android:name=".Hosts.AddHostActivity"
android:label="#string/title_activity_add_host" >
<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="text/plain" />
<data android:pathPattern=".*\\.txt" />
<data android:host="*" />
</intent-filter>
</activity>
Then I'm going to handle the opening of the text file like this:
Uri data = getIntent().getData();
if(data != null) {
// Parse text file
}
Although I'm not sure if that's the right way to go about it. Currently my app does not show in the list of apps that can open text files though so I assume something in my intent-filter definition is wrong?
I've updated my intent filter to change the mimeType and add BROWSABLE but still no joy.
<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:mimeType="text/plain" />
</intent-filter>
Turns out mimeType is the best way to go and you don't need the other junk :)

android intent-filter <data> is not working correctly

I am trying to have my application intercept on a specific URL in browser. following is my code in the Manifest:
<activity
android:name="com.myactivity.RootActivity">
<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="http" />
<data android:host="subdomian.maindomain.com" />
</intent-filter>
</activity>
it is working fine at the moment, when I open the link http://subdomain.maindomain.com/ , a dialog comes up with my activity listed on it.
but when I add android:path in the intent-filter like below, it stops working, it doesn't even work with simple url without the path.
<activity
android:name="com.myactivity.RootActivity">
<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="http" />
<data android:host="subdomian.maindomain.com" />
<data android:path="myPath" />
</intent-filter>
</activity>
am I doing something wrong here?
I tested what you said using these links and its working for me
<data android:scheme="http" />
<data android:host="developer.android.com" />
<data android:path="/guide/topics/manifest/data-element.html"/>
And the intent i used is
Intent browserIntent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://developer.android.com/guide/topics/manifest/data-element.html"));
startActivity(browserIntent);
The android:path must match after the host url that you gave for it to work ?
Can you specify what URL did you use ?
Read this link for help

Categories