日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android 调用本地第三方应用软件,如qq、微信、微博和视频播放器等

發(fā)布時(shí)間:2024/10/8 编程问答 77 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 调用本地第三方应用软件,如qq、微信、微博和视频播放器等 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
在做Android開發(fā)的過程中有很多時(shí)候要調(diào)用第三方的軟件來輔助自己的軟件完成相應(yīng)的功能,比如在一個(gè)軟件中調(diào)用QQ或者微信來進(jìn)行聊天,或者是調(diào)用第三方的視頻軟件來視頻播放等。。。經(jīng)過查找資料有很多資料是通過 調(diào)用第三方應(yīng)用的兩個(gè)參數(shù),應(yīng)用的包名和類名才能調(diào)用打開第三方程序。例如下面這樣 ComponentName componentName = new ComponentName(pkg, cls); Intent intent = new Intent(); intent.setComponent(componentName); startActivity(intent);

直接設(shè)置pkg和cls這樣也可以打開第三方應(yīng)用,首先你要知道你要調(diào)用的軟件的包名和類名,不知道的話就根本沒辦法,我在開發(fā)過程中需要調(diào)用QQ來進(jìn)行相互之間的聯(lián)系,在其中一個(gè)手機(jī)上是可以運(yùn)行的,但是將這個(gè)軟件安裝在另一個(gè)手機(jī)上的時(shí)候打開過程中就會(huì)出錯(cuò),經(jīng)過一段時(shí)間的查找問題才發(fā)現(xiàn)是QQ版本上的問題,其中的一個(gè)版本很老,包名和類名都跟現(xiàn)在的不一樣。

所以在這里我推薦用下面的方法調(diào)用第三方應(yīng)用,通過查找手機(jī)內(nèi)所有軟件的包名和類名,將其保存,然后通過查找匹配包名中的關(guān)鍵字調(diào)用第三方軟件。


得到包名后就可以根據(jù)包名來調(diào)用第三方軟件了。下面進(jìn)入正題:

布局文件,兩個(gè)按鍵,一個(gè)打開QQ和一個(gè)打開微信:

<LinearLayout 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:orientation="vertical" ><Button android:id="@+id/qqButton"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="打開QQ"/><Button android:id="@+id/weixinButton"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="打開微信"/></LinearLayout>實(shí)現(xiàn)類

MainActivity.java

package cn.edu.cqu.openqqweixin;import java.util.Collections; import java.util.List; import java.util.Map;import android.app.Activity; import android.content.ComponentName; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button;public class MainActivity extends Activity {private Button qqButton;private Button weixinButton;private PackageManager mPackageManager;private List<ResolveInfo> mAllApps;private String input;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);qqButton = (Button) findViewById(R.id.qqButton);weixinButton = (Button) findViewById(R.id.weixinButton);qqButton.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubinput = "qq";openApp(input);}});weixinButton.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubinput = "mm";openApp(input);}});}private void openApp(String str){//應(yīng)用過濾條件Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);System.out.println("testrrr");mPackageManager = this.getPackageManager();System.out.println("tesr");mAllApps = mPackageManager.queryIntentActivities(mainIntent, 0);//按報(bào)名排序Collections.sort(mAllApps, new ResolveInfo.DisplayNameComparator(mPackageManager));for(ResolveInfo res : mAllApps){//該應(yīng)用的包名和主ActivityString pkg = res.activityInfo.packageName;String cls = res.activityInfo.name;System.out.println("pkg---" +pkg);// System.out.println("打印出來的----" + str);// 打開QQ pkg中包含"qq",打開微信,pkg中包含"mm"if(pkg.contains(str)){ComponentName componet = new ComponentName(pkg, cls);Intent intent = new Intent();intent.setComponent(componet);intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);this.startActivity(intent);}}} } 程序中設(shè)置了一個(gè) String類型input,通過設(shè)置input可以打開不同的應(yīng)用程序。


總結(jié)

以上是生活随笔為你收集整理的android 调用本地第三方应用软件,如qq、微信、微博和视频播放器等的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。