相关疑难解决方法(0)

使用意图URI启动我的应用程序

我知道StackOverflow已经多次询问过这个问题,但我还没有找到解决方案.我的应用会发送一封电子邮件,其中包含一个链接,点击后应启动该应用.

根据@hackbod的说法,最好的方法是使用Intent URI(参见本节).这是我设置意图的代码并将其放入电子邮件正文中:

Intent customIntent = new Intent(CUSTOM_ACTION);
customIntent.setPackage(MY_PACKAGE);
customIntent.addCategory(MY_CAT_BROWSABLE);
customIntent.addCategory(MY_CAT_DEFAULT);

String customUri = customIntent.toUri(Intent.URI_INTENT_SCHEME);

String emailBody = getString(R.string.intent_link, customUri);

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_SUBJECT, "Recommending vid");
intent.putExtra(Intent.EXTRA_TEXT   , Html.fromHtml(emailBody));
try {
    startActivity(Intent.createChooser(intent, "Choose email client:"));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)

这是我从LogCat得到的:

08-25 17:01:23.333: VERBOSE/Test URI(16987): intent:#Intent;action=com.test.project.action.VIEW_VID_FROM_LINK;category=android.intent.category.DEFAULT;category=android.intent.category.BROWSABLE;package=com.test.project;end
08-25 17:01:23.338: VERBOSE/Test email text(16987): Hi,<br><br>Testing intents from an email.<br><br> A standard website: <a href=http://www.google.com>Go to Google</a>.<br><br> This link should …
Run Code Online (Sandbox Code Playgroud)

email android uri android-intent

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

android-intent ×1

email ×1

uri ×1