Launch a third-party apk app from Android apk
We are in the development, often encounter in an apk to run another apk, just like our windows, to make a shortcut like, how to do it?
The core of the problem is that we have to get the third-party APK package name and class name, both of which are critical! For example, I do test QQ apk,package name is Com.tencent.pad.qq,class name is com.tencent.pad.qq.login.QQLoginActivity. Booting from one apk to another apk, of course, is also done by sending intent. Here are a few simple steps:
1, in order to intuitive or build an icon is better. ImageButton controls are available on Android. It is defined in XML as follows:
[HTML]View Plaincopy
- <ImageButton android:id="@+id/startqq"
- android:layout_width="85dip"
- android:layout_height="54dip"
- android:layout_margintop="20dip" />
2, register the message processing function. That is, when you click on the icon, what to do to respond. The registration code is as follows:
[Java]View Plaincopy
- private ImageButton Mstartqqbutton;
- Mstartqqbutton = (ImageButton) Findviewbyid (R.ID.STARTQQ);
- Mstartqqbutton.setonclicklistener (Mstartqqlistener);
3, prepare intent, send intent. The code is as follows:
[Java]View Plaincopy
- Private View.onclicklistener Mstartqqlistener = new View.onclicklistener () {
- public void OnClick (View v) {
- if (localService = = null) return;
- Localservice.reqmusicexit ();
- Intent mintent = new Intent ();
- ComponentName comp = new ComponentName ("Com.tencent.pad.qq", "com.tencent.pad.qq.login.QQLoginActivity" );
- Mintent.setcomponent (comp);
- Mintent.setaction ("Android.intent.action.VIEW");
- StartActivity (mintent);
- Finish ();
- }
- };
This is just an example, mastered this method, we can develop a similar Windows shortcut icon bar, it can be arbitrary, to develop products that customers like. By the way, I would like to say, this approach must be in the code of the APK application to customize, such as in the launcher, or the development of their own apk.
(go) Launch a third-party apk app from an android apk