how to open other app activity from myapp? - android

I'm developing an app that opens other apps with intents and it works perfectly, but now I need to open a specific activity and I don't know if it's even possible.
already installed both app and I am not able to open specific activity from my app.
btnCallActivity.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
try {
Intent intent = new Intent();
intent.setClassName("com.rayvatapps.flatplan", "com.rayvatapps.flatplan.LoginActivity");
intent.putExtra("WEBVIEW_URL", "https://google.com/");
startActivity(intent);
} catch (Exception e) {
Toast.makeText(mContext, "oops...app is not found", Toast.LENGTH_SHORT).show();
}
}
});
Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rayvatapps.flatmaps">
<application
android:allowBackup="true"
android:exported="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".LoginActivity"
android:label="Other App"
android:exported="true">
<intent-filter>
<action android:name="com.rayvatapps.flatplan.app.LoginActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
i am getting following error
Error: No Activity found to handle Intent { act=com.rayvatapps.flatplan.app.LoginActivity }
E/Error: Permission Denial: starting Intent { cmp=com.rayvatapps.flatplan/.LoginActivity (has extras) } from ProcessRecord{4310b06 9701:com.rayvatapps.appdemotest/u0a384} (pid=9701, uid=10384) not exported from uid 10378
Any help will be highly appreciated.

In Manifest.xml of Second Apps Activity add Intent Filter -> android.intent.category.DEFAULT
<activity
android:name="com.myapp.ActivityName"
android:exported="true">
<intent-filter>
<action android:name="com.demo.any_name" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Then from your app
Intent launch = new Intent("com.demo.any_name");
startActivity(launch);

Your package and class names do not match. Based on the manifest of the app you want to start, you need to change this:
intent.setClassName("com.rayvatapps.flatplan", "com.rayvatapps.flatplan.LoginActivity");
into this:
intent.setClassName("com.rayvatapps.flatmaps", "com.rayvatapps.flatmaps.LoginActivity");
You also don't need the <intent-filter> on the Activity in the app you are trying to start, as you are using an explicit Intent to start it. If you remove the <intent-filter> make sure that you keep the android:exported="true" for the Activity, otherwise you won't be able to launch it from another application.

Related

Service does not start when the phone is started

I'm pretty new to android programming. I'm trying to start a service when the phone is started but it does not work. I've already seen other question done by other users but no one worked till now. This is my broadcast receiver.
public class StartBoot extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Intent intent1 = new Intent(context,MyService.class);
context.startService(intent1);
}
}
}
and this is my manifest
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".StartBoot">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
<service
android:name=".MyService"
android:enabled="true"
android:exported="true"></service>
</application>
In the log i read this
W/BroadcastQueue: Permission Denial: receiving Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 (has extras) } to com.google.android.apps.docs/.app.NotificationChannelReceiver requires android.permission.RECEIVE_BOOT_COMPLETED due to sender null (uid 1000)
Thank you in advance for the answers
Remove
<category android:name="android.intent.category.DEFAULT"/>
from the <intent-filter> inside <receiver> tag. This category is only needed for <intent-filter> inside of <activity> declaration. For a <receiver> you only need the ACTION.
The error message you posted has nothing to do with your application, it is complaining about another application.

Android call activity in other package doesn't work

I'm trying to start an activity in another package, I already saw a lot of answers on the topic, but the answers I found don't seem to work for me.
Here how I call the other activity:
Intent intent = new Intent();
intent.setClassName("com.packageroot.package2", "com.packageroot.package2.MainActivity");
context.startActivity(intent);
And here my Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.packageroot" >
<application
<activity
android:name=".package1.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.packageroot.package2.MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme"
android:parentActivityName=".package1.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".package1.MainActivity"/>
</activity>
And I still get this error:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.packageroot.package2/com.packageroot.package2.MainActivity}; have you declared this activity in your manifest?
What I don't get is that the path indicated is the error is exactly the name of the activity...
Thanks a lot in advance.
You could try adding the package to the build.gradle file under dependencies:
dependencies {
compile 'com.packageroot.package2'
}
change this line:
intent.setClassName("com.packageroot.package2", "com.packageroot.package2.MainActivity");
to
intent.setClassName("com.packageroot", "com.packageroot.package2.MainActivity");
The first parameter is "package name".
http://developer.android.com/reference/android/content/Intent.html#setClassName%28java.lang.String,%20java.lang.String%29
If your intent go through packages,this is what you should do.
In your Manifest
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:exported="true">//got to declare this
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="YOUR ACTION NAME" />
//At least one category,use DEFAULT if you don't have one
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
And in your Activity
Intent intent = new Intent();
intent.setAction(YOUR ACTION NAME);
intent.addCategory(Intent.CATEGORY_DEFAULT);
startActivity(intent);
Best Solution Work for me is controlling the back Button
#Override
public void onBackPressed() {
Intent intent = new Intent(CurrentActivity.this, SecoundActivity.class);
startActivity(intent);
finish();
}

No activity found to handle Intent/no launcher activity found manifest file issue

Here's the problem guys, first i tried to run my application with Launch default activity as launch action (Run Configurations --> Android --> Launch action), the logcat kept telling me that it can't find the launcher activity and the application wouldn't even start, problem is i defined my launcher activity in the manifest file, but it's like it's not reading it at all.
So i tried to launch the splash activity by specifically telling it to run it through run configurations, it did launch but during the transition to the next activity it crashed again, the logcat says no activity found to handle intent, which again, I defined the way I did in other applications and worked alright there. Plase help it's a nightmare.
Here's the code for the MainActivity:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread timer = new Thread()
{
public void run(){
try{
sleep(6000);
} catch (InterruptedException e){
e.printStackTrace();
} finally {
Intent openStarting = new Intent("totaltrainer.com.WorkoutPlace");
startActivity(openStarting);
}
}
};
timer.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
And Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="totaltrainer.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<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" >
<intent-filter>
<action android:name="totaltrainer.com.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".WorkoutPlace"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.WorkoutPlace" />
</intent-filter>
</activity>
<activity
android:name=".WorkoutHome"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.WorkoutHome" />
</intent-filter>
</activity>
<activity
android:name=".WorkoutGym"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.WorkoutGym" />
</intent-filter>
</activity>
</application>
</manifest>
use "totaltrainer.com.WORKOUTGYM" and so on
and below use this
<category android:name="android.intent.category.DEFAULT" />
Problem 1
logcat kept telling me that it can't find the launcher activity and
the application wouldn't even start
In your Manifest file, change below
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
as
<activity android:name="MainActivity">
<!-- This activity is the main entry, should appear in app launcher -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
What happens when you define this Action and Category ?
The ACTION_MAIN action indicates this is the main entry point and does not expect any intent data.
The CATEGORY_LAUNCHER category indicates that this activity's icon should be placed in the system's app launcher. If the element does not specify an icon with icon, then the system uses the icon from the element.
These two must be paired together in order for the activity to appear in the app launcher.
Problem 2
the logcat says no activity found to handle intent
Your Manifest declaration seems fine.
In your activity class, change
Intent openStarting = new Intent("totaltrainer.com.WorkoutPlace");
startActivity(openStarting);
as
Intent openStarting = new Intent();
openStarting.setAction("totaltrainer.com.WorkoutPlace");
startActivity(openStarting);

android Loosing context on web view when creating new task

I have two applications. The first one A has a web view with a link to another application and a timestamp.
In this web view, I have a link that opens another application B. In B, I have a button. The click on the button should take me back to app A,
without reloading it, and executing a javascript code that should populate some other fields in the web view.
As a result, App A should be brought back, timestamp should not be changed and the javascript called and fields properly populated.
The problem is if I do this scenario and I start app B from A using only StartActivity(), it doesn't work. I'm able to do A-B and B-A but my javascript is not called
because A is not called with the proper intent. In other words, when calling A from B, I should find in the intent object the action and the data that took me to A but instead the action in the intent is NULL
If in the other hand, I add a flag when starting Activity on B : FLAG_ACTIVITY_NEW_TASK. it works one time. A->B->A but after that I'm not able to call B again.
Another test I made: If I start calling B from the home screen and than A and than B. It works. So I guess it has to do with the fact that B is different if called using intent from A or from home screen.
Anyway, I couldn't make it open the app, call the js and keep the context all in the same time.
I only tried on emulator.
Here is Manifest for App A
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cgi.csb.launcher"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="12"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:label="#string/app_name" android:icon="#drawable/ic_launcher">
<activity android:name=".Activity1" launchMode="singleTask">
<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"/>
<data android:host="localhost" android:scheme="myactivity"></data>
</intent-filter>
</activity>
</application>
</manifest>
Here is the manifest for App B
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.CallerApp"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="12"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:label="#string/app_name">
<activity android:name=".Activity2" launchMode="singleTask">
<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"/>
<data
android:host="dummy"
android:scheme="testintentapp"/>
</intent-filter>
</activity>
</application>
</manifest>
To call B from A :
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addCategory("android.intent.category.DEFAULT");
startActivity(intent);
return true;
}
To call A from B :
case R.id.button:
Intent intent = new Intent();
intent.setData(Uri.parse("myactivity://localhost"));
intent.putExtra("firstKeyName","FirstKeyValue");
intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();
break;
The code I use to differentiate when A is called from home or from App B to call the javascript
Intent intent = getIntent();
if ("myactivity://localhost".equals(intent.getDataString())) {
Log.d(TAG, "*** Call JS with action : " + intent.getAction());
_jsHandler.javaFnCall("Hardcoded params");
} else {
Log.d(TAG, "***Just call the app with action :" + intent.getAction());
}
Thanks a lot !

How to launch a certain activity of an Android app

I would like to launch, from my app, two specific activities A_Activity and B_Activity from apps Aapp and Bapp
I inserted two buttons and in the two OnClickListener I wrote
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction("com.Acompany.Aapp.A_Activity");
ctx.startActivity(intent);
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction("com.Bcompany.Bapp.B_Activity");
ctx.startActivity(intent);
Moreover I added to AndroidManifest.xml the following lines
<activity
android:name="com.Acompany.Aapp.A_Activity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.Acompany.Aapp.A_Activity" />
</intent-filter>
</activity>
<activity
android:name="com.Bcompany.Bapp.B_Activity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.Bcompany.Bapp.B_Activity" />
</intent-filter>
</activity>
But my app crashes and in the logcat I read "No Activity found to handle Intent"
Where is my mistake?
EDIT: More precisely the two activities are not in my own app
More precisely the two activities are not in my own app
You should investigate target app's manifest file first, to check if these activities are available to others by being exported or offering publicly accessible intent filters. It looks you may simply be not allowed to do what you attempt to.
Try like this. For your home activity(first launch activity) do like this in your manifest file.xml
<activity
android:name="com.Acompany.LaunchHomeActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.Acompany.LaunchHomeActivity" />
</intent-filter>
</activity>
<activity android:name="com.Acompany.Aapp.A_Activity">
</activity>
<activity android:name="com.Bcompany.Bapp.B_Activity">
</activity>
don't include <intent-filter> to all activities
Intent intent = new Intent(myFirstClass.this, MySecondClassA.class);
startActivity(intent);
Class B
Intent intent = new Intent(myFirstClass.this, MySecondClassB.class);
startActivity(intent);

Categories

Resources