當前位置:首頁 » 安卓系統 » 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);
}

熱點內容
c語言零基礎入門 發布:2024-10-18 15:46:42 瀏覽:188
比特幣如何存儲 發布:2024-10-18 15:31:36 瀏覽:614
雲服務相比傳統伺服器有哪些優勢 發布:2024-10-18 15:26:20 瀏覽:678
sql10進制轉16進制 發布:2024-10-18 15:25:33 瀏覽:865
錯誤日誌上傳 發布:2024-10-18 15:08:45 瀏覽:269
三菱機械手編程 發布:2024-10-18 15:08:04 瀏覽:735
阿爾法兒童編程 發布:2024-10-18 14:59:12 瀏覽:770
生死時速2ftp 發布:2024-10-18 14:46:16 瀏覽:205
一座資料庫 發布:2024-10-18 14:45:42 瀏覽:378
事件驅動python 發布:2024-10-18 14:39:54 瀏覽:845