Multiple launchers for one Application with API 17 - java

I have my application and I would like to have two different launchers that each launch different activities. They should all be bundled into one apk and not two separate applications. I know this is possible, example in the XKCD Browser on the Google play store. I have already tried implementing this segment in the second activity I need to be in the launcher:
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
This results in the first activity declared as MAIN to be launched when clicking the second launcher. I have also tried:
<intent-filter>
<action android:name="android.intent.action.ACTIVITY_NAME"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
As well as:
<intent-filter>
<action android:name=ACTIVITY_NAME"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
Which achieves the same result. I need this to function down to API 17. Ideas?

You should have a main activity with:
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
And any other activity with only the category part:
<intent-filter>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

Maybe you need to put the same date frome place where your call intent for start app
<activity
android:name="com.spectrum.media.activity.InitializationScreen"
android:configChanges="orientation|keyboardHidden|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.MUSIC_PLAYER" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.APP_MUSIC" />
<action android:name="android.intent.action.MEDIA_BUTTON" />
<action android:name="android.media.AUDIO_BECOMING_NOISY" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:mimeType="audio/*" />
<data android:mimeType="application/ogg" />
<data android:mimeType="application/x-ogg" />
<data android:mimeType="application/itunes" />
</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:mimeType="audio/*" />
<data android:mimeType="application/ogg" />
<data android:mimeType="application/x-ogg" />
<data android:mimeType="application/itunes" />
</intent-filter>
<intent-filter android:priority="-1">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="content" />
<data android:mimeType="audio/*" />
<data android:mimeType="application/ogg" />
<data android:mimeType="application/x-ogg" />
<data android:mimeType="application/itunes" />
</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" />;-->
</intent-filter>
</activity>
And parse this scheme in first activity and run others if necessary.

Related

My NFC Scan application starts only if NFC Type 2

I've made an NFC application who can reads NFC tag. It works well. (With all types)
But since yesterday i'm trying to start automatically my app once a NFC tag is maintained against my device.
So i've updated my Manifest :
<activity android:name=".MainActivity" android:screenOrientation="portrait" >
<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.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="#xml/nfc_tech_filter" />
</activity>
Then, here is my nfc_tech_filter.xml
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.IsoDep</tech>
<tech>android.nfc.tech.NfcA</tech>
<tech>android.nfc.tech.NfcB</tech>
<tech>android.nfc.tech.NfcF</tech>
<tech>android.nfc.tech.NfcV</tech>
<tech>android.nfc.tech.Ndef</tech>
<tech>android.nfc.tech.NdefFormatable</tech>
<tech>android.nfc.tech.MifareClassic</tech>
<tech>android.nfc.tech.MifareUltralight</tech>
</tech-list>
</resources>
And surprise, it works only when I hold a NFC Type 2 against my device.
I've try with my appartement key (Mifare Classic) and my bank card (IsoDep), and it doesn't launch my app...
I specify that it works when my app is already started.
Any idea?
EDIT :
This is my Manifest right now :
<activity android:name=".MainActivity" android:screenOrientation="portrait" >
<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.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="#xml/nfc_tech_filter" />
</activity>
Now, when I pass my bank card, it opens the application but doesn't display any result.
Parcelable[] rawMessages =
intent.getParcelableArrayExtra(NfcAdapter.EXTRA_TAG);
rawMessages variable is NULL after that. Same if I put NfcAdapter.EXTRA_NDEF_MESSAGES
ACTION_TAG_DISCOVERED:
This intent is started if no activities handle the ACTION_NDEF_DISCOVERED or ACTION_TECH_DISCOVERED intents.
https://developer.android.com/guide/topics/connectivity/nfc/nfc
You get this Intent when no others has captured it, so there is something wrong in your setup.
You can capture it explicitly like:
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
</intent-filter>

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 fix not show application icon into app drawer?

In my application i want use deeplink. when added intent-filter for deeplink in launcher activity, gone application icon into app drawer!
But when remove deeplink intent-filter show application icon into app drawer.
Manifest codes :
<activity android:name=".Pages.Splash.SplashPage">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<!-- DeepLink -->
<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:pathPrefix="/gaming"
android:scheme="http" />
<data
android:host="example.com"
android:pathPrefix="/gaming"
android:scheme="http" />
</intent-filter>
</activity>
when use above codes, not show application icon in app drawer, but when remove below codes from manifest show icon.
<!-- DeepLink -->
<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:pathPrefix="/gaming"
android:scheme="http" />
<data
android:host="example.com"
android:pathPrefix="/gaming"
android:scheme="http" />
i want when open users click on link, first start launcher activity, then dynamically open another activity.
How can i fix it?
You should create two separate intent-filters. Try below code in your <activity/> tag:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- DeepLink -->
<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:pathPrefix="/gaming"
android:scheme="http" />
<data
android:host="example.com"
android:pathPrefix="/gaming"
android:scheme="http" />
</intent-filter>
Finally, your code will look as below:
<activity android:name=".Pages.Splash.SplashPage">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- DeepLink -->
<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:pathPrefix="/gaming"
android:scheme="http" />
<data
android:host="example.com"
android:pathPrefix="/gaming"
android:scheme="http" />
</intent-filter>
</activity>

My app doesnt show as a suggestion in file explorer?

My project is a download manager that open a link to download something.
I want to add this feature that when I use chrome Bower and click in a link , my application suggest to user to use it for opening the link.
I used
<category android:name="android.intent.category.DEFAULT"/>
but there is no effect.
here is my manifest:
<application
android:allowBackup="true"
android:icon="#drawable/gigaget"
android:label="#string/app_name">
<activity
android:name=".ui.main.MainActivity"
android:label="#string/app_name"
android:theme="#style/Theme.App.Blue"
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="us.shandian.giga.intent.DOWNLOAD"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:mimeType="application/*"
android:host="*"
android:scheme="http"/>
<data
android:mimeType="application/*"
android:host="*"
android:scheme="https"/>
</intent-filter>
</activity>
<activity
android:name=".ui.main.DetailActivity"
android:label="#string/app_name"
android:theme="#style/Theme.App.Blue">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ui.web.BrowserActivity"
android:label="#string/browser"
android:theme="#style/Theme.App.Blue">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity-alias
android:name=".ui.web.BrowserActivity-share"
android:label="#string/open_with_gigaget"
android:targetActivity=".ui.web.BrowserActivity">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/*"/>
</intent-filter>
</activity-alias>
<activity
android:name=".ui.settings.SettingsActivity"
android:label="#string/settings"
android:theme="#style/Theme.App.Blue">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.nononsenseapps.filepicker.FilePickerActivity"
android:label="#string/app_name"
android:theme="#style/Theme.App.Blue">
</activity>
<service
android:name=".service.DownloadManagerService"/>
</application>
with this permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
why I cant see my application as suggested app for download like the other applications.
any help?
You need to tell android that your app should become part of the chooser
In the manifest you have to declare that you have an activity that can handle the relevant content
<manifest ... >
<application ... >
<activity android:name=".MyDownloadActivity" ...>
<intent-filter >
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:mimeType="*/*"
android:scheme="file" />
</intent-filter>
<intent-filter > <!-- mime only SEND(_TO) -->
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.CATEGORY_OPENABLE" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
</application>

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