Android学习05——Intent
来源:互联网 发布:手机防盗报警软件 编辑:程序博客网 时间:2024/06/05 09:40
学习了一下Intent,包括以下知识点
- Intent启动系统组件
- Intent的7个属性
- Intent的demo
Intent启动系统组件的方法:
Activity:
startActivity(Intent intent)
startActivityForResult(intent, requestcode);
Service:
BroadcastReceiver:
7个属性包括:
- ComponentName
- Action
- Category
- Data
- Type
- Extra
- Flag
做了一个小demo,
包括以下功能:
使用Intent显式启动Activity,包括简写版和详细版
使用Intent隐式启动Activity,要求使用Action,Category,data属性和Intent-Filter配置
使用ACTION_DIAL显示拨号面板,使用ACTION_CALL 直接拨打电话
返回系统的home桌面(286)
使用Action和data属性的组合进行以下操作:
打电话(Action_view + tel:123)
显示指定联系人(Action_view + content://com.android.contacts/contacts/1)
编辑指定联系人(Action_edit + content://com.android.contacts/contacts/1)
显示向指定联系人拨号的界面(Action_dial + content://com.android.contacts/contacts/1)
显示所有联系人列表的信息(Action_view + content://contacts/people)
package org.mkh.intent01_startactivity;import android.Manifest;import android.content.ComponentName;import android.content.Intent;import android.content.pm.PackageManager;import android.net.Uri;import android.os.Bundle;import android.support.v4.app.ActivityCompat;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import android.widget.Toast;public class MainActivity extends AppCompatActivity { private Button btnStart1; private Button btnStart2; private Button btnStart3; private Button btnStart4; private Button btnStart5; private Button btnStart6; private Button btnStart7; private Button btnStart8; private Button btnStart9; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnStart1 = (Button) findViewById(R.id.btn1); btnStart2 = (Button) findViewById(R.id.btn2); btnStart3 = (Button) findViewById(R.id.btn3); btnStart4 = (Button) findViewById(R.id.btn4); btnStart5 = (Button) findViewById(R.id.btn5); btnStart6 = (Button) findViewById(R.id.btn6); btnStart7 = (Button) findViewById(R.id.btn7); btnStart8 = (Button) findViewById(R.id.btn8); btnStart9 = (Button) findViewById(R.id.btn9); btnStart1.setOnClickListener(new btnOnclickListener()); btnStart2.setOnClickListener(new btnOnclickListener()); btnStart3.setOnClickListener(new btnOnclickListener()); btnStart4.setOnClickListener(new btnOnclickListener()); btnStart5.setOnClickListener(new btnOnclickListener()); btnStart6.setOnClickListener(new btnOnclickListener()); btnStart7.setOnClickListener(new btnOnclickListener()); btnStart8.setOnClickListener(new btnOnclickListener()); btnStart9.setOnClickListener(new btnOnclickListener()); } class btnOnclickListener implements View.OnClickListener { @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn1: //显示启动,简写 Intent intent1 = new Intent(MainActivity.this, SecondActivity.class); startActivity(intent1); break; case R.id.btn2: //显示启动,非简写 ComponentName componentName = new ComponentName(MainActivity.this, SecondActivity.class); Intent intent2 = new Intent(); intent2.setComponent(componentName); intent2.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); startActivity(intent2); break; case R.id.btn3: //隐式启动,当有多个符合时,需要用户选择 String secAction = "org.mo.action.second"; Intent intent3 = new Intent(secAction); startActivity(intent3); break; case R.id.btn4: //显示向指定用户拨打电话的面板 //使用 Intent.ACTION_DIAL //使用 data : tel:10086 Intent intent4 = new Intent(Intent.ACTION_DIAL); String data = "tel:10086"; Uri uri = Uri.parse(data); intent4.setData(uri); startActivity(intent4); break; case R.id.btn5: //直接拨打电话 //使用 Intent.ACTION_DIAL //使用 data : tel:10086 Intent intent5 = new Intent(Intent.ACTION_CALL); String data5 = "tel:10086"; Uri uri1 = Uri.parse(data5); intent5.setData(uri1); if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(MainActivity.this,"no permissions",Toast.LENGTH_SHORT).show(); return; } startActivity(intent5); break; case R.id.btn6: //返回home桌面 //使用Intent.ACTION_MAIN //使用Intent.CATEGORY_HOME Intent intent6 = new Intent(); intent6.setAction(Intent.ACTION_MAIN); intent6.addCategory(Intent.CATEGORY_HOME); startActivity(intent6); break; case R.id.btn7: //打开浏览器,浏览指定网页 // 使用Intent.ACTION_VIEW // 使用 uri Intent intent7 = new Intent(); intent7.setAction(Intent.ACTION_VIEW); String url = "http://www.liaoxuefeng.com"; Uri uri2= Uri.parse(url); intent7.setData(uri2); startActivity(intent7); break; case R.id.btn8: //编辑指定联系人 // 使用Intent.ACTION_EDIT // 使用 uri content://com.android.contacts/contacts/10086 Intent intent8 = new Intent(); intent8.setAction(Intent.ACTION_EDIT); intent8.setData(Uri.parse("content://com.android.contacts/contacts/123")); startActivity(intent8); break; case R.id.btn9: //显示所有联系人列表的信息 // 使用Intent.ACTION_VIEW // 使用 uri content://contacts/people Intent intent9 = new Intent(); intent9.setAction(Intent.ACTION_VIEW); String url1 = "content://contacts/people"; Uri uri3= Uri.parse(url1); intent9.setData(uri3); startActivity(intent9); break; } } }}
0 0
- Android学习05——Intent
- Android学习——Intent
- Android学习——Intent传递数据
- android学习笔记——Intent
- android学习笔记——intent
- Activity与Intent——android学习
- android学习笔记1——Intent
- Android学习笔记——Intent
- Android学习日记——INTENT
- Android学习笔记3——学习intent
- Android学习笔记(四)Activiy学习——Intent,context
- Android学习笔记(06)——Android中的Intent
- Android——Intent
- Android——Intent
- Android开发—Intent
- Android—Intent详解
- Android枢纽—Intent
- Android——Intent和Intent过滤器
- python 修改指定路径的csd文件
- 【C语言】实现字符串右移位函数
- iOS开发技巧:设置导航栏全透明效果
- spring aop简介
- 报Keystore was tampered with, or password was incorret的原因
- Android学习05——Intent
- codeforces 651B beautiful_Painting
- ImageNet和CNN可以帮助医学图像的识别吗?
- CodeForces 630 N. Forecast(大水题)
- UICollectionView 的布局
- DataPicker 和 TimePicker
- eclipse常用插件,最实用的插件
- struts2-spring-hibernate
- LeetCode : Swap Nodes in Pairs [java]