Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intent Filter to Launch My Activity when custom URI is clicked

Tags:

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> 
like image 983
tuxGurl Avatar asked Apr 08 '11 14:04

tuxGurl


People also ask

Can an activity have multiple intent filters?

However, since a component can have multiple intent filters, an intent that does not pass through one of a component's filters might make it through on another. An <intent-filter> element in the manifest file lists actions as <action> subelements. For example: <intent-filter . . . >

What is the purpose of the intent filter?

An intent filter declares the capabilities of its parent component — what an activity or service can do and what types of broadcasts a receiver can handle. It opens the component to receiving intents of the advertised type, while filtering out those that are not meaningful for the component.

How do I start an activity from another app?

If both application have the same signature (meaning that both APPS are yours and signed with the same key), you can call your other app activity as follows: Intent LaunchIntent = getActivity(). getPackageManager(). getLaunchIntentForPackage(CALC_PACKAGE_NAME); startActivity(LaunchIntent);

Which method is used to launch a new activity or get an existing activity to do something new?

Context.startActivity() The Intent object is passed to this method to launch a new activity or get an existing activity to do something new.


2 Answers

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> 
like image 99
tuxGurl Avatar answered Sep 21 '22 04:09

tuxGurl


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.

like image 41
BigFwoosh Avatar answered Sep 21 '22 04:09

BigFwoosh