Start android application from code - android

I need simple start an application from my code, like Skype, or other one.
I read some thread, on the internet, but I haven't solution.
I tried this methode:
Intent startApp = new Intent("com.android.gesture.builder");
startActivity(startApp);
I wrote this in try/catch blokk, and the LogCat told me: ApplicationNotFound exception handled by Intent. I read the "Hello" tutorial on the Android Developers site, but it's too comlicated, to my solution...
I can't register this application starting activity to my manifest file.
I think I need to implement a new class, that extends from Activity, and implement, the code above, and try again?
Please help me, how can I start other application from my main activity easy...

You were nearly there!:
You just need to supply the package and class of the app you want.
// Try
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("com.htc.Camera", "com.htc.Camera.Camera"));
startActivity(intent);
// catch not found (only works on HTC phones)
ComponentName
I also just saw you can do it a second way:
PackageManager packageManager = getPackageManager();
startActivity(packageManager.getLaunchIntentForPackage("com.skype.android"));
See: SOQ Ref

Related

Start Wikipedia via Intent

I tried to start the Wikipedia App via Intent but I always get an InvocationTargetException, because the Activity can't be found. I can detect that Wikipedia is installed, but I can't start it. I know that I can also use the Intent Filter and call the Wikipedia URL, but then the user can decide between app and browser (both works different with the search param, which is not very useful) and I want to decide it for the user.
I tried it with following code:
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "searchString");
intent.setType("text/plain");
intent.setPackage("org.wikipedia");
Can somebody tell me, what I am doing wrong there or is it just not possible to start the wikipedia app? :-/
Finally I come to a solution after I was looking in the wikipedia code on github (https://github.com/wikimedia/apps-android-wikipedia). The app listens only for View Intents, which means that following code works:
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(searchUri);
intent.setPackage("org.wikipedia");
The problem here is, that only URI's for existing articles were handled and no search operation can be used. After watching a little bit more in the code, I found a PageActivity which also listens for ACTION_SEARCH Intents. This would work, when in the AndroidManifest.xml this Intent Filter would be also available.

How to find out the reason why Activity doesn't start

I got log cat message from startAnotherActivity() method
private void startAnotherActivity() {
Log.i(TAG, "Entered startAnotherActivity()");
Intent intent = new Intent();
intent.setAction(ANOTHER_ACTIVITY);
intent.addCategory("android.intent.category.DEFAULT");
startActivity(intent);
}
Another activity doesn't start, no other messages in log cat.
How can I resolve this issue?
UPDATE#1:
Sorry, I forgot to mention that AnotherActivity is an Activity in the other application, and therefore ANOTHER_ACTIVITY == 'some.other.app.domain.ANOTHER_ACTIVITY'
Shouldn't Dalvik complain if it cannot find specified activity?
One possible reason may be not declaring other activity in the manifest. You can do this like the following:
<activity android:name="your.package.your.activity">
</activity>
And then you can start the activity by doing the following:
Intent intent = new Intent(CurrentActivity.this, NewActivity.class);
startActivity(intent);
Hope this helps.
Since it's an activity in another application, you may need to set the component (fully qualified package name and fully qualified activity name).
See here: How to start activity in another application?
Or here:
Launch an application from another application on Android
Finally I found out my mistake.
In the project there are two similar messages in two activities, so I thought that runs one, but that was another.
Thank you for your assistance!

Launch another App within an App for android

I am new to Android. Say, I open an app and I would like to open another App after clicking a button. How can I accomplish this task? Would appreciate if you can provide me some tutorial on this.
Intent intent = new Intent();
intent.setClassName("**package.name**", "**package.name.LauncherActivityName**");
startActivityForResult(intent,REQUEST_CODE);
You need to know the package and class names of the activity to call
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("app package name");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
Use this code:
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.package");
startActivity(launchIntent);
The app you want to launch must be on the device.
Intent appIntent = getPackageManager().getLaunchIntentForPackage("your app package name ");
startActivity(appIntent );
If the other application is a pre-packaged application mean, this tutorial may help you.
If the other application is going to be your application, then you need to learn Implicit Intent tutorials.
Also include the activity of the other application which you are planning to call in the Manifest file of the calling package also.

How do we find the information for launching other app?

I need to allow user to draw/sketch/paint something. There are already many apps(like Skitch, I will use this as an example) that accomplish this task. So I don't want to re-invent the wheel.
In Android, theoretically, we can launch other activity by intent. This is sort of like "pipe" in Unix.
The problem is, I don't know how to get the information for launching Skitch.
To integrate Skitch in my app, I need to know the Action it supports, the returning intent (if any) when it finishes.
I installed Skitch, photoshop, and lots of other touch drawing apps in my device, but this code doesn't work :
Uri data = Uri.fromFile(file);
Intent i = new Intent(Intent.ACTION_EDIT);
i.setData(data);
i.setType("image/*");
startActivityForResult(i, ACTIVITY_DRAW);
I can launch Skitch from my app in the following way: but obviously I can't get any returned result this way(code from here).
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.evernote.skitch");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
My question: Is there a standard way to find information for launching a third party app?
Is this site the only way to share/get such information?
Or if you have any suggestions for my problem, please help me.
Thank you!
As you might already know how to call another application Activity from your app ..this way Mentioned Here.
Intent intent = new Intent(Intent.ACTION_RUN);
intent.setComponent(new ComponentName("<packet name>", "<class name>"));
List list = packageManager.queryIntentActivities(intent, packageManager.COMPONENT_ENABLED_STATE_DEFAULT);
if(list.size() > 0)
{
Log.i("Log", "Have application" + list.size());
startActivity(intent);
}
else
{
Log.i("Log", "None application");
}
All your require is Mainly Two Things to call any Activity
1) Package Name of that Activity
2) Activity Class Name
These two informations only can be available if they are opensource or made free to use .. like Zxing,Google Maps Application.
There is another way to start an application activity like,
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + numberField.getText())); // set the Uri
startActivity(intent);
For this way to use need to know the correct Action for the Activity you want to call and the Correct parameter to pass with.
And again,These information only can be available if they are opensource or made free to use .. like Facebook and Gmail apps to share and post messages.
So If you are searching for anything like which can tell you what you will need to pass to call any specific comercial apps in your device, you wont find it directly.
It's an old question but perhaps it could help somebody to know that Sony's AppXplore application (free) shows the package and name of the activities of every app installed on your device, so you can eventually use them to do explicit Intents.

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