`

intent 常见几种实用

阅读更多

 

Intent应该算是Android中特有的东西。你可以在Intent中指定程序要执行的动作(比如:view,edit,dial),以及程序执行到该动作时所需要的资料。都指定好后,只要调用startActivity(),Android系统会自动寻找最符合你指定要求的应用程序,并执行该程序。


打开其他APK文件的ACTIVITY

Intent mIntent = new Intent();
ComponentName comp = new ComponentName("com.android.a","com.android.a.AbcActivity" );
mIntent.setComponent(comp);
mIntent.setAction("android.intent.action.MAIN");
startActivity(mIntent);


显示网页:

1.        Uri uri = Uri.parse("http://www.google.com");

2.        Intent it  = new Intent(Intent.ACTION_VIEW,uri);

3.        startActivity(it);

 

显示地图:

1.        Uri uri = Uri.parse("geo:38.899533,-77.036476");

2.        Intent it = new Intent(Intent.Action_VIEW,uri);

3.        startActivity(it);

 

路径规划:

1.        Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");

2.        Intent it = new Intent(Intent.ACTION_VIEW,URI);

3.        startActivity(it);

 

拨打电话:
调用拨号程序

1.        Uri uri = Uri.parse("tel:xxxxxx");

2.        Intent it = new Intent(Intent.ACTION_DIAL, uri); 

3.        startActivity(it); 

 

1.        Uri uri = Uri.parse("tel.xxxxxx");

2.        Intent it =new Intent(Intent.ACTION_CALL,uri);

3.        要使用这个必须在配置文件中加入<uses-permission android:name="android.permission.CALL_PHONE" />

 

 

发送SMS/MMS
调用发送短信的程序

1.        Intent it = new Intent(Intent.ACTION_VIEW);  

2.        it.putExtra("sms_body", "The SMS text");  

3.        it.setType("vnd.android-dir/mms-sms");  

4.        startActivity(it); 

 

 

发送短信

1.        Uri uri = Uri.parse("smsto:0800000123");  

2.        Intent it = new Intent(Intent.ACTION_SENDTO, uri);  

3.        it.putExtra("sms_body", "The SMS text");  

4.        startActivity(it); 

 

 

发送彩信

1.        Uri uri = Uri.parse("content://media/external/images/media/23");  

2.        Intent it = new Intent(Intent.ACTION_SEND);  

3.        it.putExtra("sms_body", "some text");  

4.        it.putExtra(Intent.EXTRA_STREAM, uri);  

5.        it.setType("image/png");  

6.        startActivity(it);

 

 

发送Email

1.        

2.        Uri uri = Uri.parse("mailto:xxx@abc.com");

3.        Intent it = new Intent(Intent.ACTION_SENDTO, uri);

4.        startActivity(it);

 

1.        Intent it = new Intent(Intent.ACTION_SEND);  

2.        it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");  

3.        it.putExtra(Intent.EXTRA_TEXT, "The email body text");  

4.        it.setType("text/plain");  

5.        startActivity(Intent.createChooser(it, "Choose Email Client")); 

 

1.        Intent it=new Intent(Intent.ACTION_SEND);    

2.        String[] tos={"me@abc.com"};    

3.        String[] ccs={"you@abc.com"};    

4.        it.putExtra(Intent.EXTRA_EMAIL, tos);    

5.        it.putExtra(Intent.EXTRA_CC, ccs);    

6.        it.putExtra(Intent.EXTRA_TEXT, "The email body text");    

7.        it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");    

8.        it.setType("message/rfc822");    

9.        startActivity(Intent.createChooser(it, "Choose Email Client"));  

 

 

添加附件

1.        Intent it = new Intent(Intent.ACTION_SEND);  

2.        it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");  

3.        it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");  

4.        sendIntent.setType("audio/mp3");  

5.        startActivity(Intent.createChooser(it, "Choose Email Client"));

 

 

播放多媒体

//方法1.

        Uri uri = Uri.parse("file:///sdcard/song.mp3");
        Intent it = new Intent(Intent.ACTION_VIEW, uri);
//      it.addFlags(it.FLAG_ACTIVITY_NEW_TASK);//非必须选项
        it.setDataAndType(uri, "audio/mp3");
        context.startActivity(it);

//方法2.

1.         

2.        Intent it = new Intent(Intent.ACTION_VIEW);

3.        Uri uri = Uri.parse("file:///sdcard/song.mp3");

4.        it.setDataAndType(uri, "audio/mp3");

5.        startActivity(it);

//方法3. 启动一个播放器并播放一个系统声音

1.        Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");  

2.        Intent it = new Intent(Intent.ACTION_VIEW, uri);  

3.        startActivity(it); 

 

 

Uninstall 程序

1.        Uri uri = Uri.fromParts("package", strPackageName, null);  

2.        Intent it = new Intent(Intent.ACTION_DELETE, uri);  

3.        startActivity(it);

 

 

uninstall apk

1.        Uri uninstallUri = Uri.fromParts("package", "xxx", null);

2.        

3.        returnIt = new Intent(Intent.ACTION_DELETE, uninstallUri);

install apk

1.        Uri installUri = Uri.fromParts("package", "xxx", null);

2.        

3.        returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);

 

 

play audio

1.        Uri playUri = Uri.parse("file:///sdcard/download/everything.mp3");

2.        

3.        returnIt = new Intent(Intent.ACTION_VIEW, playUri);

 

 

哈,原来你还没贴完,我再加个:

1.        //发送附件

2.        Intent it = new Intent(Intent.ACTION_SEND); 

3.        it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text"); 

4.        it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/eoe.mp3"); 

5.        sendIntent.setType("audio/mp3"); 

6.        startActivity(Intent.createChooser(it, "Choose Email Client"));

 

 


 


market相关

再来一个market相关的:
market相关

1.        //搜索应用

2.        Uri uri = Uri.parse("market://search?q=pname:pkg_name"); 

3.        Intent it = new Intent(Intent.ACTION_VIEW, uri); 

4.        startActivity(it); 

5.        //where pkg_name is the full package path for an application 

6.        

7.        //显示指定应用的详细页面(这个好像不支持了,找不到app_id)

8.        Uri uri = Uri.parse("market://details?id=app_id"); 

9.        Intent it = new Intent(Intent.ACTION_VIEW, uri); 

10.     startActivity(it); 

11.     //where app_id is the application ID, find the ID 

12.     //by clicking on your application on Market home 

13.     //page, and notice the ID from the address bar

 
 

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/kome2000/archive/2009/10/20/4704308.aspx

分享到:
评论

相关推荐

    activity调转

    接下来,我们将详细讨论几种常见的Activity跳转方法: #### 方法一:使用`setClass`方式 ```java Intent intent = new Intent(); intent.setClass(a.class, b.class); startActivity(intent); ``` 这种方法使用了...

    android_跳转到其它应用

    以上就是利用Intent在Android应用中实现跳转至其他应用的几种常见方式,它们为开发者提供了强大的功能,同时也为用户带来了极大的便利。通过合理运用这些技术,可以使应用更加丰富、实用,提升用户的整体体验。

    TabHost技巧

    对于使用 `TabHost` 的场景,可以通过以下几种方式实现页面间的数据传递: 1. **使用 Intent Extras**:在启动新的 Activity 时,可以通过 `Intent` 对象的 `putExtra` 方法附加数据,然后在新 Activity 中通过 `...

    Android4.2上传图片且保存至数据库中

    通常有以下几种途径: 1. 使用`Camera` API直接拍照。 2. 通过`Intent`请求用户从相册选择图片。 3. 使用`Gallery`或`FileChooser`自定义选择界面。 在Android 4.2中,`ACTION_PICK`或`ACTION_GET_CONTENT` Intent...

    android 常见应用问题的解答

    主要分为以下几种: - **正常模式**(`RINGER_MODE_NORMAL`):表示设备处于正常的铃声状态。 - **静音模式**(`RINGER_MODE_SILENT`):表示关闭所有声音。 - **振动模式**(`RINGER_MODE_VIBRATE`):表示设备只...

    java常用开发词汇

    比如,在日常开发过程中,我们会遇到“a collection of”(一系列)、“a couple of”(几个)、“a kind of”(一种类型)等表达方式。这些简单的词汇有助于我们在编写文档和讨论技术时表达更加准确和清晰。 接...

    android屏幕截图代码

    本文详细介绍了几种常见的Android屏幕截图方法,包括通过View绘制到Bitmap、使用MediaProjection API、以及通过SurfaceView和MediaCodec等方式。每种方法都有其适用场景和限制条件。开发者在选择具体实现方式时应...

    第7章 广播机制.pptx

    自定义广播是一种非常灵活且实用的功能,它允许开发者在自己的应用内部或跨应用之间发送定制化的消息。创建自定义广播通常包括以下几个步骤: 1. **定义IntentAction**:为广播定义一个字符串常量,表示该广播的意图...

    Android应用源码之监听自身被卸载.zip

    一种常见的方法是通过创建一个自定义的`BroadcastReceiver`。 在提供的源码中,开发者可能创建了一个名为`AppUninstallReceiver`的BroadcastReceiver,它注册了对ACTION_PACKAGE_REMOVED广播的监听。ACTION_PACKAGE...

    adb1.0.26包含fastboot.exe

    输出格式为 [serialNumber] [state],serialNumber 即我们常说的 SN,state 有如下几种: offline —— 表示设备未连接成功或无响应。 device —— 设备已连接。注意这个状态并不能标识 Android 系统已经完全启动...

    自定义dialog及其他工具类库

    在Android中,处理相机通常有以下几种方式: 1. 使用`Intent`启动系统相机应用:通过`ACTION_IMAGE_CAPTURE`意图启动相机,然后通过回调获取拍摄的照片。 2. 自定义相机界面:继承自`Camera`类,自定义相机界面和...

    集成webview+gps+相机调用的安卓app源码

    总之,"集成webview+gps+相机调用的安卓app源码"是一个实用的Android开发示例,它涵盖了多种常见的功能整合,对于学习和实践Android开发具有很高的价值。通过深入理解这些知识点,开发者可以更好地掌握Android应用的...

    提取原生android系统图片裁剪源码

    在Android开发中,图片裁剪是一项常见的功能,用于让用户选择并调整图像的显示部分。"提取原生Android系统图片裁剪源码" 提供了一种直接可使用的裁剪插件代码库,允许开发者轻松集成到自己的应用中。下面将详细解释...

    android新手8天理解安卓 视频(1-67)

    - 介绍文件读写的几种模式:私有模式、只读模式等。 6. **SharedPreferences**: - 使用SharedPreferences保存简单的键值对数据,适用于轻量级的数据存储需求。 7. **SQLite数据库**: - 教授如何利用SQLite...

    android瀑布流附带图片点击事件

    在Android中,实现瀑布流布局通常有以下几种方法: 1. GridView:虽然GridView默认是网格布局,但通过自定义适配器和测量策略,可以改造为瀑布流布局。然而,这种方法灵活性较低,扩展性较差。 2. ...

    Android 字号设置Demo

    此外,为了提供良好的用户体验,可以考虑设置几种预设的字号选项,如小、中、大等,而不是直接让用户输入数值。这样可以简化用户操作,避免因输入不准确导致的显示问题。 在"AppTextSizeChange"这个项目中,你应该...

    天气课程表demo样例

    这个项目基于Eclipse开发环境构建,展示了如何将这两种常见的实用功能整合到一个应用中。 【描述】:该应用的核心特性是能够帮助用户获取各地的实时天气信息,这对于出行计划和日常生活极具价值。天气查询功能可能...

    android简析json数据

    本文将简析Android中处理JSON数据的几种方法,为Android开发者提供一些实用技巧。 首先,理解JSON的基本结构是至关重要的。JSON是一种轻量级的数据交换格式,它基于JavaScript的一个子集,采用完全独立于语言的文本...

    Android开发指南中文版.pdf

    这部分介绍了Android应用中的几种常见的数据存储方式。 - **偏好设置(Preferences)**:一种轻量级的数据存储方式,适用于存储简单的键值对数据。 - **文件(Files)**:介绍如何在设备上读写文件。 - **数据库...

Global site tag (gtag.js) - Google Analytics