0

Hi i have to do connectivity between android app and browser. So while clicking a button on browser it should redirect to android app. in android activity i have written

Uri data = getIntent().getData(); 
        if (data.equals(null)) { 
            System.out.println("Data is null");
        } else { 
            String scheme = data.getScheme();
            System.out.println(scheme);
            String host = data.getHost(); 
            int port = data.getPort(); 
            List<String> params = data.getPathSegments();
            String first = params.get(0); // "hello"
            System.out.println(first);

and in manifest i have already given

<intent-filter>
                <data android:scheme="Integration" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

in html on button click i have given <FORM METHOD="LINK" ACTION="Integration://1">

it is throwing a indexoutofboundexception. Please tell me where is the mistake

Updated *I was unnecessarily using intent in an activity. By removing that n parameter in html5 my app is running successfully now.*

Naina
  • 211
  • 1
  • 4
  • 14

1 Answers1

1

Quoting answer from: How to listen for a custom URI

To register a protocol in your android app, add an extra block to the AndroidManifest.xml

I modified the code a little, but thought I'd quote the source too

<manifest>
 <application>
   <activity android:name=".activityToCall">
           <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="scheme" android:host="path"/>
            </intent-filter>
   </activity>
 </application>
</manifest>

Then when a url matching your schema is opened your app will be called to handle it I assume. Taking into consideration that scheme and pathcorrespond to this:

scheme://host/path

After that, in the activity you've set in the manifest to handle this stuff:

Uri data = getIntent().getData(); 
if (!data.equals(null)){ 
    String scheme = data.getScheme(); 
    //Or whatever you needed
}
Community
  • 1
  • 1
Juan Cortés
  • 20,634
  • 8
  • 68
  • 91
  • i updated the code. It is giving index out of bound exception. I dont no y – Naina May 16 '12 at 09:33
  • 1
    `params.get(0)` no parameters means you can't get the first parameter, and therefor `inderOutOfBounds` – Juan Cortés May 16 '12 at 09:35
  • ok. but in html ACTION="Integration://h "> i am passing parameter "h" and in activity code i am taking String first = params.get(0);. If it don't work so in action can i write alone ACTION="Integration://"> – Naina May 16 '12 at 09:40
  • It is running finally. Thanx a ton. I was doing a silly mistake :) – Naina May 16 '12 at 10:13
  • Please upvote the answer if it was useful, I'm glad I was able to help a little. – Juan Cortés May 16 '12 at 10:18