Created
June 25, 2014 06:54
-
-
Save khris/02b04d43a4f51e59c88b to your computer and use it in GitHub Desktop.
Insecure link handling with `TextView`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest | |
... | |
package="net.tekhnokracy.intentredirect.app" | |
... > | |
<application ... > | |
<activity | |
android:name="net.tekhnokracy.intentredirect.app.DummyActivity" | |
android:exported="false" > | |
<intent-filter> | |
<action android:name="android.intent.action.VIEW" /> | |
<category android:name="android.intent.category.DEFAULT" /> | |
<data android:scheme="net.tekhnokracy.intentredirect.app" /> | |
</intent-filter> | |
</activity> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
public class DummyActivity extends Activity { | |
private void someMethod() { | |
super.onCreate(savedInstanceState); | |
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); | |
intent.putExtra(SearchManager.QUERY, mMovie.title); | |
String htmlSrc = String.format("<a href=\"%s:%s\">LINK START</a>", | |
getPackageName(), intent.toUri(0)); | |
TextView textMisc = (TextView) findViewById(R.id.text_misc); | |
textMisc.setMovementMethod(new LinkMovementMethod()); | |
textMisc.setText(Html.fromHtml(htmlSrc)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
public class DummyActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
Intent intent = getIntent(); | |
if (!getPackageName().equals(intent.getStringExtra(Browser.EXTRA_APPLICATION_ID))) { | |
finish(); | |
return; | |
} | |
try { | |
Uri converted = intent.getData().buildUpon().scheme("intent").build(); | |
Intent origIntent = Intent.parseUri(converted.toString(), Intent.URI_INTENT_SCHEME); | |
startActivity(origIntent); | |
} catch (URISyntaxException e) { | |
e.printStackTrace(); | |
} finally { | |
finish(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment