Exception when open Android N shortcuts - android

I am trying to implement Android N shortcuts but it crashes with an exception
android.content.ActivityNotFoundException: Shortcut could not be started. I believe its because I am not giving the correct targetPackageName in shortcuts.xml
I am not really sure what it should be pointing to if the application itself is in a different module and the activity I am trying to start is in a different module.
Any help is appreciated.

I had a similar problem recently. For me, the issue was that the Activity I was trying to launch only had an intent-filter for the LAUNCHER category. Once I created a separate intent filter that had category DEFAULT (ie, category android:name="android.intent.category.DEFAULT"), everything worked fine.
Note that if you're trying to use activities from different modules, it may be more flexible to use implicit intents. While your original approach will still work just fine, you may want to consider moving to using action constants instead of referring to the package name.
If that doesn't fix your problem, can you post your manifest and your shortcuts.xml?

Be sure TargetPackageName is Correct. Use package name where activity exist.
Use ActivityName like this:
android:targetClass="com.example.logs.ExampleActivity"
Use Package like this:
android:targetPackage="com.example.logs"
I Hope this works!!!

Related

android: allow creation of an activity-alias whose targetActivity is in an aar/sdk

I'm writing an SDK and would like developers to be able to create an activity-alias whose targetActivity is set to an activity inside my SDK. I'm doing this because I'd like them to be able to customize the intent filter on a specific activity in the SDK. If in the sdk's manifest there is ActivityX, I'd like them to be able to write an activity-alias like this in their app's manifest:
<activity-alias
android:name="abc"
android:targetActivity="ActivityX">
<intent-filter>
... user's custom intent filter
</intent-filter>
</activity-alias>
The problem I'm coming across is that the targetActivity has the restriction that it:
"... must match the name attribute of an activity element that
precedes the alias in the manifest."
This is a problem because no matter where I place the activity in the sdk's manifest or where I place the alias in an example app's manifest, the alias always comes before the activity in the final merged manifest causing an INSTALL_PARSE_FAILED_MANIFEST_MALFORMED error.
One idea is to put an alias without an intent filter just after ActivityX is declared in the sdk manifest and hope that the two aliases will be merged together and stay in the sdk alias's position. But I can't figure out how to do that. One reason that might not be working is that two aliases may not be able to conflict.
Do you have thoughts on solving this via a merge solution or some other technique?
An identical issue was brought up in the AOSP. A workaround to the problem is described there as follows:
Manually include the manifest entry for the Activity from [the sdk] in
the manifest of the application project, placing it before the
activity-alias entry.
Despite the fact that this workaround has the problem of
... duplicate code across manifests.
it seems that the project maintainers deemed this solution as adequate. There is no indication that a fix to the underlying problem will be released any time soon.

How to call an apk from another app without having its source code

I am developing a app in which i want to call another app apk but i don't have the code of that app so i don't know the package name and class name.i have searched alot but couldn't find anything that works. does anyone know how to do this?
It is perfectly possible. You don't need to know its "source code", you need to do a bit of research on the app and you're probably going to find its package's name.
You can:
a) Try to de-pack the .apk which is extremely tedious (or was last time I tried)
b) Write a very simple app that will list all of your installed apps (by package name)
c) Some custom and even stock firmwares even have that option baked in when you go to Apps/Installed/All or something similar to that.
Once you have the package name. For example, com.adobe.reader for...well...Adobe Reader, then you can launch the app really simply by using an Intent.
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);
For a similar, but maybe clearer for you view of things, you can check out this link:
Open another application from your own (intent)

In an AndroidManfiest.xml file, what is the impact of renaming/moving/removing activities?

Many/most of the settings in AndroidManifest.xml have a public impact. Changing the package name changes the identity of the app in the store. Changing uses-permission changes the list of permissions and may prevent automatic updates, etc.
What is the impact of removing or renaming a non-MAIN activity? For that matter, what is the impact of renaming the MAIN activity? Given that the intent-filter is used to mark it main I'm not sure why changes to the name or package of the MAIN activity would matter.
It's apparently necessary that all activity classes be declared here, so I want to know if I'll cause some sort of public effect simply by refactoring an activity so it has a different name or package.
The developer page for AndroidManifest.xml doesn't get into public consequences of changes. Can someone point me to a page describing the impacts of various changes to this file?
You can take a look at an official blog post by the Android team here: Things That Cannot Change.
If you refactor the name of your refactor the name of some Activity, either in the Manifest or in your class, obviously both the manifest and the class have to match, otherwise you'll get errors. But, in terms of your app in the Marketplace, refactor class names has zero effect.

Android emulator shows error when 2 apps with the same activity name

I have 2 projects in my Eclipse. Both of them have a activity called "MainActivity". The weird thing is, when I tried to launch the 2nd app, the emulator showed an error and pointed it to the 1st app. I can bypass this problem by changing the activity name to something different. Then everything will be fine.
I suppose this is only a emulator problem. I haven't tested it yet but I cannot image this happening on real devices, which will make Android totally unusable.
But still, I need to use the emulator and I'd like to keep the name MainActivity. Has anyone has the same experience before? Thanks in advance.
Do you also have the same package name?
Applications are distinguished by their package names so you should change those on per-project basis.
Update:
In manifest package attribute is prepended to name attribute of Activity. Combined they must be the same as your full qualified class name.
<manifest package="com.myapp">
<activity android:name=".MyActivity"/>
</manifest>

SingleLaunchActivityTestCase cannot launch activity on test

I'm new in android testing. All I've used in the testing is only the ActivityInstrumentationTestCase2 (AITC2) which is explained in the Hello, Testing tutorial.
I've made a test class using AITC2 and it runs well. But once I changed the base test class to SingleLaunchActivityTestCase (SLATC) I got RuntimeException specifying "Unable to resolve intent.. blabla.." which I suspect was originated from launchActivity().
I thought AITC2 and SLATC are pretty much the same, besides that in SLATC the activity being tested only launched once (setUp() only launched once for all test cases) and in AITC2 the activity will be launced for every test cases.
I've tried to find some example or documentation about how to use SLATC but still no luck.. :(.
Anybody knows why the activity cannot be launched in SLATC? Thanks in advance :)
Solved it. I put a wrong package string in the constructor because I have several different subpackages in my project.
I put [package].activity, it should be only [package].
Kind of weird answering my own question, but just in case someone looking for an answer from the same mistake as mine.

Categories

Resources