Starting a no launcher activity from another package - android

I try to start an activity from another package, but it has not LAUNCHER category
Intent i = new Intent();
i.setComponent(new ComponentName(maxVerPackageName, maxVerClassName));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
I faced the Exception: "An exception occurred: java.lang.SecurityException"
what's wrong, please help?

The other activity is enforcing a permission. So that only apps that have the permission or same uid can launch the activity.
Edit: If you have written other app
then add this attribute to the other activity which you are trying to launch
android:exported="true"

Related

Launching An External Shortcut

I'm trying to launch an external shortcut, What i have is only the activity path .
Here's what i did :
try {
view.getContext().startActivity(Intent.getIntentOld(List.getShortcutPath());
} catch (URISyntaxException e) {
e.printStackTrace();
}
Log :
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=com.sonyericsson.music.ArtistShortcutActivity }
The Path I'm trying to launch :
com.sonyericsson.music.ArtistShortcutActivity
How to launch the shortcut ?
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.example", "com.example.MyExampleActivity"));
startActivity(intent);
if you get permission denial error, then add android:exported XML attribute is true in the manifest for the activity you want to launch
Here com.example is the package name of the app your activity that you want to launch is in, and com.example.myexampleactivity the full name of the activity you want to launch
If the intended activity to launch is package private, then you wont be able to launch it from a foreign application activity. This is done for security reasons by Google

How to find out the reason why Activity doesn't start

I got log cat message from startAnotherActivity() method
private void startAnotherActivity() {
Log.i(TAG, "Entered startAnotherActivity()");
Intent intent = new Intent();
intent.setAction(ANOTHER_ACTIVITY);
intent.addCategory("android.intent.category.DEFAULT");
startActivity(intent);
}
Another activity doesn't start, no other messages in log cat.
How can I resolve this issue?
UPDATE#1:
Sorry, I forgot to mention that AnotherActivity is an Activity in the other application, and therefore ANOTHER_ACTIVITY == 'some.other.app.domain.ANOTHER_ACTIVITY'
Shouldn't Dalvik complain if it cannot find specified activity?
One possible reason may be not declaring other activity in the manifest. You can do this like the following:
<activity android:name="your.package.your.activity">
</activity>
And then you can start the activity by doing the following:
Intent intent = new Intent(CurrentActivity.this, NewActivity.class);
startActivity(intent);
Hope this helps.
Since it's an activity in another application, you may need to set the component (fully qualified package name and fully qualified activity name).
See here: How to start activity in another application?
Or here:
Launch an application from another application on Android
Finally I found out my mistake.
In the project there are two similar messages in two activities, so I thought that runs one, but that was another.
Thank you for your assistance!

How to open an activity of one application inside another application

I want to open an activity of one application inside another application
for that I am doing
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.settings",
"com.android.settings.audiopreferences.SystemAudioSettings"));
context.startActivity(intent);
if i execute above Im getting the below Exception
id=1: thread exiting with uncaught exception (group=0x40fac930)
E/AndroidRuntime( 2741): FATAL EXCEPTION: main
E/AndroidRuntime( 2741): java.lang.SecurityException: Permission Denial: starting Intent { cmp=com.android.settings/.audiopreferences.SystemAudioSettings } from ProcessRecord{414c0b58 2741:com.dea600.radioapp/u0a10071} (pid=2741, uid=10071) not exported from uid 1000
E/AndroidRuntime
android:exported="true"; // Have to include it in the manifest file - activity to be used across multiple applications
Example
<activity
android:name="com.example1.utility.MainActivity"
android:exported="true"
android:label="#string/app_name" />
Using MAinActivity from Another application
Intent intent = new Intent();
intent.setClassName("com.example.utility", "com.example1.utility.MainActivity");
context.startActivity(intent3);
You're trying to open a settings activity from the system. You'll have a better chance of using the actual "action" for that activity.
Try
context.startActivity(new Intent("android.settings.SOUND_SETTINGS"));
Try this
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);

Android Starting an Activity from different project

I have 2 projects in Eclipse. When I click on a button in project1, I want it to launch an activity from project2.
how can I do that ?
i tried the following code
Intent intent = new Intent(this,com.project2.tp02.MainActivity.class);
intent.setClassName("com.project2.tp02", "com.project2.tp02.MainActivity.class");
startActivity(intent);
I get an error message telling that first application stopped. How can I lauch it properly without such error?
Thanks in advance to any helper.
I got it work using this :
Intent intent = new Intent();
String pkg ="com.project2.tp02";
String clazz =pkg + ".MainActivity";
intent.setComponent(new ComponentName(pkg, clazz));
startActivity(intent);
I don't understand why that way it works and not previous one, if someone can explain I will be thankfull, but anyway I got my problem solved that way.
This is working code to invoke an activity which is in another project.
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.my.package", "com.my.package.MyClass"));
startActivity(intent);
I think your first code did not work because you provide your current activity as context of invoked activity where it is in another application.
<intent-filter>
<action android:name="com.project2.tp02.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Adding the above lines in the Manifest of your first activity might solve your problem.
It would be interesting what the error message is saying exactly... you do need the intent-filter as described by Swayam on the activity you want to call.
Try
new Intent("com.project2.tp02.MainActivity");
to get the intent, instead of setting the class name.

Starting another application from broadcast receiver

I am trying to start an activity from a Receiver after the device boot:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(ComponentName.unflattenFromString("other.apps.package.name/.ActivityName"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(intent);
This code just works fine when I call it from my activity however it fails when my BroadcastReceiver executes it after bootup. My Logcat shows:
ActivityNotFoundException: Have you declared the activity in your AndroidManifest.xml?
Any pointers will be greatly appreciated. Thanks in advance.
Intent intent = new Intent(context, activity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
i think this 3 lines only needed and the context will be the context u receive in broadcast receiver.
You probably spelled or made a error when you declared your Activity in your manifest. Make sure you put it in there and spelled everything correctly
I think the problem is in the following Line.what is the name of your Activity?is it "ActivityName"?Also Check package name.
intent.setComponent(ComponentName.unflattenFromString("other.apps.package.name/.ActivityName"))

Categories

Resources