ActivityNotFoundException - Send Intent between two apps - android

I am trying to send an intent from the MainActivity of App A to the MainActivity of App B and then bring the App B to the front but when starting the App A I am getting the following error:
Caused by: android.content.ActivityNotFoundException: No Activity
found to handle Intent { act=com.example.app.MainActivity
pkg=com.example.app (has extras) }
First, I am starting the App B and then the App A.
How can I send an intent from the MainActivity of app A to the MainActivity of app B and then bringing the app B to the front ?
App A MainActivity:
package com.mysender;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String pdfString = "Hello World";
final Intent intent= new Intent("com.example.app.MainActivity");
intent.setPackage("com.example.app");
intent.putExtra("path", pdfString);
startActivity(intent);
}
}
App A Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mysender">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
App B MainActivity:
package com.example.app;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
private WebView mWebView;
//private BroadcastReceiver myReceiver;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Bundle data = getIntent().getExtras();
if(data!=null){
String myString = data.getString("Id");
Toast.makeText(this,"Data Received from External App: " , Toast.LENGTH_SHORT).show();
}
}
App B Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<activity
android:name="com.example.app.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>
</application>
</manifest>
Error:
Caused by: android.content.ActivityNotFoundException: No Activity
found to handle Intent { act=com.example.app.MainActivity
pkg=com.example.app (has extras) }
final Intent intent= new Intent("com.example.app.MainActivity");
intent.setPackage("com.example.app");
intent.putExtra("path", pdfString);
startActivity(intent);
Caused by: android.content.ActivityNotFoundException: Unable to find
explicit activity class
{com.example.app/com.example.app.MainActivity}; have you declared this
activity in your AndroidManifest.xml?
final Intent intent= new Intent();
intent.setComponent(new ComponentName("com.example.app", "com.example.app.MainActivity"));
intent.putExtra("path", pdfString);
startActivity(intent);
Edit:
I have changed my manifest B to the following:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<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" />
<action android:name="com.mysender.Data"/>
</intent-filter>
</activity>
</application>
</manifest>
And the MainActivity of App A to:
package com.mysender;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String pdfString = "Hello World";
final Intent intent= new Intent("com.example.app.MainActivity");
intent.setPackage("com.example.app");
intent.setAction("com.mysender.Data");
intent.putExtra("path", pdfString);
startActivity(intent);
}
}
but I am still getting the error:
Caused by: android.content.ActivityNotFoundException: No Activity
found to handle Intent { act=com.mysender.Data pkg=com.example.app
(has extras) }

Related

Application crashes upon new Activity

I know and I do understand that this question has been asked, but I can't seem to interpret it for my application. I am creating an application - using Android Studio - that opens a Activity (called 'About'). When a user clicks on the 'about button' on my MainActivity, it should launch the 'About' activity. However, when I test this out on my device, it says the app has stopped. And on my output panel, it says something about an error with my Manifest.xml file?
MainActivity:
package com.msp.supercarsounds;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void clickedAbout(View view) {
final int result = 1;
Intent AboutButtonClicked = new Intent (this, About.class);
AboutButtonClicked.putExtra("About", "MainActivity");
startActivityForResult(AboutButtonClicked, result);
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.msp.supercarsounds">
<uses-sdk android:minSdkVersion="17"
android:targetSdkVersion="22"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
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>
</application>
</manifest>
Thank you for your help and time!
You have to declare About activity
<activity android:name=".About">
</activity>
Add this below the </activity> tag of MainActivity
your second activity "about" is not added to manifest.xml add this under the mainactivity
<activity android:name=".about">/activity>

Android activity is not started with any exception

I have created different activities with no problems so far, however, I have created now an activity called DetailsActivity that is not launched, with no exception, it just does not open (onCreate event is not getting called).
This is the manifest file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-feature android:name="android.hardware.camera" android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_tdc"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity
android:name=".activities.MainActivity"
android:label="#string/app_title"
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=".activities.FormActivity"
android:parentActivityName=".activities.MainActivity"
android:theme="#style/AppTheme" >
</activity>
<activity
android:name=".activities.GalleryActivity"
android:parentActivityName=".activities.FormActivity"
android:theme="#style/AppTheme" >
</activity>
<activity
android:name=".activities.DetailsActivity"
android:parentActivityName=".activities.GalleryActivity"
android:theme="#style/AppTheme" >
</activity>
</application>
This is the java class of the Activity:
package cl.virtualice.tdc.activities;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.TextView;
import cl.virtualice.tdc.R;
/**
* Created by Jaime on 23-10-2015.
*/
public class DetailsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
String title = getIntent().getStringExtra("title");
Bitmap bitmap = getIntent().getParcelableExtra("image");
TextView titleTextView = (TextView) findViewById(R.id.title);
titleTextView.setText(title);
ImageView imageView = (ImageView) findViewById(R.id.image);
imageView.setImageBitmap(bitmap);
}
}
And finally, this is the code that tries to launch the activity:
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
ImageGalleryItem item = (ImageGalleryItem) parent.getItemAtPosition(position);
//Create intent
Intent intent = new Intent(GalleryActivity.this, DetailsActivity.class);
intent.putExtra("title", item.getTitle());
intent.putExtra("image", item.getImage());
//Start details activity
startActivity(intent);
}
Any help will be appreciated, thanks.
You need to add those intents to a bundle and then unpack them in onCreate.
You put the Title as and extra and then write over it with the bitmap. Then in onCreate you try to get the title which was overwritten. I would be that it does not exist as an extra.
Bundle b = new Bundle();
b.putString("TITLE", item.getTitle);
b.putParcelable("BITMAP", item.getImage());
intent.putExtras(b);

intent not working i cant start another activity

complete newbie here .. im creating my first android quiz game.
i would like to start another activity if button is clicked. (from mainactivity to quizactivity)
i used intent for this but when i try to run it on device and i click on the button, the game crashes . a little help please
here is my main activity
package com.example.clicktothink;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn= (Button)findViewById(R.id.play_btn);
btn.setOnClickListener(new OnClickListener()
{ public void onClick(View v)
{
Intent intent = new Intent(MainActivity.this, QuizActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
}
});
}
}
and here is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.clicktothink"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.clicktothink.QuizActivity"
android:label="#string/app_name"
android:parentActivityName="com.example.clicktothink.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.clicktothink.MainActivity" />
</activity>
<activity
android:name="com.example.clicktothink.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>
</application>
</manifest>
please check your mainfest and change that to this .
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.clicktothink"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.clicktothink.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="com.example.clicktothink.QuizActivity"/>
</application>
</manifest>
btn.setOnClickListener(new OnClickListener()
{ public void onClick(View v)
{
Intent intent = new Intent(MainActivity.this, QuizActivity.class);
startActivity(intent);
}
});
instead of this
Intent intent = new Intent(MainActivity.this, QuizActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
change to this
Intent intent = new Intent(MainActivity.this, QuizActivity.class);
startActivity(intent);

Android Studio, error with intents

I'm using Android Studio to write and run my android application but I run into this error when I try to go from one activity to another via intent, I either get this error:
android.content.ActivityNotFoundException: Unable to find explicit activity class
{com.example.rudrunk/junit.framework.Test}; have you declared this activity in your
AndroidManifest.xml?
or a NullPointerException if I use another intent.
My manifest file is below, but all the code comes from the IDE automatically, so I don't understand what's going on.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rudrunk"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application android:theme="#style/AppTheme" android:label="#string/app_name" android:icon="#drawable/ic_launcher" android:debuggable="true" android:allowBackup="true">
<activity android:label="#string/app_name" android:name="com.example.rudrunk.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/title_activity_test" android:name="com.example.rudrunk.Test" />
<activity android:label="#string/title_activity_drunk_test" android:name="com.example.rudrunk.DrunkTest" />
</application>
Java Code for intents:
final Intent localIntent1 = new Intent(MainActivity.this, DrunkTest.class);
final Intent localIntent2 = new Intent(MainActivity.this, Test.class);
Button localButton1 = (Button)findViewById(R.id.maybe);
Button localButton2 = (Button)findViewById(R.id.yes);
localButton1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramAnonymousView)
{
startActivity(localIntent1);
}
});
localButton2.setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramAnonymousView)
{
Intent localIntent = new Intent("android.intent.action.CALL");
localIntent2.setData(Uri.parse("tel:16097212155"));
startActivity(localIntent2);
}
});
Looks like Test.class is being resolved into junit.framework.Test instead of your Activity. This could be a wrong import (import junit.framework.Test;?) but the sure way to make it work would be to use the full class name, i.e.
new Intent(MainActivity.this, com.example.rudrunk.Test.class);
In any case, it should match the class name in the AndroidManifest file.

Unable to start activity no activity found to start intent

I am trying to open a splash activity followed by main activity. But i am getting the following error in logcat.
01-20 16:46:45.568: E/AndroidRuntime(29579): FATAL EXCEPTION: main
01-20 16:46:45.568: E/AndroidRuntime(29579): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cyoa.necroprelude/com.cyoa.necroprelude.MainActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.cyoa.necroprelude.CHARACTER }
Activity code - Main Activity
package com.cyoa.necroprelude;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
Intent openStartingPoint;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
run();
}
private void run() {
Intent openStartingPoint = new Intent("com.cyoa.necroprelude.CHARACTER");
startActivity(openStartingPoint);
}
}
Activity code - Character Activity
package com.cyoa.necroprelude;
import android.app.Activity;
import android.os.Bundle;
public class Character extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.character);
}
}
here is the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cyoa.necroprelude"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.cyoa.necroprelude.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="com.cyoa.necroprelude.Character"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.CHARACTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Change
Intent openStartingPoint = new Intent("com.cyoa.necroprelude.CHARACTER");
to
Intent openStartingPoint = new Intent(this, CHARACTER.class);
String CUSTOM_ACTION = "android.intent.action.CHARACTER";
openStartingPoint.setAction(CUSTOM_ACTION);
When creating an intent that opens another screen make sure it looks something like the following
Intent intent = new Intent(thisScreen.this, newScreen.class);
startActivity(intent);

Categories

Resources