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. execute、executeUpdate、executeQuery三者的区别及返回值

    一.boolean execute(String sql)允许执行查询语句.更新语句.DDL语句.返回值为true时,表示执行的是查询语句,可以通过getResultSet方法获取结果:返回值为fal ...

  2. iOS:Swift界面实例1, 简单界面

    Apple推出了基于Objective-C的新语言Swift. 通过实例, 我们可以很好的感受这门新语言 注意事项: 在XCode6_Beta中, 如果有中文, IDE的自动补全功能就会失效, 所以开 ...

  3. 搭建hive到eclipse里面

    (1)下载源码 git clone https://git-wip-us.apache.org/repos/asf/hive.git git clone https://github.com/apac ...

  4. mysql申请账户

    INSERT INTO mysql.user set Host='%',user='alipay',password=password('alipay'),Select_priv='Y',Insert ...

  5. vim脚本及配置

    ============set optional===========set nu         //显示行号                                        numb ...

  6. 利用jquery操作Radio方法小结

    用Radio来实现用户的选择效果,在项目中积累了一些利用JQUERY来操作Radio的方法,这里与大家分享下 在开发中经常会用到Radio来实现用户的选择效果,我在项目中积累了一些利用JQUERY来操 ...

  7. BZOJ 3563 DZY Loves Chinese

    Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅Dzy以降. 纷Dzy既有此内美兮,又重之以修能. 遂降临于OI界,欲以神力而凌♂辱众生. 今Dzy有一魞歄图,其上 ...

  8. Codeforces Round #131 (Div. 2) : B

    首先能被2,5整除的数结尾必须是0: 如果没有0肯定不行: 然后判断他们的和ans%3: 如果==0,直接从大到小输出就行: 如果==1,要么删除它们之间最小的那个%3==1的,要么删除两个小的并且% ...

  9. 当今流行的 React.js 适用于怎样的 Web App?

    外村 和仁(株式会社 ピクセルグリッド)  React.js是什么? React.js是Facebook开发的框架. http://facebook.github.io/react/ 官网上的描述是「 ...

  10. QML学习:Rectangle,Text,TextEdit,Flickable,Flipable元素

    QML学习:Rectangle,Text,TextEdit,Flickable,Flipable元素 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 参 ...