當前位置:首頁 » 安卓系統 » android調用其他應用

android調用其他應用

發布時間: 2022-10-25 12:02:12

Ⅰ android中一個應用程序如何調用到另一個另一程序的activity

生成一個要被調用的APK。在其Manifest.xml設置中,與一般的寫法大致相同,唯一區別的地方在於-->安裝這個要被調用的APK。安裝完畢之後,你會發現,系統中找不到這個程序。別急,它確實安裝在手機裡面了,但是因為他不是main的,所以系統不會把他當做Application的入口程序。而要想打開這個activity,只有知道它名字的人才可以。跟系統的intent一樣使用。它的名字定義為"testApp",所以,這里用這個字元串就可以調用它了在另一個項目中調用上述APK。代碼如下java">Intentintent=newIntent("testApp");startActivity(intent);啟動另外一個apkjava">IntentmIntent=newIntent();ComponentNamecomp=newComponentName(packageName,activityName);mIntent.setComponent(comp);mIntent.setAction("android.intent.action.VIEW");startActivity(mIntent);

Ⅱ android怎麼打開另外的應用程序

我們可以通過ComponentName以及Intent的setComponent來實現:在一個應用程序裡面啟動另外一個已經安裝的應用程序或系統程序。
下面是一個在一個應用程序裡面啟動另外一個已經安裝的程序,如下:
[javascript]
//組件名稱,第一個參數是應用程序的包名,後一個是這個應用程序的主Activity
ComponentName com = new ComponentName("com.antroid.Test", "com.antroid.Test.TestActivity");
Intent intent = new Intent();
//設置部件
intent.setComponent(com);
startActivity(intent);
//組件名稱,第一個參數是應用程序的包名,後一個是這個應用程序的主Activity
ComponentName com = new ComponentName("com.antroid.Test", "com.antroid.Test.TestActivity");
Intent intent = new Intent();
//設置部件
intent.setComponent(com);
startActivity(intent);
我們也可以使用下面的代碼啟動系統的日歷程序:
[javascript]
Intent intent=new Intent();
intent.setComponent(new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity"));
startActivity(intent);
Intent intent=new Intent();
intent.setComponent(new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity"));
startActivity(intent

Ⅲ Android 跨應用間調用: URL Scheme

Android中的自定義的 URL Scheme 是一種頁面內跳轉協議,也可以被稱為 URLRouter ,就是通過類似打開網頁的方式去通過路由打開一個Activity,而非直接通過顯式Intent方式去進行跳轉。這樣隱式intent的方法跳轉好處如下:

上文已經說過, URL Scheme 是就通過類似打開網頁的方式去通過路由打開一個Activity,其協議格式和我們打開網頁輸入的網址類似。

一個完整的完整的URL Scheme協議格式由scheme、host、port、path和query組成,其結構如下所示:

其中scheme既可以是Android中常見的協議,也可以是我們自定義的協議。Android中常見的協議包括content協議、http協議、file協議等,自定義協議可以使用自定義的字元串,當我們啟動第三方的應用時候,多是使用自定義協議。

如下是一個自定義協議的URI:

通過上面的路徑 Scheme、Host、port、path、query全部包含:

URL Scheme 的使用方法簡要言之就是先在manifest中配置能接受Scheme方式啟動的activity;當需要調用時,將Scheme協議的URi以Data的形式加入到Intent中,隱式調用該activity。

1). 在AndroidManifest.xml中對<activity >標簽增加<intent-filter>設置Scheme

上面的設置中可以看到,MainActivity包含多個<intent-filter>設置,第一個是正常的啟動,也就是在應用列表中啟動;第二個是通過 URL Scheme 方式啟動,其本身也是隱式Intent調用的一種,不同在於添加了<data>屬性,定義了其接受 URL Scheme 協議格式為 urlschemel://auth_activity

這里需要說明下, URL Scheme 協議格式中,組成URI的這些屬性在<data >標簽中都是可選的 ,但存在如下的依賴關系:

當我們將intent對象中的Uri參數與intent-filter中的<data>標簽指定的URI格式進行對比時,我們只對比intent-filter的<data>標簽指定的部分,例如:

需要注意的是,intent-filter的<data>標簽在指定path的值時,可以在裡面使用通配符*,起到部分匹配的效果。

2). 使用URL啟動Activity

當然可以在網頁中調用

或者是在JS中調用

3.)如何判斷URL Scheme是否有效

有時候需要把一些輔助性的、較為獨立的APP在Home Launcher中隱藏起來,只允許一些特定的APP調用。這個時候,我們可以利用 URL Scheme 協議來做到這一點,設置AndroidManifest.xml中對<activity >標簽如下

因為Home Launcher列出的應用圖標要求必須有Activity同時滿足

上面的配置中有多餘的category和data限制存在,所以並不匹配,不會在Home Launcher出現,但是可以使用 URL Scheme 來啟動。

這樣就可以將一組APP設置一個統一的入口,然後根據實際需要在調用不同子APP,即所謂的 APP業務組件化 , URL Scheme 在其中有著重要的作用,更進一步討論會在以後的文章中呈現,敬請期待。

參考文獻:
http://blog.csdn.net/iispring/article/details/48481793
http://blog.csdn.net/hb707934728/article/details/53196419
http://www.cnblogs.com/whoislcj/p/5825333.html

Ⅳ android 應用調用另外一個應用的activity

這個首先你要知道app2的activity的名字才行。你知道了就簡單了,不知道的話,只能通過log一個個的看。比如app2中有個activity的名字為MyActivity,完整的包名是com.example.app2.MyActivity.那麼你從app1跳過去可以這樣跳:

Intent in = new Intent();
in.setClassName("com.example.app2", "com.example.app2.MyActivity");
mContext.startActivity(in);

Ⅳ 如何通過android的應用程序調用另一個應用

  1. 如果你知道另外一個程序的類名就可以這樣寫

intent.addCategory(Intent.CATEGORY_LAUNCHER);
ComponentNamecn=newComponentName(packageName,className);
intent.setComponent(cn);
startActivity(intent);

2.如果你只知道包名不知道類名,首先獲取類名

privatevoidopenApp(StringpackageName){
PackageInfopi=getPackageManager().getPackageInfo(packageName,0);

IntentresolveIntent=newIntent(Intent.ACTION_MAIN,null);
resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
resolveIntent.setPackage(pi.packageName);

List<ResolveInfo>apps=pm.queryIntentActivities(resolveIntent,0);

ResolveInfori=apps.iterator().next();
if(ri!=null){
StringpackageName=ri.activityInfo.packageName;
StringclassName=ri.activityInfo.name;

Intentintent=newIntent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);

ComponentNamecn=newComponentName(packageName,className);

intent.setComponent(cn);
startActivity(intent);
}
}

然後使用1中的方法調用程序

Ⅵ android 在一個應用程序裡面調用另一個應用程序 打開頁面怎麼與原先應用程序的頁面一致

這個是行不通的,有些程序的Activity 是不能通過其他程序打開的,會直接出現java.lang.SecurityException: Permission Denial:

Ⅶ 如何在一個android應用裡面調用一個系統的應用程序呢

//調用系統照相機
public void cameraInfo(){
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
//照片保存的路徑及保存的名稱
intent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(new File("/sdcard/JetMobileDev/camera.jpg"));
startActivityForResult(intent, 1);
}

Ⅷ Android 調用其他應用打開文件

/**
*打開文件
*@paramfile
*/
privatevoidopenFile(Filefile){
Intentintent=newIntent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//設置intent的Action屬性
intent.setAction(Intent.ACTION_VIEW);
//獲取文件file的MIME類型
Stringtype=getMIMEType(file);
//設置intent的data和Type屬性。
intent.setDataAndType(/*uri*/Uri.fromFile(file),type);
//跳轉
startActivity(intent);
}
/**
*根據文件後綴名獲得對應的MIME類型。
*@paramfile
*/
privateStringgetMIMEType(Filefile){
Stringtype="*/*";
StringfName=file.getName();
//獲取後綴名前的分隔符"."在fName中的位置。
intdotIndex=fName.lastIndexOf(".");
if(dotIndex<0){
returntype;
}
/*獲取文件的後綴名*/
Stringend=fName.substring(dotIndex,fName.length()).toLowerCase();
if(end=="")returntype;
//在MIME和文件類型的匹配表中找到對應的MIME類型。
for(inti=0;i<MIME_MapTable.length;i++){//MIME_MapTable??在這里你一定有疑問,這個MIME_MapTable是什麼?
if(end.equals(MIME_MapTable[i][0]))
type=MIME_MapTable[i][1];
}
returntype;
}具體的看這篇文章http://tonysun3544.iteye.com/blog/1265884

熱點內容
小學加減混合運演算法則 發布:2025-03-01 19:25:50 瀏覽:959
我的世界好玩的自創伺服器 發布:2025-03-01 19:16:31 瀏覽:951
密碼鎖一直在閃是什麼情況 發布:2025-03-01 19:09:21 瀏覽:269
寶馬app插件怎麼到安卓桌面 發布:2025-03-01 19:09:19 瀏覽:995
二維碼信息加密 發布:2025-03-01 19:03:35 瀏覽:306
子齊游戲解說的qq群密碼是什麼 發布:2025-03-01 18:59:18 瀏覽:219
iosflutter編譯 發布:2025-03-01 18:59:05 瀏覽:423
求心演算法 發布:2025-03-01 18:57:33 瀏覽:110
買個塔式伺服器當電腦主機 發布:2025-03-01 18:46:21 瀏覽:479
sql正在運行的包 發布:2025-03-01 18:41:05 瀏覽:178