【Android 初学者】权限调用,手把手教你们启用权限
2016-12-04 14:47
197 查看
说起调用权限,就是意图组件!(唯一和用户交互的组件)意向组件(不属于四大核心组件)作用:1,指令输出,通过反射读取路径。2,实现Android的应用组件之间的交互和通信:使用手机 →打电话,发短信,听歌,上网,→ 意向 →启用短信,电话,听歌,上网等相应应用组件属性:操作:要执行的动作(与输入连在一起)数据:执行动作要操作的数据类型:显示指定意向的数据类型类别:类别,被执行动作的附加信息演员:包含所有附加信息的集合成分:指定意向的目标组件的类名称(差不多淘汰)本文章讲解:一,打开应用程序,显示一张精美的背景图,再跳转主页面(参考支付宝,QQ,微信等应用程序)如图:先显示一张背景图片,几秒后再跳转主页面
二,如上图,实现打电话![](http://img.blog.csdn.net/20161204143646050)
三,发短信与群发短信(基本河蟹了,但是根过的手机可用,![](http://img.blog.csdn.net/20161204143726816)
![](http://img.blog.csdn.net/20161204143736413)
![](http://img.blog.csdn.net/20161204143800082)
因为批量发送属于骚扰的恶意程序,谁也不想看到手机有成百上千条骚扰短信吧?!)四,打开网页(工作室自带的虚拟机测试不稳定,日食的稳定打开网页,大家也可以自己去网上找个其他的虚拟机,或者用手机测试)
五,往虚拟机的SD卡添加文件,实现:播放音乐,安装APK卸载APK几乎不用,都是长按促发卸载功能。(前面四个上代码,很简单的,第五详细讲解)
点击左上的虚拟机,再看到右边的文件夹,可见:存储SD卡
添加的MP3可见,添加APK一样
安装APK:![](http://img.blog.csdn.net/20161204144226825)
![](http://img.blog.csdn.net/20161204144235544)
![](http://img.blog.csdn.net/20161204144258029)
卸载
当然,名字是要修改的!从项目4,到爱丽丝桌面主题,到QQ萌化的apk
-------------------------------------------------------------------------------------------------所有文件:
MainActivity.javapackage com.open_open.androidch_07_2;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.telephony.SmsManager;import android.view.View;import android.widget.EditText;public class MainActivity extends Activity {private EditText setValues;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);setValues=(EditText)findViewById(R.id.setValues);}//电话拨号public void testOne(View view){//跳出拔号界面!Intent intent=new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+setValues.getText().toString()));startActivity(intent);}//发短信public void testTwo(View view){Intent intent=new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:"+setValues.getText().toString()));intent.putExtra("sms_body","Hello,Android!");startActivity(intent);}//发信息public void testTwo_2(View view){SmsManager sms=SmsManager.getDefault();for (int i = 0; i < 5; i++) {sms.sendTextMessage("smsto:"+setValues.getText().toString(), null,"this is a test!", null, null);}}//打开网页public void testThree(View view){Intent intent=new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.baidu.com"));startActivity(intent);}//播放音乐public void testFour(View view){Intent intent=new Intent(Intent.ACTION_VIEW);intent.setDataAndType(Uri.parse("file:///sdcard/Oranje.mp3"),"audio/mp3");startActivity(intent);}//安装APK AndroidCH04public void testFive(View view){Intent intent = new Intent();intent.setAction(Intent.ACTION_VIEW);intent.setDataAndType(Uri.parse("file:///sdcard/by.apk"),"application/vnd.android.package-archive");startActivity(intent);}//卸载APK androidch04public void testSix(View view){Intent intent = new Intent(Intent.ACTION_DELETE,Uri.parse("package:com.example.by"));startActivity(intent);}}AndroidMainfest.xml(权限调用)
在自己的虚拟机上测试: 1,在java的环境变量上,设置机器人的环境变量 ANDROID_HOME E:\ Android的\ SDK PATH(在JDK和mysql的的基础上加的; 号可以断开) D:\的Java \ jdk1.8.0_91 \ BIN; D:\ mysql5.6 \ BIN; E:\ Android的\ SDK \平台工具; E:\ Android的\ SDK \工具 设置好后,应该有这个图标的2,新建虚拟机(略),打开它,往桌面放一个APK测试
<!-- 权限开启: 拨打电话,发送邮件,连接网络,安装apk ,卸载apk --> <uses-permission android:name="android.permission.CALL_PHONE"/> <uses-permission android:name="android.permission.SEND_SMS"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>红色表示修改 和 增加的地方<activity android:name=".MainActivity"><intent-filter><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.DEFAULT" /></intent-filter></activity><activity android:name=".WelcomeActivity"><intent-filter><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity>WelcomeActivity.java(背景页面的方法)activity_main.xml中(主页面布局)<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><EditTextandroid:id="@+id/setValues"android:layout_width="match_parent"android:layout_height="wrap_content"android:hint="请输入内容"android:textSize="28sp"android:gravity="left"android:layout_marginTop="5sp"/><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="拨打电话"style="@style/myButton"android:onClick="testOne"/><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="发送短信一"style="@style/myButton"android:onClick="testTwo"/><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="发送短信二"style="@style/myButton"android:onClick="testTwo_2"/><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="打开网页"style="@style/myButton"android:onClick="testThree"/><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="播放音乐"style="@style/myButton"android:onClick="testFour"/><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="安装Apk"style="@style/myButton"android:onClick="testFive" /><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="卸载Apk"style="@style/myButton"android:onClick="testSix" /></LinearLayout>activity_welcome.xml(背景页面布局,其实就一个背景设置)
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@drawable/meizi"></LinearLayout>
WelcomeActivity.java背景页面方法package com.open_open.androidch_07_2;import android.app.Activity;import android.content.Intent;import android.os.Bundle;public class WelcomeActivity extends Activity {//定义一个时间长度的变量int size=0;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_welcome);getWindow().setType(getWindow().FEATURE_NO_TITLE);new Thread(new Runnable() {@Overridepublic void run() {while(size<3){try {Thread.sleep(1000);size++;} catch (InterruptedException e) {e.printStackTrace();}}Intent intent=new Intent(WelcomeActivity.this,MainActivity.class);startActivity(intent);finish();}}).start();}}值文件夹:自定义样式:mystyle.xml 略
相关文章推荐
- android调用shell命令及权限问题
- Android开发,在一个项目中调用(启用)已经安装的第三方apk应用软件
- Android中应用调用系统权限
- android 7.0调用相机权限
- android 7.0调用相机权限
- Android权限问题导致的系统调用bug
- Android开发拨打电话的权限,调用方式有两种,以及区别
- 请教一个问题,Android应用运行时在调用某个API(比如相机)时,系统如何判断这个应用是否具备相应的权限?
- 求教:请问Android中,权限的实现与相应API的调用是如何实现的
- android 7.0调用相机权限
- Android 调用百度地图所需权限
- [置顶] Android m6.0权限问题调用封装utils类 - Permission in Android M
- Android调用binder实现权限提升-android学习之旅(81)
- 以调用系统相机拍照为例了解Android 6.0运行时权限
- 通俗易懂,手把手教会你android 6.0后(兼容6.0之前版本)申请危险权限的方法
- Android JNI 手把手教你编写.so并调用接口
- Android调用binder实现权限提升-android学习之旅(81)
- 关于Android 6.0 调用 要求使用权限代码报红色问题
- 关于Android6.0/7.0权限,以及7.0调用相机和切图的解决办法
- android 7.0调用相机权限