Android(安卓)Intent的几种用法全面总结
16lz
2022-03-28
Android Intent的几种用法全面总结
Intent, 用法Intent应该算是Android中特有的东西。你可以在Intent中指定程序要执行的动作(比如:view,edit,dial),以及程序执行到该动作时所需要的资料。都指定好后,只要调用startActivity(),Android系统会自动寻找最符合你指定要求的应用程序,并执行该程序。 下面列出几种Intent的用法 显示网页:
调用拨号程序
调用发送短信的程序
|
uninstall apk
- Uri uninstallUri = Uri.fromParts("package", "xxx", null);
- returnIt = new Intent(Intent.ACTION_DELETE, uninstallUri);
install apk
- Uri installUri = Uri.fromParts("package", "xxx", null);
- returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);
play audio
- Uri playUri = Uri.parse("file:///sdcard/download/everything.mp3");
- returnIt = new Intent(Intent.ACTION_VIEW, playUri);
- //发送附件
- Intent it = new Intent(Intent.ACTION_SEND);
- it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
- it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/eoe.mp3");
- sendIntent.setType("audio/mp3");
- startActivity(Intent.createChooser(it, "Choose Email Client"));
- //搜索应用
- Uri uri = Uri.parse("market://search?q=pname:pkg_name");
- Intent it = new Intent(Intent.ACTION_VIEW, uri);
- startActivity(it);
- //where pkg_name is the full package path for an application
- //显示指定应用的详细页面(这个好像不支持了,找不到app_id)
- Uri uri = Uri.parse("market://details?id=app_id");
- Intent it = new Intent(Intent.ACTION_VIEW, uri);
- startActivity(it);
- //where app_id is the application ID, find the ID
- //by clicking on your application on Market home
- //page, and notice the ID from the address bar
*获得包安装Intent
*@paramtempFile
*@return
*/
publicstaticIntentgetPackageInstallIntent(FiletempFile)
{
UrimPackageURI=Uri.fromFile(tempFile);
Intentin=newIntent();
in.setAction(Intent.ACTION_VIEW);
in.addCategory(Intent.CATEGORY_DEFAULT);
in
.setComponent(newComponentName(
"com.android.packageinstaller",
"com.android.packageinstaller.PackageInstallerActivity"));
in.setDataAndType(mPackageURI,
"application/vnd.android.package-archive");
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
returnin;
}
更多相关文章
- Android: java应用程序进程启动过程的代码分析
- Cocos2d-x在win7下的android交叉编译环境
- Android中EventBus事件总线发送网络请求结果更新UI
- Android(安卓)HAL 开发 (1)
- Androidstudio开发button按钮的操作以及项目开发大致过程
- Android(安卓)APIDemos 研读之一:android.graphics.Movie
- Android(安卓)Handler 异步消息处理机制 《第一行代码》
- Android(安卓)no such table (找不到表)
- 在Android的c/c++代码中使用LOG