I add new class in the android/packages/apps/phone/src and I want to call the class in the ohter application.
Assume that the new class is SS.java
I added
<activity android:name="SS"></activity>
in the AndroidManifest.xml file in the android/packages/apps/phone folder.
The application which want to call the SS class has a list and I put the code in the xml file;
<PreferenceScreen
android:title="#string/SS">
<intent
android:action="android.intent.action.MAIN"
android:targetPackage="com.android.phone"
android:targetClass="com.android.phone.SS" />
When I choose the menu in the list, the phone show Class Not Found Exception.
The message isUnable to find explicit activity class {com.android.phone/com/android.phone.SS}; ....
Please let mw know what is the problem
Are you talking about contributing to the AOSP or building custom ROMs? If you are, this is not the most relevant forum. Try http://groups.google.com/group/android-contrib?pli=1.
If you are not, then:
The android/packages/apps/phone is a part of special apps shipped with the OS. You can't add classes to this package. Even if you do and compile the AOSP code, no phone will have your classes, so no application can use your classes.
Related
I'm trying to display (as a system-level application) multiple activities. There's an hidden AOSP class called ActivityView meant to do just that. Here's how you would use it, as far as I understand:
findViewById(R.id.view1).setCallback(object: ActivityView.StateCallback() {
override fun onActivityViewReady(view: ActivityView?) {
view?.startActivity(InnerActivity.getIntent(view.context, "my extra"))
}
override fun onActivityViewDestroyed(view: ActivityView?) {
// Cleanup
}
})
Note that the inner activity has to be declared with the attribute allowEmbedded set to true. It is in my case. My application also has the permission android.permission.INJECT_EVENTS (and is built as a system application, with the ROM certificate and installed in /system/priv-app)
Now, for the problem: when I call startActivity, the inner activity is displayed as a new activity on the stack, like any standard Context.startActivity call would do (the ActivityView.startActivity method actually does exactly that, but adds some options to the bundle before that, to display the activity on a virtual display). I also have a system Toast displayed that tells me that my App does not support launch on secondary displays.
In regard to this Toast, I tried giving my application the android.permission.CAPTURE_SECURE_VIDEO_OUTPUT permission, to no help.
I'm probably missing something related to the virtual display, but I can't see what…
(I know ActivityView is hidden, and that actually could be a bug, I'm just being curious of what it can or cannot do.)
I have already used ActivityView successfully on Android 9 (Pie). I noted some key points that you can refer to use ActivityView.
The application which use ActivityView need to be private application (installed in /system/priv-app) and must use system uid (declare in AndroidManifest.xml) as below
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.packagename"
android:sharedUserId="android.uid.system">
Noted that you need to replace "your.packagename" by package name of your application
You need config Android framework to support secondary display by copy file android.software.activities_on_secondary_displays.xml to /system/etc/permissions/
Content of android.software.activities_on_secondary_displays.xml
<?xml version="1.0" encoding="utf-8"?>
<permissions>
<feature name="android.software.activities_on_secondary_displays" />
</permissions>
You should config in makefile to copy this file in building process of Android image from source code using PRODUCT_COPY_FILES
Enable resizeable mode and using singleTask for the Activity need to be placed inside an ActivityView
In AndroidManifest.xml
<activity
android:name=".YourActivity"
android:resizeableActivity="true"
android:launchMode="singleTask">
You must add these two attributes to the Activity tag in your manifest for any activity which should be allowed to be placed inside an ActivityView:
android:resizeableActivity="true"
android:allowEmbedded="true"
As you know, this is not documented, since ActivityView is not part of the Android SDK.
In my case I was using Flutter and its PlatformView API to display ActivityView as a widget. Unfortunately, both ActivityView and PlatformView are using virtual displays as the underlaying technology, and maybe it's not possible to show one virtual display inside another.
TLDR:
I have to extend the application class but don't know where to start.
Ok... I know this is a dumb one but I have to ask it.
I need to install LeakCanary and I see in their documentation that it requires me to put code in the Application Class.
I understand how to make a java class that extends the application class, but I have some questions before I do this.
SITUATION:
I have 9 classes in my app already.
The entry point to my app is MainActivity.class (figures, right?)
I have not had to extend the Application Class yet.
App name is "CST-ALERT"
QUESTIONS:
Do I just create a new Java class in my java source folder and name it the same as my overall
package name? What do I name this new class?
Do I need to adjust the manifest now to have this as the entry point
instead of MainActivity? Which I imagine will change things quite a
bit for me.
Do I have to change anything else in the manifest? I assume I will
at least have to declare it in there.
Hopefully my situation and questions will give you an idea of what I am asking.
Do I just create a new Java class in my java source folder
Yes.
and name it the same as my overall package name?
If by "it", you mean the Java package, you already have a directory for your existing Java code. Put your subclass of Application in there, unless you have a clear reason not to.
In this trivial sample app, I put my Application subclass in the same directory as my launcher Activity, which is the directory for my Java package (com.commonsware.android.button).
What do I name this new class?
That is up to you. I called it CanaryApplication. If you think you leak a lot, call it CoalMine. So long as it is a legal Java class name, it doesn't matter.
Do I need to adjust the manifest now to have this as the entry point instead of MainActivity?
Um, well, I wouldn't describe MainActivity as the entry point. Regardless, MainActivity is left alone. You need to add an android:name attribute to the <application> element, identifying your Application subclass.
Do I have to change anything else in the manifest?
No, that should suffice.
I am busy reading up of fully qualified names and packets etc,
In my project I have broken everything up into packages just to try and organize my project, but I have now realized this doesn't quite fit with the android manifest element as you can only provide one package?
Can I have multiple packages in my project like so?
You should specify a main package, and that package may have as many sub-packages as you like:
com.example.android could be a main package.
then you could specifiy the following:
com.example.android.activities
com.example.android.adapters
etc...
Of course, you may add classes to the 'root package' too without any hassle.
Check out Java package naming conventions for more info, Android follows these conventions as well.
You have to Specify a common package name for your application. eg:com.example.rhino68mobileapp and start every other packages by using this eg:com.example.rhino68mobileapp.utils
Yes you can use the multiple package in android, Only you have to play with access modifiers within your application, so that your one package class or object can communicate with other package class when desired.
Java provide different access modifiers:
Visible to the package. the default. No modifiers are needed.
Visible to the class only (private).
Visible to the world (public).
Visible to the package and all subclasses (protected).
For more read here
Edited:
You can define the main package(Application main package) and other package into your manifest like this:
<manifest package="com.example.mainPackage">
<application . . .>
<activity android:name=".packageOne.ActivityOne" . . . />
<activity android:name=".packageTwo.ActivityTwo" . . . />
<activity android:name=".packageThree.ActivityThree" . . . />
</application>
</manifest>
Yes you can.
The application package from the AndroidManifest.xml identifies your app.
But your Java code can be organized as you please.
I have a project (in Eclipse) which I've turned into an Android Project Library so as to re-use some of the code in another similar project. I think I've shot myself in the foot however as I'm getting the error:
Unable to start activity ComponentInfo{com.test.scroller1/com.lib.scrolltest.ScrollTestActivity}: java.lang.ClassCastException: android.app.Application cannot be cast to com.lib.scrolltest.resAppVars
com.lib.scrolltest is my Project Library which instantiates a class extending Application (resAppVars). In the onCreate() method I call:
mRav = (resAppVars) getApplicationContext ();
This way, I can use methods in the mRav object which would otherwise be a lot of duplicated code in other classes (such as passing a query to a generic select statement which returns an ArrayList of results).
What's the problem here? It seems I've hit a limitation in the way I've implemented the Application class.
Calling getApplicationContext() returns the Application object for the current application (i.e. the application that owns the activity that onCreate() is running inside of).
Unless you're doing something strange, you don't get to pick which Application class is used. There's even a note in the documentation for Application saying not to do this:
There is normally no need to subclass Application. In most situation,
static singletons can provide the same functionality in a more modular
way. If your singleton needs a global context (for example to register
broadcast receivers), the function to retrieve it can be given a
Context which internally uses Context.getApplicationContext() when
first constructing the singleton.
You should just create a regular shared class inside of your library project. Or if you don't have a need for the special functionality library projects offer, you can also just use a regular .jar file.
And if you need shared state, just make it a singleton. ;)
Although this is a very old post. I encountered the same problem and solved it. So I thought I'll post the solution for everyone.
It turns out that I forgot to declare the subclassed application name in the manifest file.
The android:name should point to the extended app class, even if it is defined in the referenced library.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name="com.example.lib.MyApp">
After I added that I could use the extended app with (<cast>) getApplication() anywhere in my project.
I'm porting an application to SDK 3.0.
I have already modified the Settings to use the new Fragment feature available in PreferenceActivity.
The problem I have now is that the following configuration I had in the settings.xml does not work any more:
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="#string/mykey"
android:summary="#string/musummary"
android:title="#string/mytitle" >
<intent
android:action="android.intent.action.MAIN"
android:targetClass="com.android.settings.WirelessSettings"
android:targetPackage="com.android.settings" />
</PreferenceScreen>
com.android.settings.WirelessSettings is not found. Do you know why?
My first guess is that now that activity does not exist any more and was replaced by a fragment.
The problem is that I can't find how to call this fragment.
Do you know how to embed the standard WirelessSettings Fragment in my application?
Thank you
OK finally I found the correct version. This works:
<intent
android:action="android.settings.WIRELESS_SETTINGS"/>
com.android.settings.WirelessSettings is not found. Do you know why?
They either elected to rename the class or make it be not exported. You should not have been using this in the first place -- any references to com.android are a really bad idea, as they are not part of the Android SDK.
Do you know how to embed the standard WirelessSettings Fragment in my application?
You can't embed fragments from other applications in your own application.
I have also tried: with that intent I get: android.content.ActivityNotFoundException: No Activity found to handle Intent {...
I can tell you that this works on a XOOM:
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
Your action string is wrong -- replace settings.Settings with just Settings. Try that and see if it helps. If not, perhaps there is something peculiar about using <intent> in preference XML -- I've never used it. Regardless, Settings.ACTION_WIFI_SETTINGS is the proper way to refer to this particular portion of Settings.