Not the right Activity java.lang.SecurityException: Permission Denial: starting Intent - android

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/

Related

Permission Denial: start Intent

In my app, I have to use Intent.setClassName or setComponent to start an activity in another package. There is no problem when I use Intent.setClass like
Intent intent = new Intent(getApplicationContext(), org.iustb.knowledebase.animation.transparent.MainTransparentActivity.class);
The suggestions to solve this problem on the web is that adding or android:exported="true" to the target activity in the AndroidManifest, but it doesn't work.
Is there anybody can help me?
i wrote the below code:
Intent intent = new Intent();
intent.setClassName(cursor.getString(pIndex), cursor.getString(cIndex));
startActivity(intent);
manifest file settings of the target activity:
<activity android:name="org.iustb.knowledebase.animation.transparent.MainTransparentActivity"
android:exported="true"></activity>
Did you make sure the values that the cursor returns the are correct ones?
The first parameter of the setClassName() should be the application package name, not the package where the Activity beings started is.
Assume the application package is: com.testandroid, but you want to start the other activity from the com.testandroid.other package, then your code should look like this:
intent.setClassName("com.testandroid", "com.testandroid.other.OtherActivity");
in my case it was a conflict between package=com.example.myApplication in the AndroidManifest.xml file under the <manifest> tag and applicationId in the build.gradle:app module under the defaultConfig tag. hope it would help.

Android NoClassDefFoundError when create intent

I got a NoClassDefFoundError when try to create an intent for a class which inherited from MapActivity.
here is the code where I got the exception: Intent mapTabIntent = new Intent(this, MapTab.class); Where this is the TabActivity
I tired with Android version 2.1 and 2.2 Google APIs.
I put the manifest file outside the application:
I used in manifest the android.permission.INTERNET too.
My application is works perfectly without the MapTab.
I already recreate the MapTab class and maptab layout, the result is same.
What I missed out?
check this question: https://stackoverflow.com/a/5719847/1317080
It seems your problem has to do with the vm not finding the google maps class you inherited from

How to discover intent names within an existing Android application? (specifically Facebook)

I have a Samsung Galaxy Nexus Android phone and for whatever reason the Facebook app's menu UI is missing. This means I cannot get to the Settings screen. I figure I can start the intent from my own app, but how do I find the intent name? I've looked in the APK, but the manifest appears to be compiled into a binary format.
Does anyone know the intent name for the Facebook settings activity?
How can I get a list of the intents in an APK?
----------- Update -----------
The Facebook app's manifest includes:
<manifest android:versionCode="4130"
android:versionName="1.6.3"
package="com.facebook.katana"
xmlns:android="http://schemas.android.com/apk/res/android">
<activity android:label="#string/home_settings"
android:name=".SettingsActivity" />
I've got this in my code:
public void goToFacebookSettings(Context context) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.facebook.katana",
"com.facebook.katana.SettingsActivity");
context.startActivity(intent);
}
But this fails with:
FATAL EXCEPTION: main
java.lang.SecurityException: Permission Denial: starting Intent
{ act=android.intent.action.VIEW cmp=com.facebook.katana/.SettingsActivity }
Is this an inherent limitation, or can I comply with the security requirements in some way?
<activity android:label="#string/home_settings"
android:name=".SettingsActivity" />
This activity doesn't declare any intent-filters. It also doesn't have the android:exported attribute set to true. Which means it can only be launched by the Facebook app or an app that has the same user ID since it's considered for app-internal use only.
See the android:exported attribute documentation for more information.
Since this is for your personal use, you might be able to edit that attribute into the manifest and rebuild the application (also using apktool).
AFAIR you can use explicit activity invocation only inside of your apk - no way to call externally something that is not advertised.

Using an Android library project Activity within another project

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);

Android Error Cant Use FLAG_RECEIVER_BOOT_UPGRADE here

I am trying to start AppB from AppA. On activity of AppB I issue:
Intent i = new Intent();
i.setAction("START_APPB");
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.sendBroadcast(i)
Inside AppB I have a broadcast receiver that is listening on START_APPB intent filter.
as follows:
Intent i = new Intent();
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setAction("SHOW_APPBPAGE");
context.startActivity(i);
Note in each case context is the activities context of the respective app.
This causes a crash error from activity manager:
IllegalArgumentException: Can't use FLAG_RECEIVER_BOOT_UPGRADE here
I have never seen this error before. When i have sent same message from first activity of App it runs without error, but somehow not on 3rd page , using context of third page.
Do not use any FLAG_ACTIVITY_ constant with sendBroadcast().
When populating your Intent, do:
intent.setFlags(0);
I ran into this and found out that this is a bug in android. At some point in history this two flags - FLAG_ACTIVITY_NEW_TASK and FLAG_RECEIVER_BOOT_UPGRADE - get the same numeric value because some android developer changed one of their values without checking that it is already taken by another flag. The latest version (4.4) seems to have it fixed already.

Categories

Resources