Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

android - Calling an app from another app

In this app I'm developing I need to load/call another app that is already installed on the phone. It's an application for my own personal use only, so no need to check if the other app is installed - I know it is.

I've googled this problem for hours, but I can't find anything that works. Mostly because the guidelines for finding package name and class name are really bad.

Via cmd and adb I was able to find that the info regarding the application I'd like to call is: package:/data/app/com.soundcloud.android-1.apk=com.soundcloud.android (that's exactly what it said in the cmd window.)

I tried something like this:

Intent i = new Intent();
i.setClassName("/data/app/com.soundcloud.android-1.apk", "com.soundcloud.android");
startActivity(i);

But my app just crashes instead. I used the above code because someone said that this could call an app:

Intent i = new Intent();
i.setClassName("<package_name>","<Class Name(with package name)>");
startActivity(i);

Does anyone know what to really write?

P.S.: my own app does not need any information about what's happening in the called app.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use the PackageManager to get an Intent for the package:

PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.example.package");
startActivity(intent);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...