Deep linking does not open a new app - android

I have two apps. From the first, I want to launch the second one by deep linking. It works but the problem is that the second one starts inside the first one. I would like to start the second one in a new instance.
The code of the first app to open the second app:
String uri = "deeplinkTestTom://token/123456";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
The manifest of the second app:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data
android:scheme="deeplinkTestTom" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
When I try to launch Facebook app from my first app (String uri = "facebook://facebook.com/inbox";), it launch facebook in a new app and not inside my first app. So I suppose that something is missig in the manifest of my second app, but I can't find what.
What should I do ?

I believe you're talking about new Task instead of "new app".
Read Tasks and Back Stack
You need to use Intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) to start an Activity in a new Task.
For your case, use
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Related

Intent does not work in same way all the time in Android

There are 2-3 ways to use Intent to start New Activity.
Mostly, I am using
Intent openStartingPoint = new Intent("com.Example.Jeeten.Connection");
startActivity(openStartingPoint);
But sometimes, It does not work, It shows error Activity not found and in that case If I use
Intent openStartingPoint = new Intent(Connection.this, Hello.class);
startActivity(openStartingPoint);
then It works fine. What can be the issue with this ?
When u make an activity, u have to register it in your AndroidManifest.xml file.
<activity
android:name=".Connection"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.Example.Jeeten.CONNECTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
In the above code <activity android:name represents your activity class(Case sensitive),in your case its Connection and Hello.Next is <action android:name in this you specify by what name are you going to refer to the activity(its a good practice to put the last word all in uppercase CONNECTION).
So make sure you have two such activities in your xml file.In case one of the activity is your starting point of your app,modify the <intent-filter> like this
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

Why is my app not showing in the list of default launchers?

I have an application where it is going to be the home screen, default launcher. I am implementing this by using the CATEGORY_LAUNCHER in my intent and CATEGORY_HOME in my manifest file, the home activity has ACTION_MAIN and CATEGORY_HOME. Because there are multiple homes set then android prompts the user to select one with the optional extra of selecting a default one. There are many default apps in this list on my emulator but my app is not one of them. Does someone know how to get my app onto the list?
Here is how I am sending the intent:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_LAUNCHER);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
Here the relevant part of the manifest:
<activity
android:name=".NewHome"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>
If you want to show your application in Default launchers. Change your code as:
<activity
android:name=".NewHome"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

ActivityNotFoundException when calling activity of another application

I keep getting "ActivityNotFoundException: Unable to find explicit activity class ... " when using Eclipse's emulator to call the activity of another application from an application. Perhaps the problem maybe related to I am not able to download to/find both applications at the same time when I click on "Manage Applications" in Settings. This is the first project I need to call the activity of another application. But I am not sure the code is correct either. Please help me determine if there are errors in the code snippets I present below. It is hinted that I can set the action field of the intent to achieve the objective but have not found learning material for this. I learned about using the setComponent method in the calling app and to add android:export to the called activity's AndroidManifest.xml. Thanks in advance!
Calling app's relevant source code:
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.MyPackage", om.MyPackage.Activity1));
startActivity(intent);
Calling app's relevant AndroidManifest.xml :
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity1">
<intent-filter>
<action android:name="com.MyPackage.Activity1" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Relevant code of AndroidManifest.xml of the activity of another application
<activity android:name=".Activity1" android:exported = "true">
<intent-filter>
<action android:name="com.MyPackage.Activity1" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Firstly point out that you're trying to start Activity in Application2 from Activity in Application1
You have to give them separate namespaces
both applications now have com.MyPackage.* prefix
OR use names Activity1 and Activity2
So you will have
com.MyPackage1.Activity1
// and
com.MyPackage2.Activity1
Then you can use this code, to start Activity1 in MyPackage2 from MyPackage1.
// in file com.MyPackage1.Activity1
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.MyPackage2", "com.MyPackage2.Activity1"));
startActivity(intent);
And your AndroidManifest.xml files should look like this:
first
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name="com.MyPackage1.Activity1"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
second
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name="com.MyPackage2.Activity1"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
see related SO question:
How to start activity in another application?

What does it mean "No Launcher activity found!"

I am writing a simple program of Android, and getting these no errors, I don't know what they are. My program is right, but showing not output.
I think it is because of these two lines:
[2005-01-06 19:56:38 - my_Android] No Launcher activity found!
[2005-01-06 19:56:38 - my_Android] The launch will only sync the application package on the device!
Here's an example from AndroidManifest.xml. You need to specify the MAIN and LAUNCHER in the intent filter for the activity you want to start on launch
<application android:label="#string/app_name" android:icon="#drawable/icon">
<activity android:name="ExampleActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Multiple action tags in a single intent-filter tag will also cause the same error.
Like Gusdor said above, "Multiple action tags in a single intent-filter tag will also cause the same error." (Give him the credit! I could just kiss Gusdor for this!)
I didn't find any docs for this fact!
I had added a new (USB) action and being clever, I lumped it in the same intent-filter. And it broke the launch.
Like Gusdor said, one intent filter, one action!
Apparently each action should go in its own intent filter.
It should look like this...
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
When I did this, WAZOO! it worked!
Do you have an activity set up the be the launched activity when the application starts?
This is done in your Manifest.xml file, something like:
<activity android:name=".Main" android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Check your manifest.xml. Make sure you have the category LAUNCHER there.
<activity android:name=".myActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It means you didn't specify an Activity for Android to launch as the default when the app opens from the launcher. You have to add an Intent Filter in the Manifest for the Activity you would like to act as the default when the app is being launched.
Read http://developer.android.com/guide/topics/intents/intents-filters.html#ccases for more details.
I fixed the problem by adding activity block in the application tag. I created the project using wizard, I don't know why my AdroidManifest.xml file was not containing application block? I added the application block:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".ToDoListActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
And I get the desired output on the emulator.
As has been pointed out, this error is likely caused by a missing or incorrect intent-filter.
I would just like to add that this error also shows up if you set android:exported="false" on your launcher activity (in the manifest).
I had this same problem and it turns out I had a '\' instead of a '/' in the xml tag. It still gave the same error but just due to a syntax problem.
If you are using the standard eclipse IDE provided by google for Android development, you can check the "Launcher Activity" check-box while creating a new Activity. Please find below:
In Eclipse when can do this:
But it is preferable make the corresponding changes inside the Android manifest file.
You missed in specifying the intent filter elements in your manifest file.Manifest file is:
<application android:label="#string/app_name" android:icon="#drawable/icon">
<activity android:name="Your Activity Name"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Add and check this correctly. Hope this will help..
Manifest is case sensitive, so please compare this lines for any case mismatch especially the word MAIN in:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
You can add launcher to activity in eclipse manifest visual editor:
MAIN will decide the first activity that will used when the application will start.
Launcher will add application in the application dashboard.
If you have them already and you are still getting the error message but maybe its because you might be using more than more category or action in an intent-filter. In an intent filter there can only be one such tag. To add another category, put it in another intent filter, like the following
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!--
TODO - Add necessary intent filter information so that this
Activity will accept Intents with the
action "android.intent.action.VIEW" and with an "http"
schemed URL
-->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
just add this to your aplication tag in AndroidManifest.xml file
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
and also edit the uses-sdk tag from android:targetSdkVersion="16" to 17
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
You have not included Launcher intent filter in activity you want to appear first, so it does not know which activity to start when application launches, for this tell the system by including launcher filter intent in manifest.xml

How do I start my app from my other app?

How do I start my app from my other app? (they will not be package together)
--update
Manifest of the second app:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloandroid"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".HelloAndroid"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".HelloAndroid">
<intent-filter>
<action android:name="com.example.helloandroid.HelloAndroid" />
</intent-filter>
</activity>
</application>
</manifest>
I calling it with:
startActivity(new Intent("com.example.helloandroid.HelloAndroid"));
and it throws:
07-16 15:11:01.455: ERROR/Desktop(610): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.helloandroid.HelloAndroid }
Ralated:
How to launch android applications from another application
In the first app, you will have to modify the AndroidManifest.xml. Specifically, you are going to add a custom action into the intent-filter of the activity that you want to launch from somewhere:
<activity android:name="FirstApp">
<intent-filter>
<action android:name="com.example.foo.bar.YOUR_ACTION" />
</intent-filter>
</activity>
Then, in your second app you use that action to start the activity:
startActivity(new Intent("com.example.foo.bar.YOUR_ACTION"));
With regards to your comments:
Looks like if I change the default name "android.intent.action.MAIN" I'm not able to run the app from the Eclipse in the Virtual Device
Keep in mind you can have as many actions as you want... for instance:
<activity android:name="FirstApp">
<intent-filter>
<action android:name="com.example.foo.bar.YOUR_ACTION" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
This questions seems similar to one I answered earlier today.
If you just want to start like you started it from the launcher:
Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(new ComponentName( "PACKAGE NAME", "CLASS" ));
startActivity(intent);

Categories

Resources