In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how Android to achieve jump tripartite application, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
How to jump to tripartite applications?
The three-party application here can be understood as the rest of the app outside itself, such as QQ, Wechat, Alipay, Taobao and other app ~
The tripartite App is started mainly through Activity Intent + PackageManager, mainly in the getLaunchIntentForPackage method. If you understand how to start App through Launch, you will know it in a second.
Jump to tripartite application
Core code
PackageManager packageManager = this.getPackageManager (); Intent intent = packageManager.getLaunchIntentForPackage ("project package name"); startActivity (intent)
Encapsulation method
/ * * @ param context context * @ param packageName package name * / public void skipOtherApp (Context context, String packageName) {PackageManager packageManager = context.getPackageManager (); Intent intent = packageManager.getLaunchIntentForPackage (packageName); startActivity (intent);} Jump three-party application + specified page (Activity)
The specific interface of the jump three-party application is slightly different from the way above, mainly through the ComponentName class to help open the Activity or Service of another application, specifically through the Intent.setComponent method.
Core code
Intent intent = new Intent (); / / the startup page of Taobao ComponentName comp = new ComponentName ("com.taobao.taobao", "com.taobao.tao.welcome.Welcome"); intent.setComponent (comp); / / the newly opened task stack intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK) for the tripartite activity; startActivity (intent)
Method encapsulation
/ * * @ param packageName package name * @ activity * / public void skipOtherAppActivity (String packageName, String activityClass) {Intent intent = new Intent () of the param activityClass jump interface; / / ComponentName class is mainly used to help open Activity or Service of another application, and implements ComponentName comp = new ComponentName (packageName, activityClass) through the Intent.setComponent method; intent.setComponent (comp) Intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK); startActivity (intent);} how do I get the app package name and launch page (Activity) that already exist on the phone? Get the app package name installed in the phone, launch Activity/** * get the package name and launch page of all app in the phone through PackageManager (the first class name to start Activity) * you can encapsulate the return body of the method according to your business needs, which can be single app information or appList * / public void getAllApp (Context context) {Intent intent = new Intent (Intent.ACTION_MAIN, null) Intent.addCategory (Intent.CATEGORY_LAUNCHER); PackageManager packageManager = context.getPackageManager (); List appsInfo = packageManager.queryIntentActivities (intent, 0); Collections.sort (appsInfo, new ResolveInfo.DisplayNameComparator (packageManager)); for (ResolveInfo info: appsInfo) {String pkg = info.activityInfo.packageName; String cls = info.activityInfo.name Log.e ("app_info", "pkg:" + pkg + "- cls:" + cls);}}
Query effect
Get the list of mobile phone app
Method encapsulation (maybe it's a little superfluous, just think of it as the next copy element)
/ * get the app list of mobile phones * / public List getAllAppList (Context context) {Intent intent = new Intent (Intent.ACTION_MAIN, null); intent.addCategory (Intent.CATEGORY_LAUNCHER); PackageManager packageManager = context.getPackageManager (); List appsInfo = packageManager.queryIntentActivities (intent, 0); Collections.sort (appsInfo, new ResolveInfo.DisplayNameComparator (packageManager)); return appsInfo;} interest analysis
Looking at the picture, we can find out that it is mainly through PackageManager to filter out the app of android.intent.category.LAUNCHER under the condition of Category.
Look at ResolveInfo.
Look at ActivityInfo (I didn't look for the online source code, and I didn't download it locally. So I can't see it all.)
The basic information about each app is generally in ActivityInfo. If you are interested, you can take a look at the source documents.
The above is all the contents of the article "how to jump to tripartite applications in Android". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.