I am trying to import android.hardware.camera2.*; to my project but android studio cant find it. It only shows android.hardware.Camera and android.graphics.Camera. My compile sdk version is also 23 so I don't know how to fix this.
That is because there is no Java class in Android named android.hardware.Camera2. There is a Java package named android.hardware.camera2. You are welcome to use classes out of that Java package, such as android.hardware.camera2.CameraManager, via import statements like:
import android.hardware.camera2.CameraManager;
Related
I'm learning Notifications.
There is a sample project user-interface-samples, I find many files in the project exists Code A.
But the artical tell me "NotificationCompat is obsolete", please see Image A
1: Code A use latest androidx namesapce, why is it obsolete?
2: Is there a sample project about Notifications based AndroidX which is part of Jetpack.
Code A
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationCompat.BigTextStyle;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.content.ContextCompat;
Image A
You're looking at the documentation for android.support.v4.app.NotificationCompat, part of the pre-AndroidX Support Libraries. That class is deprecated, but you aren't using that version, so the documentation there is irrelevant.
The AndroidX equivalent, androidx.core.app.NotificationCompat is not deprecated.
Using the "Optimize Imports" in Android Studio 3.4.1, the imports are ordered similar to this:
import com.walla.walla
import com.willy.willy
import org.koin.android.ext.android.get
import org.koin.androidx.viewmodel.ext.android.viewModel
import kotlin.concurrent.thread // <-- note this line
import kotlin.random.Random
As you can see above, function (a.k.a. "static" import in Java) imports like kotlin.concurrent.thread and kotlin.random.Random are put under other imports.
It is not consistent with the Android Kotlin style guide:
Import statements for classes, functions, and properties are grouped together in a single list and ASCII sorted.
I couldn't find a way to make it such that Android Studio order imports irrespective of whether the import is a class or a function. Is there an option to make it so?
This seems to be a misunderstanding. In fact, kotlin.concurrent.thread is a function. Therefore, it should be grouped together with the other classes.
UPDATE: I do see that the latest version of IntelliJ 2019.1 (and Android Studio) might not be able to conform to the Android Kotlin style guide. If you have these import statements, then IntelliJ does not sort strictly by ASCII:
import org.apache.commons.lang3.StringUtils
import java.util.Base64
import kotlin.concurrent.thread
Instead, IntelliJ orders them as:
Third-party
Java
Kotlin
I do not see a way to configure IntelliJ or Android Studio to sort them this way:
import java.util.Base64
import kotlin.concurrent.thread
import org.apache.commons.lang3.StringUtils
Perhaps you should submit some feedback to IntelliJ or the authors of the Android Kotlin style guide.
I am trying to build a FM Radio kind of application and I cloned this Google Respository for the reference.
However There are few classes in the imports which are missing in android sdk. I tried changing compileSdkVersion from 18 to 24 but android.jar seems to be missing these Following imports:
import android.media.AudioManager.OnAudioFocusChangeListener;
import android.media.AudioManager.OnAudioPortUpdateListener;
import android.media.AudioMixPort;
import android.media.AudioPatch;
import android.media.AudioPort;
import android.media.AudioPortConfig;
import android.media.AudioDevicePort;
import android.media.AudioDevicePortConfig;
Where exactly are these classes and how can i import them ?
The Strange thing about them is they are present as .java files in sources/android-xx but not in actual .jar file.
The sample is showing errors and I am not able to proceed. Please guide me how to resolve this issue.
You can see from the Android source code that these classes are "hidden" from the jar using the "pseudo-annotation":
/* #hide */
For example, see here and here.
This annotation controls what will appear in the runtime Android.jar.
Note, sometimes these hidden classes are later included as part of the official SDK.
Refer to:
https://commonsware.com/blog/2018/01/18/think-hard-about-hide.html
What does #hide mean in the Android source code?
What exactly does Android's #hide annotation do?
I am trying to use the class BluetoothAvrcp from the package android.bluetooth but the import fails. It can't seem to file the class.
import android.bluetooth.BluetoothAvrcp;
Is there anything that I need to add before being able to use that one?
SDK 22.
Thank you.
It happens that these classes requires to build the android rom from the source.
Follow the following link to build from the source.
https://source.android.com/source/index.html
I downloaded an Android Project and got some errors.
How can I use this imports in Android?
import com.android.internal.telephony.IccSmsInterfaceManager;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.SMSDispatcher;
When I import this, I got errors like these:
The import com.android.internal.telephony cannot be resolved
The import com.android.internal.telephony cannot be resolved
The import com.android.internal.telephony cannot be resolved
The import com.android.internal.telephony cannot be resolved
Later in the code there are:
Phone phone = PhoneFactory.getDefaultPhone();
With the error:
Multiple markers at this line
- Phone cannot be resolved to a type
- PhoneFactory cannot be resolved
And so on...
I tried to fix it with the https://stackoverflow.com/a/16377968/3203914
but I did not work for me.
Can please someone tell me how to fix it?
Thanks!
How can I use this imports in Android?
Those are not part of the Android SDK. If you are editing the Android source code, the build process for it should resolve those imports. If you are trying to write an Android app, you cannot directly reference them. In fact, com.android suggests they are part of a separate app, not yours and not the Android framework.
CommonsWare is correct, its not in the SDK so you cannot directly reference them. You will either have to
Import all of the android source code, which will resolve these issues
Import the specific project containing this code, then set up your code as a dependency
Stop using those packages