Android: merging two diffrent application into one - android

I have source code of two different application.In a separate Project I want to start an application with choice that if a user click option 1 then go to first application and if click on next button then to other application. I made a main page with buttons. Now how do I achieve this task.

If you have to applications that should be started by a third (yours) then make sure those two are installed on your device and start them via Intent from your third.

That's easy. Look at the /system/bin/am command (here: How to start an Android application from the command line?). You can run it from your code with Runtime.getRuntime().exec().

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("PACKAGE NAME OF THE OTHER APPLICATION");
startActivity(LaunchIntent);
Replace "PACKAGE NAME OF THE OTHER APPLICATION" with the package name of the application that you want to run

You can make a new Activity with 2 buttons and make it MainActvity. From button 1 call MainActivity of the 1st app and from 2nd button call MainActivity of 2nd app using Intent and startActivity().
And make necessary changes in AndroidManifest.xml

Related

Android start activity of second app having no icon from first app

I am having two apps. First app has an activity from which I want to launch an activity from the second app. I am using the following code:
Intent launchIntent = m_context.getPackageManager().getLaunchIntentForPackage(m_packageName);
if (launchIntent != null) {
m_context.startActivity(launchIntent);
}
This code is working very fine to launch the activity from the second app but I want to have the second application without any icon. I am using following code in MainActivity of the second application to remove icon:
PackageManager p = getPackageManager();
//Removing app icon
ComponentName componentName = new ComponentName(this, com.tools.html2pdf.MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
This code successfully removes the launcher icon but then activity from my first application is unable to launch the activity from second app.
Can any one help me in this regard? I want to launch activity of an app having no icon from activity of another application.
When you disable the component like you have done, that component can't be launched in any way. However, interesting thing is that other components (non-disabled activities) of your second application are still launchable.
So, you can create an alias of your MainActivity in the second application which will be used for your purpose. Let's call alias as MainActivityAlias.
From your first application, call the intent on MainActivity. The code for disabling the component will be executed and nothing will open. However, the icon will be gone because this component is disabled and everything related to this component (i.e icon) is gone too.
Now, call the intent on MainActivityAlias just after above intent in the first application. This is just a copy of MainActivity but it does not have any code for disabling and thus, it is enabled and launchable.
Some Side Notes :
1) Both activities should have an <intent-filter> with android.intent.action.MAIN.
2) Your MainActivity should be the launcher activity and thus should have android.intent.category.LAUNCHER in the manifest.
3) Inside MainActivity, you have to check where the call is coming from. If the call is from the first application, then execute the code to disable icon which you mentioned in the question. If the call is coming from launcher icon, then open MainActivityAlias using intent. You can know where the call is coming from like this.
Note - This is just an idea. I have not tested it.
If you don't want the second app to have an app icon, just remove the <intent-filter> with ACTION=MAIN and CATEGORY=LAUNCHER for the root Activity in the second app. When the app is installed, if there is no <intent-filter> with ACTION=MAIN and CATEGORY=LAUNCHER, there will be no app icon shown.
Your app can still launch the second app, but not with the method you've described, since Android doesn't know which is the "launch" Activity. Assuming you know the package and class name of the Activity you want to launch in the second app, you can launch it like this:
Intent launchIntent = new Intent();
launchIntent.setClassName("second.package.name", "fully.qualified.class.name.of.MainActivity");
// add and Intent flags if necessary here
launchIntent.addFlags(Intent.FLAG_ACTIVITY_...);
startActivity(launchIntent);

Priority order of activity

I have two activities with same intent filters. than which one will start first?
I have two activity activity1.java and activity2.java
then which activity starts first?
I have not tested this out, though my guess is the android os should prompt you with a dialog to choose one of the two Activities. This is similar to when you click on a music file and you are prompted with different media/music players on your device that are capable of playing the file.(they have intent filters)
The Android usually shows up a dialog for you choose which one you want. Like the image below:

Open android app programmatically

I would like to open another app when clicking a button in my app. How can I achieve that?
Intent intent = new Intent("com.test.test");
You don't start "applications" in Android, but "activities". If the activity is not in your process, you need the full class name - just as you did in your demo code.
You need to know the exact activity name in order to open it.

Create new intent in background

I am looking for a way to launch another app from within my app but so that the focus is not changed from my app to the app launched.
I.e currently I have the new app launched via a intent, however when this is carried out the new app is launched and becomes the app in view, I need it to be kept in the background with my app still in view.
The reason for this?
I am developing an application for internal use that will act like a lock-screen to the device so although things must happen in the background the 'lock-screen' must always be on top.
I have done some research into intents and launching other apps but can not find anything about what I need.
Hope you can help thank you!
Currently the terminal is called like this:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("jackpal.androidterm", "jackpal.androidterm.RemoteInterface"));
intent.setAction("jackpal.androidterm.RUN_SCRIPT");
intent.putExtra("jackpal.androidterm.iInitialCommand", cmdString);
The reason it needs to be running in the background is so that the app can run commands in terminal without the user having access, but then they 'unlock' the screen they need to then be able to view the terminal and what commands are being run etc
You can not startActivity in Background.Instead start the activity and minimise the activity(in your case this activity is of different application) using moveTaskToBack(true);
In your case, put a condition based on your intent and its params and use moveTaskToBack(true); so that activity will be minimised only when your application launches.
This won't be possible, you will have to start a background Service that does the actual work and only launch the Activity you want to navigate to once your foreground Activity is finished. Depending on your architecture, you can store the Activity to call when your foreground Activity is finished and change it from the service. That way you will have your desire behaviour without having to actually call the Activity.
In addition to the answer from #Meher, in the intent for your current starting activity, you can add the flag FLAG_FROM_BACKGROUND.
With this you get rid of the "blinking" effect (the one where your activity shows for one fraction of second while it discovers wether to go to background)

How can I launch an activity in another apk?

HI,
I have 2 projects (each has its own apk).
Can you please tell me how can I launch an activity which is in another apk that I created?
I have this activity which I want to launch from another project:
// what should I put in here so that I can launch this from another activity in another project?
You would have to implement an Intent interface. I.e. have your activities respond to specific Intents specified via Intent-filters in your manifest. Have a look at this page:
http://android-developers.blogspot.com/2009/11/integrating-application-with-intents.html
Intent myIntent = new Intent();
myIntent.setClassName("com.activity1", "com.activity2");
startActivity(myIntent);
Activity 1 is the activity that is already running.
Activity 2 is the com name of the activity you want to launch.

Categories

Resources