欢迎来到天天文库
浏览记录
ID:37912905
大小:74.50 KB
页数:8页
时间:2019-06-02
《Android 常用代码集合》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、这篇文章主要记录一些我常用的一些代码段,方便以后查阅,不断更新中1调用浏览器载入某网址01.Uriuri=Uri.parse("http://www.baidu.com");02.Intentit=newIntent(Intent.ACTION_VIEW,uri);03.startActivity(it);Uriuri=Uri.parse("http://www.baidu.com");Intentit=newIntent(Intent.ACTION_VIEW,uri);startActivity(it);2Broadcast接收系统广播的intent监控应
2、用程序包的安装删除01.publicclassgetBroadcastextendsBroadcastReceiver{02.@Override03.publicvoidonReceive(Contextcontext,Intentintent){04.05.if(Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())){06.Toast.makeText(context,"有应用被添加",Toast.LENGTH_LONG).show();07.}08.elseif(Intent.ACTION_PACK
3、AGE_REMOVED.equals(intent.getAction())){09.Toast.makeText(context,"有应用被删除",Toast.LENGTH_LONG).show();10.}11.12.elseif(Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())){13.Toast.makeText(context,"有应用被替换",Toast.LENGTH_LONG).show();14.}15.16.elseif(Intent.ACTION_CAMERA_BUTTON
4、.equals(intent.getAction())){17.Toast.makeText(context,"按键",Toast.LENGTH_LONG).show();18.}19.20.}21.22.}publicclassgetBroadcastextendsBroadcastReceiver{@OverridepublicvoidonReceive(Contextcontext,Intentintent){if(Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())){Toast.makeTex
5、t(context,"有应用被添加",Toast.LENGTH_LONG).show();}elseif(Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())){Toast.makeText(context,"有应用被删除",Toast.LENGTH_LONG).show();}elseif(Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())){Toast.makeText(context,"有应用被替换",Toast.LENGTH_L
6、ONG).show();}elseif(Intent.ACTION_CAMERA_BUTTON.equals(intent.getAction())){Toast.makeText(context,"按键",Toast.LENGTH_LONG).show();}}}需要声明的权限如下AndroidManifest.xml01.02.7、zy.Broadcast"04.android:versionCode="1"05.android:versionName="1.0">06.07.09.10.8、MAIN"/>11.
7、zy.Broadcast"04.android:versionCode="1"05.android:versionName="1.0">06.07.09.10.8、MAIN"/>11.
8、MAIN"/>11.
此文档下载收益归作者所有