I am trying to use YouTubeStandalonePlayer from https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubeStandalonePlayer
With this code inside onCreate():
Intent intent = YouTubeStandalonePlayer.createVideoIntent(this, DeveloperKey.DEVELOPER_KEY, VIDEO_ID);
startActivity(intent);
But application fails with error.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.youtubestandalone/com.example.youtubestandalone.MainActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.android.youtube.api.StandalonePlayerActivity.START (has extras) }
How to fix this?
Add this line to your AndroidManifest.xml
<activity
android:name="com.google.android.youtube.api.StandalonePlayerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
/>
Check if you have include the jar file in your project. Make sure you have done the follow steps.
Right Click your project
Select Properties
Select Java Build Path
Go to Order and Export Tab
Tick YouTubeAndroidPlayerApi
Good luck!
Related
Running tests with createComposeRule and hitting a stack trace like (irrelevant parts omitted):
java.lang.RuntimeException: Could not launch activity
at androidx.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:495)
...
Caused by: java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=my.app.package.name.here/android.app.Activity }
...
The OP question is about the use of createComposeRule() which doesn't require a custom activity (it uses ComposeActivity under the hood).
In this case you need to include this below in your gradle file:
debugImplementation("androidx.compose.ui:ui-test-manifest:1.0.0-beta05")
If you take a look at the contents of that package, it's simply an AndroidManifest.xml with an <activity/> entry for androidx.activity.ComponentActivity.
You need declare an Activity with name android.app.Activity in your AndroidManifest.xml for the Compose UI tests to use to host the content. Add the following within your <application> tag:
<activity android:name="android.app.Activity" android:theme="#style/your_app_theme_here"/>
substituting your_app_theme_here with a theme that exists in your app.
You need to add
<activity android:name="androidx.activity.ComponentActivity" />
to your manifest.
The app crashes in Android Studio when a button is clicked to reach the another activity through intent
public void next(View view) {
Toast.makeText(getApplicationContext()," Next called " , Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),SecondActivity.class));
}
The error I am getting from logcat is
Caused by: android.content.ActivityNotFoundException: Unable to find
explicit activity class
{com.example.utkarsh.internalstorage/com.example.utkarsh.internalstorage.SecondActivity};
have you declared this activity in your AndroidManifest.xml?
specify activity in your android manifest file
<activity android:name="SecondActivity"> </activity>
The issue is, the SecondActivity Activity wasn't added to the AndroidManifest.xml. Once you add that as an application node, it will work properly.
<activity android:name="com.example.utkarsh.internalstorage.SecondActivity" />
Error message is clear, define your activity in your manifest
I read all other answers about this problem but it doesn't help me.
I have an app (MyApp) which include a library (named lib (example)). In my app, I call LoginActivity in my lib.
But I have this exception.
java.lang.SecurityException: Permission Denial: starting Intent { cmp=fr.myotherapp/.activity.LoginActivity
Myotherapp is a other app which I created and installed in the same device.
I don't set "exported"="true" in myotherapp manifest because I dont want to use this one but I set "exported"="true" for the activity in the lib manifest.
I use Android Studio.
Why does Android want to use this one even if I call the activity like this ?
final Intent intent = new Intent(mContext, fr.lib.activity.LoginActivity.class);
Thanks
If you are using eclipse, try adding manifestmerger.enabled=true to your project.properties file.
relevant docs :
http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger#TOC-Android-Manifest-file-merging
https://roostertech.wordpress.com/2013/10/29/manifest-merger/
I have an Android library project that I would like to use from within another Android project.
The library has a Activity declared in its AndroidManifest. When I try the following within the second project:
Intent intent = new Intent(this, ReaderActivity.class);
startActivity(intent);
I get the following exception:
java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.digitalpages.reader.demo/br.com.digitalpages.reader.demo.ReaderDemoActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {br.com.digitalpages.reader.demo/br.com.digitalpages.reader.ReaderActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
...
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {br.com.digitalpages.reader.demo/br.com.digitalpages.reader.ReaderActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
...
How can I open the Activity from the another project?
EDIT:
By users answers I added the following line into my second project
<uses-library android:name="br.com.digitalpages.reader" android:required="true" />
But it's still doesn't works
I believe you must include the <activity> in your own AndroidManifest.xml -- I don't think it gets picked up from a library. I don't have my reference for that handy.
Update: It's official solution. From the doc:
Declaring library components in the manifest file
In the manifest file of the application project, you must add
declarations of all components that the application will use that are
imported from a library project. For example, you must declare any
<activity>, <service>, <receiver>, <provider>, and so on, as well as
<permission>, <uses-library>, and similar elements.
Declarations should reference the library components by their
fully-qualified package names, where appropriate.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("packagename//ex-com.hello",
"classname//ex-com.hello.ExampleActivity"));
startActivity(intent);
And make sure in library you have declared the activities. You don't need to declare the library activities in your current project's manifest.
did you add to the manifest?
http://developer.android.com/guide/topics/manifest/uses-library-element.html
This works:
In your library, put your custom Activity:
public class MyLibraryActivity extends ListActivity { ... }
No need to put it into a manifest.
In your calling Android project, create an empty (dummy) wrapper:
public class MyActivity extends MyLibraryActivity { }
and add reference to this class to your manifest:
<activity android:name="my_package.MyActivity" ... />
I am aware that the question is quite old but I think this might help people like me that came up with the same problem.
Using Eclipse, the best way to share code and activities among libraries is probably the one that can be found in the android documentation here:
Managing Projects from Eclipse with ADT
When using an activity inside the library, the activity should be declared only inside the manifest of library.
The activity can be started from the main app like this:
Intent intent = new Intent();
intent.setClassName(this, "com.duna.remotelocklibrary.activities.MainRemoteActivity");
startActivity(intent);
I tried to start the library's activity like the following code, but i warn you: it doesn't work
Intent intent = new Intent();
intent.setClassName("com.duna.remotelocklibrary", "com.duna.remotelocklibrary.activities.MainRemoteActivity");
startActivity(intent);
you should import just the code of the activity ( not the manifest too ) , and then , declare your Activity ( of the library ) , in the manifest of your second project
You don't need to explicitly add activity in your main project's manifest if you have already added the activity in your library's manifest by using the following code when starting library's activity.
For Kotlin
val myIntent = Intent(activityContext, ActivityToLaunch::class.java)
// Needed to set component to remove explicit activity entry in application's manifest
myIntent.component = ComponentName(activityContext, PickerActivity::class.java)
activityContext.startActivity(myIntent, PICKER_REQUEST_CODE)
For Java
Intent myIntent = new Intent(activityContext, PickerActivity.class);
// Needed to set component to remove explicit activity entry in application's manifest
final ComponentName component = new ComponentName(activityContext, PickerActivity.class);
myIntent.setComponent(component);
activityContext.startActivity(myIntent, REQUEST_CODE);
i have created 4 activities in eclipse now i want to run activity 1, 2,3 ,4 repectively one by one in emulator for testing.
can any one guide me how can i run those all???
when i press run button it only runs first activity.
any help would be appriciated.
You could try startActivityForResult but you may need to possibly modify your program your applications to handle this.
I would suggest using one of the android sdk tools called am (activity manager).
In the adb shell:
# am start -n package-name/activity-1-name
# am start -n package-name/activity-2-name
# am start -n package-name/activity-3-name
# am start -n package-name/activity-4-name
Go to the AndroidManifest.xml and cut
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
from the Main Activity. Then paste it into the Activity that you want to start.
To Run A specific Activity First
Change the Activity Name In the setContentView within the Main Activity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.Your_Activity_Name);
}
public void onClick(View v) {
Intent i;
i = new Intent(this, YourActivity1.class);
startActivity(i);
i = new Intent(this, YourActivity2.class);
startActivity(i);
i = new Intent(this, YourActivity3.class);
startActivity(i);
i = new Intent(this, YourActivity4.class);
startActivity(i);
}
Android SDK includes the JUnit framework for writing unit tests. You can use the package android.test packages to run activities under JUnit. It may be overkill for what you want but eventually you may need this functionality.
References:
http://junit.sourceforge.net/
http://mylifewithandroid.blogspot.com/2008/11/junit-in-android.html
Go to the Android Manifest file under your workspace root and double click on it to open. Go to the AndroidManifest.xml tab and change the name of the first activity to whatever activity you want to launch at run. Also make sure you rename that first activity to the other activity so ADT doesn't throw errors. Basicall, switch their names in the xml file. I had to do it because I wanted to test each activity individually before linking them. Let me know if you have any other question.