Link to an android application from SMS/mail - android

I would like to know if we can have a link in a SMS that would be handle by my application. For example a link which would look like myapp://blabla. And by clicking on it myapp would be open with the link as an argument.
This question also refers to email, either from a file with a special extension or a link like in the SMS.
Thanks a lot for your help.
Edit 31/01
Actually, I did what Greg suggested it but it doesn't work. Such a link (myapp://blabla) is not clickable in a SMS/email...When I replace myapp with http as a scheme, it works (Android asks me wether it should open the link with myapp or the browser). But myapp://blabla isn't clickable with myapp as a scheme.
Here is my code:
<application android:icon="#drawable/icon" android:label="#string/app_name"
android:debuggable="true">
<activity android:name=".myapp"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"
android:launchMode="singleTask"
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.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="myapp" android:host="blabla" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"></activity>
<activity android:name=".SettingsActivity"></activity>
</application>

Yep you can with an intent filter.
Basically in your android Manifest, choose an activity that you want to be the one that handles the given url.
<activity android:name=".myactivies.MyActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="myapp" android:host="blabla" />
</intent-filter>
</activity>
Then inside your activity you can get the url by calling getData() on the intent.

Related

Using Deep link to open app with external link

I am trying to make my android app open when the user presses on a link to our website.
I was following this documentation but it is not working for me as it always opens the browser instead of asking if I would like to continue with the browser or the app. What am I doing wrong?
here is my manifest
<activity
android:name=".presentation.MainActivity"
android:exported="true"
android:label="#string/app_name"
android:theme="#style/Theme.LegendaryCollectionsAndroid.NoActionBar"
android:allowTaskReparenting="true"
>
<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"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data
android:host="www.legendarycollections.net"
android:path="/reset"
android:scheme="https"></data>
</intent-filter>
</activity>
check your website association here.

How to avoid multiple open in particular application in android?

I have already opened my android application. I used url scheme, so that my app can be opened from the users email. But if i try to open my application from clicking email link from the web browser, it will open that application in separate window. (Please see my attached screen short picture) .
How to avoid my application to open twice separately?
<activity
android:name="com.mYs3.MainActivity.flash_screen"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="mYs3" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
try this line in your activity block in manifest
android:launchMode="singleTask"

How to make my Android app appear in the share list of another specific app

<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
this is in my manifest file
this will make my app appear on the share list of all apps
but I want my app to appear in the share list of another specific app
and I don't own the other app
Add this code in the activity you want opened first when sharing a content from outside the app, call this method in onCreate()
private void onSharedIntent() {
Intent receiverdIntent = getIntent();
String receivedAction = receiverdIntent.getAction();
String receivedType = receiverdIntent.getType();
if (receivedAction.equals(Intent.ACTION_SEND)) {
// check mime type
if (receivedType.startsWith("text/")) {
String receivedText = receiverdIntent
.getStringExtra(Intent.EXTRA_TEXT);
if (receivedText != null) {
//do your stuff
}
}
else if (receivedType.startsWith("image/")) {
Uri receiveUri = (Uri) receiverdIntent
.getParcelableExtra(Intent.EXTRA_STREAM);
if (receiveUri != null) {
//do your stuff
fileUri = receiveUri;// save to your own Uri object
Log.e(TAG,receiveUri.toString());
}
}
} else if (receivedAction.equals(Intent.ACTION_MAIN)) {
Log.e(TAG, "onSharedIntent: nothing shared" );
}
}
Add this in Manifest,
<activity
android:name="your-package-name.YourActivity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>
In order to do this, you need to know the Intent that the application is creating and create an IntentFilter that will add your application to the specific list.
Receiving an Implicit Intent on Intents and Filters (Android Developers)
The application probably uses a specific action name that you could hook to.
<intent-filter . . . >
<action android:name="com.example.project.SHOW_CURRENT" />
<action android:name="com.example.project.SHOW_RECENT" />
<action android:name="com.example.project.SHOW_PENDING" />
. . .
</intent-filter>
Or it could be looking for applications accepting a certain type of file.
<intent-filter . . . >
<data android:mimeType="video/mpeg" android:scheme="http" . . . />
<data android:mimeType="audio/mpeg" android:scheme="http" . . . />
. . .
</intent-filter>
The name of the application and what it is sharing would help me give a more specific response.
- Add below code into your Project AndroidManifest.xml file in Specific Activity.
<activity
android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
- Add the following line of code into your project specific Activity.
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if ("android.intent.action.SEND".equals(action) && type != null && "text/plain".equals(type)) {
Log.println(Log.ASSERT,"shareablTextExtra",intent.getStringExtra("android.intent.extra.TEXT"));
}
add this to your mainefist file
<activity android:name=".ShareActivity">
<intent-filter
android:label="Share with my app">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
this link may help you
this worked well for me for getting all web pages, for my app that scans for mp3 files on a web page, and sets alarms from them. It opens up my new url activity, when you share a web page:
Here is what this code results in:
<activity
android:name=".NewUrl"
android:label="#string/title_activity_new_url"
android:windowSoftInputMode="stateUnchanged">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/*"/>
</intent-filter>
</activity>
Then to receive the link in the app, I got awsome info from this tutorial:
http://code.tutsplus.com/tutorials/android-sdk-receiving-data-from-the-send-intent--mobile-14878
I want to add something to the above answers. Keep in mind that you should put another intent filter to prevent overriding in case you are using multiple categories in an activity.
For example, the following will prevent your application to be shown on the application list in your device because it doesn't detect it as launcher activity.
Don't do this
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<!-- DO NOT DO THIS-->
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
</application>
Instead do following
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- USE SEPERATE INTENT FILTER -->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
</application>
Note: Change mimeType according to your use.
Verdict: If you are using more than one category in intent filter use them separately.
I would check to see if there is any API for this app you want to work with.
If so, you can benefit by knowing
a more specific implicit action for your filter
or perhaps add a category other than DEFAULT
If you can find something like these, it would be unlikely to be seen by other apps.
Also make sure to have you Activity NOT labeled with android:exported="false", otherwise it won't show up in other applications' intent choosers (only your own)
E.g. AndroidManifest.xml
<activity
android:name=".ReceiveImageActivity"
android:exported="true"> <!-- here -->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

Intent Filter to Launch My Activity when custom URI is clicked

I am trying to allow a URI to be registered to open up with my app. Like the PatternRepository on the Blackberry and the CFBundleURLName/CFBundleURLSchemes on the iPhone. How do I achieve the same results on the Android?
The system will be sending emails with the following link: myapp://myapp.mycompany.com/index/customerId/12345. The idea is that the user should be able to click on the link to open up the customer activity in the application.
I've tried numerous suggestions from other SO posts but I cannot get the OS to recognize the pattern and open my app.
On The Gmail app it looks like this: myapp://myapp.mycompany.com/index/customerId/12345. It recognizes and underlines the myapp.mycompany.com/index/customerId/12345 portion of the link and it opens it in a browser. The myapp:// part is not linkified.
The standard mail application treats the entire link as plain text.
What am I missing here?
PS: I've already looked at
How to implement my very own URI scheme on Android
and How to register some URL namespace (myapp://app.start/) for accessing your program by calling a URL in browser in Android OS?
The Manifest:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="2"
android:versionName="0.0.8"
package="com.mycompany.myapp.client.android">
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="7"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:label="#string/app_name"
android:name="myappApplication"
android:icon="#drawable/ic_icon_myapp"
android:debuggable="true">
<activity
android:label="My App"
android:name=".gui.activity.LoginActivity"
label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".gui.activity.CustomerDetailActivity" >
<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>
<activity android:name=".gui.activity.CustomerDetailActivity"/>
<activity android:name=".gui.activity.CustomerImageViewerActivity" />
<activity android:name=".gui.activity.CustomerListActivity" android:configChanges="orientation|keyboardHidden"/>
<activity android:name=".gui.activity.HomeActivity" android:configChanges="orientation|keyboardHidden"/>
<activity android:name=".gui.activity.AboutActivity" android:configChanges="orientation|keyboardHidden"/>
<activity android:name=".gui.activity.AccountActivity" android:configChanges="orientation|keyboardHidden" />
</application>
</manifest>
The final solution was a hacky workaround to cover all bases. The email now also contains an attachment with an extension that is registered to open with the app.
AndroidManifest.xml :
<activity android:name=".gui.activity.CustomerDetailActivity" >
<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="myapp.mycompany.com" />
</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"
android:host="myapp.mycompany.com" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/myapp" />
</intent-filter>
</activity>
When I was working on OAuth with Google Calendar, I had to add this filter to the Activity I wanted to receive the callback:
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:scheme="yourapp" android:host="goog"></data>
</intent-filter>
The when the browser invoked the yourapp://goog URL, it would return to my Activity.
You can get around the issue of GMail not linking non-standard protocols by using a standard HTTP URL with a 302 redirect. You could either set it up on your website's webserver or application server, or for the quick and dirty test you could use a URL shortener like http://bit.ly.
This is solution for me. Thanks #DanO
<intent-filter>
<data android:scheme="yourcustomname"/>
<data android:host="*"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Have you dried adding a category to your intent-filter:
<category android:name="android.intent.category.BROWSABLE" />
You could always try sending your emails using HTML and then use an <a> tag around to create the URL. I don't think there is a way to change the way the Gmail or Mail parse their text, since they probably use the Linkify class.
Another option would be use use http:// and then just parse for a specific custom subdomain which would provide your users with the option to open in a browser or your application.
I just ran into this also, but for standard http: scheme urls. Gmail doesn't appear to add any categories to the Intent. Now I check for BROWSABLE, but I also include a check for !intent.hasCategories() and allow that to go through as well.

Issue with launching Android application via Intents

My problem is thus; I am new to programming on the ANDROID platform and have a 'working' application that piggy-backs on the API-Docs example. I wish it to launch three tabs one containing a list of reports, one a form to file a report and the last to show the geo-located reports. It doesn't appear as a separate application, it instead appears as a list to be launched by the API-Docs example. Below is my manifest code...
<activity android:name=".HelloFlamingos">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />
</intent-filter>
</activity>
<activity android:name=".Controls2" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.TAB" />
</intent-filter>
</activity>
<activity android:name=".List1" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.TAB" />
</intent-filter>
</activity>
<activity android:name=".ReviewTab" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.TAB" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
HelloFlamingos is the initial page that I wish to be displayed, I realise that the intents for this are wrong, have thought about using category: VIEWS, action: DEFAULT, however is seemingly unwilling to work. Thanks!
In what context is the activity started? If you're looking to have the HelloFlamingos activity the first displayed from the Android OS, you should change its category in the manifest to category.LAUNCHER.
If you're looking to start the activity from elsewhere in your app, create an Intent which matches what you've specified (category.SAMPLE_CODE) and use startActivity or startActivityForResult.

Categories

Resources