Open android app programmatically - android

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.

Related

Can I start an activity as a new Application or outside my app?

I am trying to help my users to turn on their GPS like this:
Intent gpsOptionsIntent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(gpsOptionsIntent);
The problem is that it opens the android settings as it was a view from my app, but I want to open it as a new application (android default settings aplication), in other words, outside my app.
Does anyone know how to accomplish what I want?
Thanks!
The code you are executing shows a new activity "on its own app process", if the activity you are calling is not in your application project it mean's that is not in your application context, so my thought is that just because you go back and fall down in the last activity shown you may think is in your app, but that's not the case, the activity is running on it's own process and because of the back stack you are going back to your previous activity.
Hope this Helps.
Regards!
The problem is that it opens the android settings as it was a view from my app,
No it doesn't. It's starting an Activity which is part of the Android Settings app.
but I want to open it as a new application (android default settings aplication), in other words, outside my app.
That's exactly what is happening - it's just opening the Activity which deals with the settings for Location Services rather than opening the default Settings root page.
Don't confuse the generic terms 'app' and 'application' with Android classes such as Application and Activity.
Android is meant to be modular - even though it looks like the Activity which is started with your code is part of your own 'app', in reality what happens is an instance of the native Settings app is created and the Location Services Activity is displayed. This happens entirely outside of your app.
As mentioned in this answer and comment, you need to add intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Intent gpsOptionsIntent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
// add the following line
gpsOptionsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(gpsOptionsIntent);

Getting data from intent

I am little confused about getting data from intent of an activity, here is what I am trying to do.
I am opening my first activity
I press home button and my activity(application) goes in background
I go to download folder and select one doc file it gives me Open with feature with my application in list.
I select my application.
Now instead of getting resume it calls create method of activity(I think its ok because second instance of my app(activity is created))
Here I try to get data from intent using intent = activity.getIntent();
But I dont get anything(getting null expecting path of this doc)
If I first open my app with Open with feature(No background activity right now) I get file path successfully but when I pres home button and my app goes background again and if I press my app from application list again intent has same data(expecting null in this case.)
What I am trying to achieve:-
I am simply trying that if user is coming from application list intent data should be null and if he is coming from Open with function then he intent data should be path of file.
One more thing I am trying this behaviour in Appcelerator Titanium but as this is native behaviour(handling life cycle of activity and I can do this in titanium) but having no luck.
Thanks.
I some what manage this by giving my activity as 'singleInstance' in manfiest file. So now I can be sure that at a time same instance is running.
Now for handling intent data I am registering onNewInstance method. By using this intent data is get affected everytime when I comes from background or when when I select any file to open with my application.
Thanks.

How to Assign a Quick Launch Hotkey to a Specific App on Android

I am trying to set a quicklaunch shortcut key for my app.
I am able to bring up the Quick Launch screen with the following code:
launchIntent = new Intent();
launchIntent.setAction("android.intent.action.MAIN");
launchIntent.setPackage("com.android.settings");
launchIntent.setComponent(new ComponentName("com.android.settings", "com.android.settings.quicklaunch.QuickLaunchSettings"));
startActivityForResult(launchIntent,0);
The screen looks like this: Quick Launch Screenshot. You can assign an app to, for example, "a", and when you press find-a, it will launch that app.
What I'd really like to do is to programmatically assign a hotkey to a specific app, but I cannot figure out how to do this. Is this possible, and how?

Android: merging two diffrent application into one

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

Android: Starting An Activity For A Different Third Party App

I'm working on an app and I want to integrate the Last.fm app into it. Basically, when someone is looking at an artist in my app, I would like to have a button that they can tap to open up Last.fm application with the artist's information.
This intent works, but it loads a menu asking which app I would like to use (Browser or Last.fm):
Intent i = new Intent();
i.setData(Uri.parse("http://last.fm/music/" + headliner));
i.setAction("android.intent.action.VIEW");
startActivity(i);
However, I just want to start the Last.fm app and skip the dialog asking which app to use, I thought maybe using the setPackage() method would work like this:
i.setPackage("fm.last.android");
But it causes the app to crash:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://last.fm/music/Rihanna pkg=fm.last.android }
Is it possible to just start the Last.fm app? Here's a copy of Last.fm's AndroidManifest.xml for reference.
Thanks for reading,
Tony
Yes, it's possible but you need to know the correct component name. Launch the last.fm app regularly and check the logfile for the cmp=... information that's been used when the app is started. Use this as well in your app then.
I start the Z-DeviceTest app from the market from within my app without a problem like this:
final Intent intentDeviceTest = new Intent("android.intent.action.MAIN");
intentDeviceTest.setComponent(new ComponentName("zausan.zdevicetest","zausan.zdevicetest.zdevicetest"));
startActivity(intentDeviceTest);
in my case the info I took from the logcat was:
// dat=content://applications/applications/zausan.zdevicetest/zausan.zdevicetest.zdevicetest
// cmp=zausan.zdevicetest/.zdevicetest
in order to know how to start the app with the right component/class... do the same for the last.fm app
Edit:
I've tested to launch Last.fm from my own app, and this works fine without any errors:
final Intent intentDeviceTest = new Intent("android.intent.action.MAIN");
intentDeviceTest.setComponent(new ComponentName("fm.last.android","fm.last.android.LastFm"));
startActivity(intentDeviceTest);

Categories

Resources