当前位置:首页 » 安卓系统 » androidintent包

androidintent包

发布时间: 2022-06-08 02:44:37

1. android不同的包怎么用Intent实现Activity跳转 为什么在androidManifest里面找不到另一个包呢

首先不同的包时可以实现Activity的跳转的、其次manifest中是配置activity、service、receiver等等android组建的、不知道你的Ranklist是不是activity,activity的跳转是不关乎包的、哪怕不同的应用也是能够实现activity的跳转的,有问题继续问

2. Android 收到intent后怎么获取到发送者的包名

broadcast发送的时候都是传递一个intent对象,这个intent对象就是传给onReceive方法的那个intent.通过这个intent就可以获取发送广播的程序的包名,知道了包名就知道是哪个程序了。
ComponentName com = intent.getComponent();
String pkgName = com.getPackageName();
试试看行不行。。。

3. android 里面intent类干什么的

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)。

4. android中intent的作用 越详细越好

1 Intent.ACTION_MAIN

String: android.intent.action.MAIN

标识Activity为一个程序的开始。比较常用。

Input:nothing

Output:nothing

例如:

1
2
3
4
5
6

也可以直接在程序中实现 Intent it = new Intent(原Activity.class,需跳转Activity.class);
2 Intent.Action_CALL

Stirng: android.intent.action.CALL

呼叫指定的电话号码。

Input:电话号码。数据格式为:tel:+phone number

Output:Nothing

Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:1320010001");
startActivity(intent);

3 Intent.Action.DIAL

String: action.intent.action.DIAL

调用拨号面板

Intent intent=new Intent();
intent.setAction(Intent.ACTION_DIAL); //android.intent.action.DIAL
intent.setData(Uri.parse("tel:1320010001");
startActivity(intent);

Input:电话号码。数据格式为:tel:+phone number

Output:Nothing

说明:打开Android的拨号UI。如果没有设置数据,则打开一个空的UI,如果设置数据,action.DIAL则通过调用getData()获取电话号码。

但设置电话号码的数据格式为 tel:+phone number.

4.Intent.Action.ALL_APPS

String: andriod.intent.action.ALL_APPS

列出所有的应用。

Input:Nothing.

Output:Nothing.

5.Intent.ACTION_ANSWER

Stirng:android.intent.action.ANSWER

处理呼入的电话。

Input:Nothing.

Output:Nothing.

6 Intent.ACTION_ATTACH_DATA

String: android.action.ATTCH_DATA

别用于指定一些数据应该附属于一些其他的地方,例如,图片数据应该附属于联系人

Input: Data

Output:nothing

7 Intent.ACTION_BUG_REPORT

String: android.intent.action.BUG_REPORT

显示Dug报告。

Input:nothing

output:nothing

8 Intent.Action_CALL_BUTTON

String: android.action.intent.CALL_BUTTON.

相当于用户按下“拨号”键。经测试显示的是“通话记录”

Input:nothing

Output:nothing

Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);
startActivity(intent);

9 Intent.ACTION_CHOOSER

String: android.intent.action.CHOOSER

显示一个activity选择器,允许用户在进程之前选择他们想要的,与之对应的是Intent.ACTION_GET_CONTENT.

10. Intent.ACTION_GET_CONTENT

String: android.intent.action.GET_CONTENT

允许用户选择特殊种类的数据,并返回(特殊种类的数据:照一张相片或录一段音)

Input: Type

Output:URI

这个以前用到过,看事例。

选择一个图片:

代码
int requestCode = 1001;

Intent intent = new Intent(Intent.ACTION_GET_CONTENT); // "android.intent.action.GET_CONTENT"
intent.setType("image/*"); // 查看类型,如果是其他类型,比如视频则替换成 video/*,或 */*
Intent wrapperIntent = Intent.createChooser(intent, null);
startActivityForResult(wrapperIntent, requestCode);

5. Android 中Intent类存在于哪个包中,需要导入什么

在content包下,不用导入的,这是androidsdk里基础类

6. android中intent什么意思

英文里 Intent是“意向、打算”的意思,其实就是告诉别人你的意图的意思了,这么理解Android里面的Intent也就不难了。

书面化的解释是:
Android中提供了Intent机制来协助应用间的交互与通讯,Intent负责对应用中一次操作的动作、动作涉及数据、附加数据进行描述,Android则根据此Intent的描述,负责找到对应的组件,将 Intent传递给调用的组件,并完成组件的调用。Intent不仅可用于应用程序之间,也可用于应用程序内部的Activity/Service之间的交互。因此,Intent在这里起着一个媒体中介的作用,专门提供组件互相调用的相关信息,实现调用者与被调用者之间的解耦。

7. android中为什么要使用intent进行通信

1、Intent对象详解
Android的应用程序包含三种重要组件:Activity、Service、BroadcastReceiver,应用程序采用一致的方式来启动它们----都是依靠Intent来进行启动的,Intent就封装了程序想要启动程序的意图,不仅如此,Intent还用于与被启动组件进行交换信息。

组件类型

启动方法

Activity
startActivity(Intent intent)
startActivityForResult(Intent intent,intrequestCode)

Service
ComponentName startService(Intent service)
boolean bindService(Intent service,ServiceConnection conn,int flags)

BroadcastReceiver
sendBroadcast(Intent intent)
sendBroadcast(Intent intent,String receiverPermission)
sendOrderedBroadcast(Intent intent,String receiverPermission,BroadcastReceiver resultReceiver,Handler scheler,int initialCode,String initialData,Bundle initialExtras)
sendOrderedBroadcast(Intent intent,String receiverPermission)
sendStickyOrderedBroadcast(Intent intent,BroadcastReceiver resultReceiver,Handler scheler,int initialCode,String initialData,Bundle initialExtras)

Intent对象大致包含Component、Action、Category、Data、Type、Extra和Flag这7种属性,其中Component用于明确指定需要启动的目标组件,而Extra则用于“携带”需要交换的数据。
2、Intent的属性及Intent-filter配置
(1)Component属性
Intent的Component属性需要接受一个ComponentName对象,应用程序可根据给定的组件类去启动特定的组件。
当程序通过Intent的Component属性(明确指定了启动哪个组件)启动特定组件时,被启动组件几乎不需要使用<intent-filter.../>元素进行配置。
(2)Action、Category属性与intent-filter配置
Intent的Action和Category属性都是一个普通的字符串,其中Action代表该Intent所要完成的一个抽象“动作”,Category则用于为Action增加额外的附加类别信息,通常,Action与Category结合使用。
<intent-filter.../>元素里通常可包括如下子元素:
a、0~N个<action.../>子元素
b、0~N个<category.../>子元素
c、0~1个<data.../>子元素
<action.../><category.../>子元素的配置非常简单,它们都可指定android:name属性,该属性的值就是一个普通字符串。
当<activity.../>元素里的<intent-filter.../>子元素里包含多个<action.../>子元素(相当于指定了多个字符串)时,就表明该Activity能响应Action属性值为其中任意一个字符串的Intent。
一个Intent对象最多只能包括一个Action属性,程序调用Intent的setAction(String str)方法来设置Action属性值;但一个Intent对象可包含多个Category属性,调用Intent的addCategory(String str)方法添加。
当程序创建Intent时,该Intent默认启动Category属性值为Intent.CATEGORY_DEFAULT常量(常量值为android.intent.category.DEFAULT)的组件。
(3)指定Action、Category调用系统Activity
实际上,Android内部提供了大量标准Action、Category常量,其中用于启动Activity的标准Action常量及对应的字符串如下:

Action常量

对应字符串

简单说明

ACTION_MAIN

android.intent.action.MAIN

应用程序入口

ACTION_VIEW android.intent.action.VIEW 显示指定数据
ACTION_ATTACH_DATA android.intent.action.ATTACH_DATA 指定某块数据将被附加到其它地方
ACTION_EDIT android.intent.action.EDIT 编辑指定数据
ACTION_PICK android.intent.action.PICK 从列表中选择某项并返回所选的数据
ACTION_CHOOSER android.intent.action.CHOOSER 显示一个Activity选择器
ACTION_GET_CONTENT android.intent.action.GET_CONTENT 让用户选择数据,并返回所选数据
ACTION_DIAL android.intent.action.DIAL 显示拨号面板
ACTION_CALL android.intent.action.CALL 直接向指定用户打电话
ACTION_SEND android.intent.action.SEND 向其他人发送数据
ACTION_SENDTO android.intent.action.SENDTO 向其他人发送消息
ACTION_ANSWER android.intent.action.ANSWER 应答电话
ACTION_INSERT android.intent.action.INSERT 插入数据
ACTION_DELETE android.intent.action.DELETE 删除数据
ACTION_RUN android.intent.action.RUN 运行维护
ACTION_SYNC android.intent.action.SYNC 执行数据同步
ACTION_PICK_ACTIVITY android.intent.action.PICK_ACTIVITY 用于选择Activity
ACTION_SEARCH android.intent.action.SEARCH 执行搜索
ACTION_WEB_SEARCH android.intent.action.WEB_SEARCH 执行Web搜索
ACTION_FACTORY_TEST android.intent.action.FACTORY_TEST 工厂测试的入口点

标准Category常量及对应的字符串如下:

Category常量

对应字符串

简单说明

CATEGORY_DEFAULT android.intent.category.DEFAULT 默认的Category
CATEGORY_BROWSABLE android.intent.category.BROWSABLE 指定该Activity能被浏览器安全调用
CATEGORY_TAB android.intent.category.TAB 指定Activity作为TabActivity的Tab页
CATEGORY_LAUNCHER android.intent.category.LAUNCHER Activity显示顶级程序列表中
CATEGORY_INFO android.intent.category.INFO 用于提供包信息
CATEGORY_HOME android.intent.category.HOME 设置该Activity随系统启动而运行
CATEGORY_PREFERENCE android.intent.category.PREFERENCE 该Activity是参数面板
CATEGORY_TEST android.intent.category.TEST 该Activity是一个测试
CATEGORY_CAR_DOCK android.intent.category.CAR_DOCK 指定手机被插入汽车底座(硬件)时运行该Activity
CATEGORY_DESK_DOCK android.intent.category.DESK_DOCK 指定手机被插入桌面底座(硬件)时运行该Activity
CATEGORY_CAR_MODE android.intent.category.CAR_MODE 设置该Activity可在车载环境下使用

3、Data、Type属性与intent-filter配置
Data属性通常用于向Action属性提供操作的数据,Data属性接收一个Uri对象,一个Uri对象通常通过如下形式的字符串表示:
content://com.android.contracts/contacts/1
tel:123
上面两个字符串的冒号前面大致指定了数据的类型,冒号后面是数据部分。
Type属性则用于明确指定Data属性所指定数据的类型或MIME类型,当Intent不指定Data属性时Type属性才会起作用,否则Android系统将会根据Data属性值来分析数据的类型,因此无需指定Type属性。
一旦为Intent同时指定Action、Data属性,那么Android将可根据指定的数据类型来启动特定的应用程序,并对指定数据执行相应的操作。下面介绍几个Action、Data属性的组合:
ACTION_VIEW content://com.android.contacts/contacts/1:显示标识为1的联系人的信息
ACTION_EDIT content://com.android.contacts/contacts/1:编辑标识为1的联系人的信息
ACTION_DIAL content://com.android.contacts/contacts/1:显示向标识为1的联系人拨号的界面
ACTION_VIEW tel:123:显示向指定号码123拨号的界面
ACTION_DIAL tel:123:显示向指定号码123拨号的界面
ACTION_VIEW content://contacts/people/:显示所有联系人列表的信息,通过这种组合可以方便地查看系统联系人
4、Extra属性
Intent的Extra属性通常用于在多个Action之间进行数据交换,Intent的Extra属性值应该是一个Bundle对象,Bundle对象就像一个Map对象,它可以存入多组key-value对,这样可以就可以通过Intent在不同Activity之间进行数据交换了。

8. android中intent的作用

意图和意图过滤器Intents and Intent Filters

一个应用程序的三个核心组件-活动,服务和广播接收器是通过消息即意图(Intents)来激活的。Intent息传送是相同或不同应用中组件运行时晚绑定的一种机制。意图本身,一个意图对象,是一个包含被执行操作抽象描述的被动的数据结构-或者,对于广播而言,是某件已经发生并被声明的事情的描述。存在不同的机制来传送意图到每种组件中:
• 一个意图对象是传递给Context.startActivity()或者Activity.startActivityForResult()来启动一个活动或者让一个存在的活动去做某些新的事情。
• 一个意图对象是传递给Context.startService()来发起一个服务或者递交新的指令给运行中的服务。类似的,一个意图能被传递给Context.bindService() 来在调用组件和一个目标服务之间建立连接。作为一个可选项,它可以发起这个服务如果还没运行的话。
• 传递给任意广播方法(例如Context.sendBroadcast(),Context.sendOrderedBroadcast(), 或者Context.sendStickyBroadcast())的意图对象被传递给所有感兴趣的广播接收者。许多种广播产生于系统代码。
在每个例子里,Android系统找到合适的活动,服务,或者一组广播接收者来回应这个意图,必要时实例化它们。这些消息传送系统没有重叠:广播意图仅被传递给广播接收者,永远不会给活动或者服务。一个传送给startActivity()的意图是只会被传递给一个活动,永远不会给一个服务或广播接收者,如此类推。
这篇文档以意图对象的描述开始,然后描述Android映射意图到组件的规则-如何解决哪个组件应该接收一个意图消息。对于没有显式命名一个目标组件的意图,这个过程包括对照与潜在目标相关联的意图过滤器来测试这个意图对象。

意图对象Intent Objects
一个意图Intent对象是一堆信息。它包含接收这个意图的组件感兴趣的信息(例如将要采取的动作和操作的数据)再加上Android系统感兴趣的信息(例如应该处理这个意图的组件类别和如何启动一个目标活动的指令):
组件名称Component name
应该处理这个意图的组件名字. 这个字段是一个ComponentName对象- 一个组合物:目标组件的完全合格的类名 (比如"com.example.project.app.FreneticActivity") 以及应用程序描述文件中设置的组件所在包的名字(比如, "com.example.project"). 这个组件名字的包部分和描述文件中设置的包名字不一定要匹配。
组件名字是可选的。如果被设置了,这个意图对象将被传递到指定的类。如果没有, Android使用另外的意图对象中的信息去定位一个合适的目标- 请看本文稍后描述的意图解析Intent Resolution。
组件名字通过如下方法:setComponent(),setClass(), 或者setClassName()设置并通过getComponent()读取。

9. android中Intent问题

Android 开发网站上解释了一下,如果你想允许其它的app通过 intent-filter 命中你的 app 启动它,我们需要给我们的 app 添加 default category,一般来说没有 default category 是表示这个 activity 肯定只是我们 app 自己使用,比如我们一个app有多个 activity,只有主控 activity 会访问其它的 activity 时就是这样的。因为隐含地启动一个 app 的方式是通过对比 intent 条件的,我们没有指定 default category 就是表示我们不打算被其它程序隐含地启动(比如我们想放个木马什么的)。

这个文档说明了,想以隐含方式启动 activity 就需要添加 default category,这是因为需要允许其它app来启动你的activity (而启动自己的activity甚至可以直接使用类名来,不需要这么麻烦)。

另外,当我们希望把主控activity列在应用程序列表中时我们就给它添加 launcher category。

举个例子,一个产品管理程序,主控activity是先打开当前热销产品列表,它在手机的应用程序列表中,因此需要一个 launcher category,它有一个产品详细介绍的activity可以允许通过一个产品编号来查看产品,甚至在网页上有个链接,这时这个产品详细介绍activity就需要一个default category但不需要launcher category,而另一个修改产品资料的activity则不是必须添加一个category,因为它只会被主控activity启动并且外部其它app不应该有机会隐含地启动它。

http://developer.android.com/guide/components/intents-filters.html

10. 如何在Android7.0系统下通过Intent安装apk

Android系统升级到7.0之后,安全性提高了不少,过去我们通常是使用这样的代码进行apk的安装操作。
“`
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(apkFile), “application/vnd.android.package-archive”);
context.startActivity(intent);
“`
但是在Android7.0的系统上,运行这段代码,会报如下错误。
Caused by: android.os.FileUriExposedException
原因是,安卓官方为了提高私有文件的安全性,面向 Android 7.0 或更高版本的应用私有目录被限制访问(0700)。此设置可防止私有文件的元数据泄漏,如它们的大小或存在性.
传递软件包网域外的 file:// URI 可能给接收器留下无法访问的路径。因此,尝试传递 file:// URI 会触发 FileUriExposedException。分享私有文件内容的推荐方法是使用 FileProvider。
1.定义一个FileProvider
<manifest>
...
<application>
...
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.mydomain.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
...
</provider>
...
</application>
</manifest>
2.添加可用权限的文件目录
在res目录下,增加xml文件夹,并新建一个名为 file_paths.xml 的文件。文件内容格式如下:
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="name1" path="test1" />
...
</paths>
标签下面必须包含至少包含以下标签中的一个或者多个。
files-path
<files-path name="name1" path="test1" />
表示Context.getFilesDir()目录或者其子目录。
示例 : /data/data/com.chen.gradle/files/test1
cache-path
<cache-path name="name2" path="test2" />
表示Context.getCacheDir()目录或者其子目录。
示例 : /data/data/com.chen.gradle/cache/test2
external-path
<external-path name="name3" path="test3" />
表示Environment.getExternalStorageDirectory()目录或者其子目录。
示例 : /storage/emulated/0/test3
external-files-path
<external-files-path name="name4" path="test4" />
表示Context.getExternalFilesDir(null)目录或者其子目录。
示例 : /storage/emulated/0/Android/data/com.chen.gradle/files/test4
external-cache-path
<external-cache-path name="name5" path="test5" />
表示Context.getExternalCacheDir()目录或者其子目录。
示例 : /storage/emulated/0/Android/data/com.chen.gradle/cache/test5
3.增加到provider
通过<meta-data>标签将上面的filepath添加到provider当中。
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.mydomain.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
4.通过provider生成Uri
File imagePath = new File(Context.getFilesDir(), "test1");
File newFile = new File(imagePath, "default_image.jpg");
Uri contentUri = FileProvider.getUriForFile(getContext(), "com.mydomain.fileprovider", newFile);
5.赋予临时权限给Uri
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
最终安装apk的代码变成这样:
public static void installApk(Context context, String apkPath) {
if (context == null || TextUtils.isEmpty(apkPath)) {
return;
}
File file = new File(apkPath);
Intent intent = new Intent(Intent.ACTION_VIEW);
//判读版本是否在7.0以上
if (Build.VERSION.SDK_INT >= 24) {
//provider authorities
Uri apkUri = FileProvider.getUriForFile(context, "com.mydomain.fileprovider", file);
//Granting Temporary Permissions to a URI
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
} else {
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
}
context.startActivity(intent);
}

热点内容
java前一个月 发布:2024-10-18 17:07:19 浏览:949
战地配置有哪些 发布:2024-10-18 16:44:48 浏览:310
中国联通短信提示服务密码未完善是什么意思 发布:2024-10-18 16:42:17 浏览:711
c语言中非 发布:2024-10-18 16:21:20 浏览:146
招编程人员 发布:2024-10-18 16:19:37 浏览:425
什么数据类型存储图片 发布:2024-10-18 16:19:28 浏览:751
电脑维护服务器 发布:2024-10-18 16:18:51 浏览:437
取舍算法 发布:2024-10-18 16:12:36 浏览:251
安卓数据线一般在什么价位 发布:2024-10-18 16:09:25 浏览:734
老式安卓机怎么插卡 发布:2024-10-18 15:52:35 浏览:340