startActivity does not launch a new Activity of other app - android

I have two android apps(i.e. BIApp and EApp) and I am trying to open EApp from BIApp.
EApp has two activity one is MainActivity and another is LandingPageActivity.
When I try to launch MainActivity using startActivity(intent) it works fine but if I try to launch LandingPageActivity. startActivity(intent) does nothing.
if EApp is open in background then startActivity(intent) works for LandingPageActivity too.
Below is the code snippet that I am using.
Intent intent = new Intent();
intent.setClassName("com.pkg.eapp", "com.pkg.eapp.LandingPageActivity");
startActivity(intent);
I want to start LandingPageActivity.
What should I do ?

Try this:
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.pkg.eapp", "com.pkg.eapp.LandingPageActivity"));
startActivity(intent);
and add
android:exported="true"
and in the intent-filter add
<category android:name="android.intent.category.DEFAULT"/>
to the declaration of LandingPageActivity in the manifest.

Try this, this is working for me
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.pkg.eapp", "com.pkg.eapp.LandingPageActivity"));
startActivity(intent);

Read how to allow Other Apps to Start Your Activity
You only need to add android.intent.category.DEFAULT category to your Activity onto manifest. Like below
<activity android:name="com.pkg.eapp.LandingPageActivity">
<intent-filter>
<action android:name="com.pkg.eapp.action.OPEN_LANDING_PAGE" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
and call it as
Intent intent = new Intent("com.pkg.eapp.action.OPEN_LANDING_PAGE");
intent.setComponent(new ComponentName("com.pkg.eapp", "com.pkg.eapp.LandingPageActivity"));
// Or intent.setPackage("com.pkg.eapp");
startActivity(intent);

I have never done this but may be LandindPageActivity is not accessible by other apps. In your EApp manifest, do you have an intent filter like this for the LandingPageActivity ?
<intent-filter>
<action android:name="com.pkg.eapp.LandingPageActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Try this:
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.pkg.eapp.LandingPageActivity");
startActivity(LaunchIntent);
Hope this might help you.

Related

Android click a button by intent

I have a service running into my device. When this service execute a specific task, i want to create an intent. This intent should open another application and at the same time, perform a button click that is implemented in this second app. How do I SEND and GET this intent?
This is the manifest of the second application.
<activity
android:name="com.example.app2">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
I don't know how to implement the sender. Is this correct?:
Intent in = new Intent("com.example.app2.MAIN");
context.startService(in);
I solved implemented a simply intent a put Extra:
Intent ii = new Intent();
ii.setComponent(new ComponentName("com.example.app2", "com.example.app2.INTENT_MAIN"));
ii.putExtra("ACTION", "TEST");
this.startService(ii);
and into the second activity, I read the intent extra value:
Intent ii = new Intent();
ii.getStringExtra("ACTION");

Skype chat screen from intent

I am trying to make an intent that starts skype conversation with a certain person. Having looked through it all over the stackoverflow, I still cannot make it work properly. Here's my code:
String skypeUri = "skype:name?chat";
Intent intent = new Intent();
intent.setData(Uri.parse(skypeUri));
intent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
My intent filter:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
<data android:scheme="skype" />
</intent-filter>
It brings me to skype but only to the main page of it, no conversation is opened.
Any help would be appreciated.
just use below code
Intent skypeIntent = new Intent("android.intent.action.VIEW");
skypeIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
skypeIntent.setData(Uri.parse("skype:" + skypeId + "?chat"));
Assuming that is your exact code, the problem is that you are not passing the username of the person you want to call. You just have 'name' where their username should be. You need something like:
String skypeUri = "skype:"+username+"?chat";

Unable to start activity through intent: ActivityNotFoundException

I have this Activity defined in my AndroidManifest.xml:
<activity
android:name=".Splash"
android:label="#string/app_name"
android:noHistory="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
When I am trying to call it in this way:
Intent splashActivity = new Intent("android.intent.action.Splash");
mainAppContext.startActivity(splashActivity);
I get:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.Splash }
And when I try to start it in this way:
Intent splashActivity = new Intent("android.intent.action.MAIN ");
mainAppContext.startActivity(splashActivity);
It open a Complete action using dialog with many options there like play store etc.
Please help in starting this Activity.
From some other Activity:
startActivity(new Intent(this, Splash.class));
Intent splashActivity = new Intent("android.intent.action.Splash");
No-no-no! It should to
Intent splashActivity = new Intent(context, Splash.class);
If you use action - it seem that you want activity for some type of action, for example, view webpage on browser.
In your situation you have to use concrete activity and set it to intent
<action android:name="android.intent.action.MAIN" />
this action is not for your app, it is needed to android's launcher, that find activity in your application to launch it
Official documentation about intent mechanism
Where are you trying to launch this activity from? The following lines imply that Splash is your main Activity:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Are you trying to launch the Splash Activity from Splash itself? This would be problematic. If you are launching from another Activity then you can use the following to launch Splash:
Intent intent = new Intent();
intent.setClass(YourCurrentActivity.this, Splash.class);
startActivity(intent);
Activity not found exception is occurred when u are trying to use or start activity that is not declared into the Mainfeast.xml file.
And When you want to start any activity then you need to start that activity by using intent. but in android "android.intent.action.Splash" Intent Action exist. And you have declared the following intent filter
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
"android.intent.action.MAIN" this is the action name that indicate the this is the activity to be started first. and android send this intent and an activity that is registered with this intent action is the first activity to be started first.
So to start splash activity you doesn't need any intent. You just need to simply run this project. but If u want to Start Another activity from splash actiivty then u need to do following things.
Intent intent = new Intent(Context, ActivityName.class);
startActivity(intent);
or
startActivityForResult(intent, requestCode);
and remember that You have to declare that activity into the mainfeast.xml

How to launch app at the same time on Android

I have two apps, A and B.
I want to call B by A.
My code in A is as below:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.example.bapp","com.example.bapp.BActivity"));
intent.putExtra ("test2abc", "abctest2");
startActivity(intent);
And B's intent filter in manifest as below:
<intent-filter>
<action android:name="ACTION_BACKCALL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
But it will close B before launch B while B had opened.
I find below code to open *.txt file. This will open two txt reader app at the same time.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), mimetype);
startActivity(inte
nt);
How can I arrive that?
hey i found this code snippet Launch an application from another application on Android which will work for you
set the address of the application which you want to launch
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);
you might want to try android:launchMode="singleInstance" and
android:finishOnTaskLaunch="true" while defining launcher activity.
<activity
android:name="com.example.test.sampleMediaPlayer"
android:label="#string/app_name"
android:launchMode="singleInstance"
android:finishOnTaskLaunch="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
For Activity A.

PendingIntent not launching app

I have a service running that will put a notification on the notification bar on a particular event. In that notification I'm setting a PendingIntent to launch another application. For some reason when I act on the notification it doesn't launch the other application. Here is the code where I create the PendingIntent.
private PendingIntent externalAppStartIntent(LaunchInfo launchInfo) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName(launchInfo.getPackageName(), launchInfo.getActivityName());
intent.setData(launchInfo.toUri());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return PendingIntent.getActivity(this, ZONE_SERVICE_START_EXTERNAL_APP, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
}
I am able to launch the app using a regular Intent elsewhere in my code like this.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName(packageName, activityName);
intent.setData(data);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
ZoneUtils.launchMarketDialog(getActivity(), packageName);
}
I've checked to make sure the values of the variables I'm sending in both cases are the same.
Note that I'm trying to launch an Activity in another application outside of the one where this code lives.
EDIT:
Here is the activity definition from the other apps manifest.
<activity
android:name=".ui.GalleryActivity"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="join"
android:path="/"
android:scheme="mgp" />
</intent-filter>
</activity>
EDIT2:
Here is the log I get when I act on the notification
04-20 19:05:59.151: I/ActivityManager(193): START {act=android.intent.action.VIEW cmp=com.brockoli.magnet.photoapp/.ui.GalleryFragment bnds=[128,418][720,546]} from pid -1
David Suppiger spotted it!
I was accidentally passing my GalleryFragment instead of my GalleryActivity. Working great now! Ty

Categories

Resources