Return to Snippet

Revision: 42289
at March 2, 2011 22:48 by BenClayton


Updated Code
// This is the definition of the activity in the AndroidManifest.xml file
<activity android:name=".MyActivity" android:label="@string/app_name">
	<!-- open the app when a foo://www.example.com link is clicked -->
	<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="foo" />
	</intent-filter>
</activity>

// Here's how to get the data out inside the activity itself. Put in the onCreate function
Intent intent = getIntent();
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
 Uri uri = intent.getData();
 Log.i(TAG, "Started by a user clicking " + urlStr);
 doSomethingWithTheUrl(uri.toString(););
}

Revision: 42288
at March 2, 2011 22:45 by BenClayton


Updated Code
// This is the definition of the activity in the AndroidManifest.xml file
<activity android:name=".MyActivity" android:label="@string/app_name">
	<!-- open the app when a foo://www.example.com link is clicked -->
	<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="foo" />
	</intent-filter>
</activity>

// Here's how to get the data out inside the activity itself. Put in the onCreate function
Intent intent = getIntent();
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
 Uri uri = intent.getData();
 String urlStr = uri.toString();
 Log.i(TAG, "Started by a user clicking " + urlStr);
 startAddActivity(urlStr);
}

Revision: 42287
at March 2, 2011 22:45 by BenClayton


Initial Code
// This is the definition of the activity in the AndroidManifest.xml file
<activity android:name=".MyActivity" android:label="@string/app_name">
	<!-- open the app when a foo// link is clicked -->
	<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="foo" />
	</intent-filter>
</activity>

// Here's how to get the data out inside the activity itself. Put in the onCreate function
Intent intent = getIntent();
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
 Uri uri = intent.getData();
 String urlStr = uri.toString();
 Log.i(TAG, "Started by a user clicking " + urlStr);
 startAddActivity(urlStr);
}

Initial URL


Initial Description


Initial Title
Android: Open an Activity when a custom protocol is clicked in the browser

Initial Tags


Initial Language
Java