Intent intent=new Intent(LoginActivity.this, MainActivity.class);//显示意图启动,显示从一个activity到另一个activity,
隐示意图启动activity,不显示activity名字,而通过一个action或者category一个字符串,跨应用程序启动另一个应用程序的activity只能用隐示意图启动,

Main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <Button
android:id="@+id/btnStartSecondActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="start SecondActivity" />
<Button
android:id="@+id/btnBrowser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="浏览网页" />
<Button
android:id="@+id/btnCall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="拨打电话" />
<Button
android:id="@+id/btnDial"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="启动拨号面板" />
<Button
android:id="@+id/btnUninstall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="卸载应用程序" />
<Button
android:id="@+id/btnInstall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="安装应用程序" />
<Button
android:id="@+id/btnSendSms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="发送短信" />
<Button
android:id="@+id/btnPlayMusic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="播放音乐" /> </LinearLayout>

MainActivity.java

package com.sxt.day04_06;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener; public class MainActivity extends Activity implements OnClickListener { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setListener();
} private void setListener() {
findViewById(R.id.btnBrowser).setOnClickListener(this);
findViewById(R.id.btnCall).setOnClickListener(this);
findViewById(R.id.btnDial).setOnClickListener(this);
findViewById(R.id.btnInstall).setOnClickListener(this);
findViewById(R.id.btnPlayMusic).setOnClickListener(this);
findViewById(R.id.btnSendSms).setOnClickListener(this);
findViewById(R.id.btnStartSecondActivity).setOnClickListener(this);
findViewById(R.id.btnUninstall).setOnClickListener(this);
} @Override
public void onClick(View v) {
Intent intent = null;
switch (v.getId()) {
case R.id.btnBrowser://浏览网页
intent = new Intent(Intent.ACTION_VIEW);//查看数据, public static final String ACTION_VIEW = "android.intent.action.VIEW";
intent.setData(Uri.parse("http://www.baidu.com"));//查看什么数据
startActivity(intent);//隐士意图启动activity,不指定安卓系统浏览网页的activity的名字,只需要告诉安卓系统动作是什么,操作数据是什么,自动匹配,看见是网址则把浏览器的activity打开,ACTION_VIEW是查看,查看的数据是网址,
break;
case R.id.btnCall:
intent = new Intent(Intent.ACTION_CALL);//拨打电话的action是ACTION_CALL(public static final String ACTION_CALL = "android.intent.action.CALL";),需要权限,
intent.setData(Uri.parse("tel:15555215554"));
break;
case R.id.btnDial:
intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:68337799"));
break;
case R.id.btnInstall: {//安装应用程序,
// 找到sd卡的Download目录
File dir = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);//目录,getExternalStoragePublicDirectory获取sd卡的根目录“storage/sdcard”,
//public static String DIRECTORY_DOWNLOADS = "Download";
File file = new File(dir, "baidu_safe.apk");//"storage/sdcard/Download/baidu_safe.apk"
intent = new Intent(Intent.ACTION_VIEW);//启动查看activity,然后点击安装,以查看数据的方式,
intent.setDataAndType(Uri.fromFile(file),//设置路径和类型,Uri.fromFile(file)根据file类型的地址转成url类型,后面是固定的。
"application/vnd.android.package-archive");//application表示是一个应用程序,
}
break;
case R.id.btnPlayMusic://播放音乐
intent = new Intent(Intent.ACTION_VIEW);
File dir = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File file = new File(dir, "yielaixiang.mp3");
intent.setDataAndType(Uri.fromFile(file), "audio/mp3");//第一个是路径,第二个是"音频/mp3"
break;
case R.id.btnSendSms://发短信
intent=new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("smsto:13377558899"));
intent.putExtra("sms_body", "hello android!");
break;
case R.id.btnStartSecondActivity://启动SecondActivity,即显示activity_second.xml视图
intent=new Intent("com.sxt.day04_06.SecondActivity");//com.sxt.day04_06.SecondActivity是ACTION名字,
//匹配下面过滤器intent-filter中的action,然后启动下面的这整个activity
/*<activity
android:name="com.sxt.day04_06.SecondActivity"
android:label="@string/title_activity_second" >
<intent-filter>
<action android:name="com.sxt.day04_06.SecondActivity"/>
<category android:name="android.intent.category.DEFAULT"/>缺省的(默认的),
</intent-filter>
</activity>
*/
break;
case R.id.btnUninstall://卸载
intent=new Intent(Intent.ACTION_DELETE);//action名字是删除数据
intent.setData(Uri.parse("package:com.sxt.day04_01"));//package:com.sxt.day04_01是包名,
break;
}
startActivity(intent);
} }
activity_second.xml
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SecondActivity" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> </RelativeLayout>
activity_second.java
package com.sxt.day04_06;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu; public class SecondActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Log.i("main","SecondActivity.onCreate()");
} }

系统描述文件.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sxt.day04_06"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.CALL_PHONE"/>拨打电话的权限,安装apk的时候会提示应用程序有拨打电话的权限,不同意就不安装。
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.sxt.day04_06.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> 设置这个activity为项目入口 <category android:name="android.intent.category.LAUNCHER" /> 这个activity为顶级列表,软件的图标,
</intent-filter>
</activity>
<activity
android:name="com.sxt.day04_06.SecondActivity"
android:label="@string/title_activity_second" >
<intent-filter>
<action android:name="com.sxt.day04_06.SecondActivity"/>
<category android:name="android.intent.category.DEFAULT"/>缺省的(默认的),
</intent-filter>
</activity>
</application> </manifest>
intent即意图
一:用来启动其他新的Activity。
二:作为传递数据和事件的桥梁。传递数据时的代码有两种:
第一种是:
Intent intent = new Intent(CurrentActivity.this , OtherActivity.class);
intent.putExtra(“data” , somedata);
第二种是新建一个Bundle,再把该Bundle加入intent,如:
Bundle bundle = new Bundle() ;
bundle.putString(“data” , somedata) ;
intent.putExtras(bundle)。 隐式意图:创建Intent对象的时候不指定activity类的名字,而是设置action,action值跟安卓系统预定义的antion(Intent.ACTION_VIEW)匹配,启动安卓系统预定义的activity(卸载、安装、浏览网页)。可以给一个acticity设置多个category,启动的时候也可以给category设置多个字符串,只要匹配了category的某一个也可以把activity启动起来。
显示意图启动只能启动同一个应用程序的2个activity(组件)。跨应用启动,启动别人的程序的或者安卓系统的activity则只能用隐士意图启动。
												

android 21 隐式意图启动系统预定义activity的更多相关文章

  1. 隐式意图调用系统自带组件的各种Uri总结

    调用系统应用解析(必需要加各自使用的权限)  android intent 隐式意图和显示意图(activity跳转) 显示意图要求必须知道被激活组件的包和class 隐式意图仅仅须要知道跳转acti ...

  2. 隐式意图启动一个Activity

    隐式意图是通过指定一组动作或者属性实现,主要用于跨应用使用. 1.创建一个意图对象 Intent intent = new Intent(); 2.设置意图过滤器 intent.setAction(& ...

  3. android intent 隐式意图和显示意图(activity跳转)

    android中的意图有显示意图和隐式意图两种, 显示意图要求必须知道被激活组件的包和class 隐式意图只需要知道跳转activity的动作和数据,就可以激活对应的组件 A 主activity  B ...

  4. Android 设置隐式意图

    AndroidManifest.xml对于被调用的activity: <activity android:name="com.wuyou.twoactivity.OtherActivi ...

  5. Android学习记录(7)—Intent中显示意图和隐式意图的用法

    Intent(意图)主要是解决Android应用的各项组件之间的通讯. Intent负责对应用中一次操作的动作.动作涉及数据.附加数据进行描述,Android则根据此Intent的描述,负责找到对应的 ...

  6. 基础学习总结(八)--Intent中显示意图和隐式意图的用法

    Intent(意图)主要是解决Android应用的各项组件之间的通讯.Intent负责对应用中一次操作的动作.动作涉及数据.附加数据进行描述,Android则根据此Intent的描述,负责找到对应的组 ...

  7. 无废话Android之smartimageview使用、android多线程下载、显式意图激活另外一个activity,检查网络是否可用定位到网络的位置、隐式意图激活另外一个activity、隐式意图的配置,自定义隐式意图、在不同activity之间数据传递(5)

    1.smartimageview使用 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&q ...

  8. Android开发之通过Intent启动系统应用的协议

    使用隐式Intent启动系统应用,除了http协议,还有geo(显示地理位置),tel(拨打电话),file(文件)等

  9. Android 隐式意图的配置

    本文地址:http://www.cnblogs.com/wuyudong/p/5677473.html,转载请注明源地址. <Android 显示意图激活另外一个Actitity>一文介绍 ...

随机推荐

  1. Type 类型

    修改 type 类型 UPDATE  wd_order2 SET  info = array_append(info, row(2,100001, now() )::info )  WHERE id_ ...

  2. github基础命令

    github被zf断断续续的墙掉,只能多试几次;习惯用svn了,作为git新手,把svn跟git命令对比了一下,瞬间发现好方便记忆了: (1)获取代码仓库克隆:https://github.com/c ...

  3. java特点

    简单: Java语言的语法与C语言和C++语言很接近,使得大多数程序员很容易学习和使用.另一方面,Java丢弃了C++中很少使用的.很难理解的.令人迷惑的那些特性,如操作符重载.多继承.自动的强制类型 ...

  4. 安装Java

    1.在Oracle的官网下载需要的jdk,这里选择JDK1.8,下面,是下载的网址 http://www.oracle.com/technetwork/java/javase/downloads/jd ...

  5. Map迭代器

            今天用到了,发现不会,随手谷歌之,整理如下. //Map是接口,刚才在那new Map,汗颜 Map<Character,Integer> mm = new HashMap ...

  6. Python安装及开发环境配置

    Python的语法简洁,功能强大,有大量的第三方开发包(模块).同时Python不像java一样对内存要求非常高,适合做一些经常性的任务方面的编程.根据codeeval网站数据统计显示,连续三年,Py ...

  7. 5种php加密工具zendGuard、ionCube、SourceCop、SourceGuardian、phpShield

    PHP做桌面应用的想法: 除去icudt55.dll,PHP7用7ZIP压缩后不足7MB,而PHP自带了SQLite和CLI HTTP Server,用户打开浏览器就能访问PHP开发的桌面应用.如果源 ...

  8. Qt 中update()和repaint()的区别

    void QWidget::repaint ( int x, int y, int w, int h, bool erase = TRUE ) [槽]通过立即调用paintEvent()来直接重新绘制 ...

  9. 深入Spring之web.xml

    针对web.xml我打算从以下几点进行解析: 1.ContextLoaderListener: 启动Web容器时,自动装配ApplicationContext的配置信息. 2.RequestConte ...

  10. Android+clipse导入工程提示:invalid project description

    今天遇到一个奇怪的问题.一个android的工程用eclipse导入的时候,提示错误.错误为:invalid project description . details为xxxx project ov ...