I need to wake up my application while clicking on the hyperlink that i got via email.
Any Idea? Please help on this.
Thanks in Advance.
This can be done by using a custom URI scheme (like those market: urls that are handled by the Market app), or by using a custom action with the intent: scheme.
In both cases you should create an activity that will be started when the user clicks your link.
Let's first go through the first case:
1. A custom scheme
Start by declaring the activity in the manifest:
<activity android:name="LinkHandler">
<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="SACPK" android:host="www.anyhost.com" />
</intent-filter>
</activity>
In this case, the link should look like SACPK://www.anyhost.com/anything-goes-here.
Your activity will receive the whole link in the intent, so you can process it and decide what to do next, based on query parameters or path:
public class LinkHandler extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Uri uri = getIntent().getData();
// this is the URI containing your link, process it
}
}
2. intent: scheme
This time the link should have the following format:
intent:#Intent;action=com.sacpk.CUSTOM_ACTION;end
And the intent-filter should contain a corresponding action that you will check in your activity:
<intent-filter>
<action android:name="com.sacpk.CUSTOM_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
And in your onCreate method:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if ("com.sacpk.CUSTOM_ACTION".equals(getIntent().getAction()) {
// then you really know you got here from the link
}
}
The downside to this method is that you won't get any data with your intent.
This whole answer is based on commonsware's brilliant book, The Busy Coder's Guide to Advanced Android Development.
Related
What I am trying to achieve is to open Activity automatically when URL is clicked on a browser, notes app or messenger.
So I have this URL format:
http://testsite.com/code/AB1234
In AndroidManifest.xml, I have set Intent filter for Activity:
<activity android:name=".HomeActivity">
<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="testsite.com"
android:pathPrefix="/code"
android:scheme="http" />
</intent-filter>
</activity>
In HomeActivity, just getting code from URL and showing it on Toast:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
String code = getIntent().getData().getLastPathSegment();
Toast.makeText(this, code, Toast.LENGTH_LONG).show();
}
When I click on link, system is showing my application and browser application on application chooser. I know that this URL can be handled browser also. I would like to know how to make my intent filter to have priority if it is possible.
Is it possible to open my app automatically? If yes how to make it? How I should change my intent filter?
If you have control over the link, the easiest way to achieve what you want is to set unique scheme for your app.
<data android:host="testsite.com"
android:pathPrefix="/code"
android:scheme="myapp" />
I need a way to include a link in an email which either opens a mobile app or redirects the user to a website depending on whether the mobile app is installed or not. I need a solution for both Android and IOS, it is there a set practice on how to achieve this?
Thanks!
You need a combo of answers here I think.
For iOS, You can replace http:// with itms:// or itms-apps:// to avoid redirects.
How to link to apps on the app store
For Android, I think you'll want to look at the <intent-filter> element of your Mainfest file. Specifically, take a look at the documentation for the <data> sub-element.
Make a link in the Android browser start up my app?
On Android, you need to handle this via Intent Filter:
<activity
android:name="com.permutassep.IntentEvaluator"
android:label="#string/app_name">
<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="your/url"
android:scheme="http" />
<data
android:host="your/url"
android:scheme="https" />
</intent-filter>
</activity>
And the class you need to handle the intent data should look like this:
public class IntentEvaluator extends BaseActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = null;
if(getIntent() != null && getIntent().getData() != null){
// Do whatever you want with the Intent data.
}
}
}
Taken from an app I developed: https://raw.githubusercontent.com/lalongooo/permutas-sep/master/app/src/main/java/com/permutassep/IntentEvaluator.java
Currently I am having two web pages, home and about. The about is deep link in that ,so when i click on the link , android gives me the option to use a browser to or my own app to open that link. I would like to explicitly open that link in my app.I don't want list of the apps to handle it. Is this possible? Below is my code:
AndroidManifest.xml
<activity
android:name=".AboutPage"
android:label="#string/about_page">
<intent-filter android:label="#string/filter_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="appindexing.robscv.info"
android:pathPrefix="#string/aboutHTML"/>
</intent-filter>
</activity>
AboutPage.java
public class AboutPage extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.about_page);
// Enable the "Up" button for more navigation options
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
onNewIntent(getIntent());
}
protected void onNewIntent(Intent intent){
String action = intent.getAction();
String data = intent.getDataString();
Log.d(action, data);
}
}
In short. No
But
Its coming.
This is a feature scheduled for release in Android M.
All you have to do is add this to the Manifest
<intent-filter android:label="#string/filter_name" android:autoVerify="true">
//...categories etc
</intent-filter>
More info here
Just FYI what this will actually do is deep link directly to the app and if multiple apps on a users phone autoVerify then it will throw up the prompt.
This question already has answers here:
How to implement my very own URI scheme on Android
(5 answers)
Closed 7 years ago.
I want to make an android app that can be used as a default application for opening a certain kind of link (like if I click http://facebook.com it will show me suggested app to open that link, browser or facebook's app)
These are called Implicit Intents
Assume you want to open your app on web link click with link "myApp://someapp"
then in your App Manifest
<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:scheme="myApp" android:host="path" />
</intent-filter>
</activity>
Whenever you click the above link, it will suggest to open your app.
If you want to developed application that allow the other application to complete the action using your application, for example in your case you want to handle the any of url user click, your application will be listed for complete the action. You have to create the activity that will handle the deep linking. For that you need to add some attributes to your handle activity in your android manifest. see below example
The following XML snippet shows how you might specify an intent filter in your manifest for deep linking. The URIs that start with “http”
<activity
android:name="com.example.android.BrowseActivity"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
<data android:scheme="http"
android:host="www.example.com"
android:pathPrefix="/gizmos" />
<!-- note that the leading "/" is required for pathPrefix-->
<!-- Accepts URIs that begin with custom url "example://gizmos” -->
<data android:scheme="com.example.android"
android:host="gizmos" />
</intent-filter>
</activity>
Once you've added intent filters with URIs for activity content to your app manifest, Android is able to route any Intent that has matching URIs to your app at runtime.
Once the system starts your activity(BrowseActivity) through an intent filter, you can use data provided by the Intent to determine what you need to render. Call the getData() and getAction() methods to retrieve the data and action associated with the incoming Intent. You can call these methods at any time during the lifecycle of the activity, but you should generally do so during early callbacks such as onCreate() or onStart().
Here’s a snippet that shows how to retrieve data from an Intent inside BrowseActivity:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
}
Let me know if you need more help on this point thank you.
Phonegap Application lunching Problem
it is manifest file:
<activity
android:name=".MainActivity"
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" />
<data
android:scheme="cedemo" android:host="com.example.shcema.MainActivity"/>
</intent-filter>
</activity>
it is my main activity:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}}
But when I click "Launch Application" link then i get this alert.
please, help me any one.
You missed CATEGORY_BROWSABLE in your intent-filter.
Quote from Android Docs:
Activities that can be safely invoked from a browser must support this category. For example, 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. By supporting this category, you are promising that there is nothing damaging (without user intervention) that can happen by invoking any matching Intent.
So your intent-filter must be like:
<intent-filter>
<data android:scheme="cedemo" android:host="com.example.shcema.MainActivity"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
See more at : Make a link in the Android browser start up my app?
This won't work. because how Android can know which App I've start on this custom URI call?
So you first have to let the android know that a custom URI exists which can receive such calls and then whenever that custom URI is invoked by any app either native or hybrid, OS will automatically forward it to the registered app i.e. able to receive such calls.
Read this Android docs tutorial:
Allowing Other Apps to Start Your Activity
http://developer.android.com/training/basics/intents/filters.html
Here is an example how one app can call other app. Launch an application from another application on Android
And here is custom plugin which makes easier to open another app from the Cordova/phonegap App.
https://github.com/lampaa/org.apache.cordova.startapp