Android HTC Hero not reporting back correct FeatureInfo - java

I'm having a strange problem with my HTC Hero 2.1
model=HERO200
manufacturer=HTC
APILevel=7
It is not reporting back that it has a hardware microphone. Here is my code to check for Features.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Context context = this;
PackageManager pm = context.getPackageManager();
FeatureInfo[] foo = pm.getSystemAvailableFeatures();
for (FeatureInfo bar : foo) {
if (bar.name != null) {
System.out.println(bar.toString());
if (bar.name.equalsIgnoreCase("android.hardware.microphone"))
System.out.println("Booyah!");
}
}
}
It does report back these features:
android.hardware.camera
android.hardware.wifi
android.hardware.location.network
android.hardware.bluetooth
android.hardware.sensor.light
android.hardware.location
android.hardware.location.gps
android.hardware.camera.autofocus
android.hardware.touchscreen.multitouch
android.hardware.touchscreen
android.hardware.sensor.accelerometer
android.hardware.sensor.compass
Some are API Level 8 like compass and gps, and others are level 7. Is there another way I can search for features? Something else I can use besides getSystemAvailableFeatures()? Maybe a lower level system call? Why is my phone not reporting back that it has a hardware microphone? Help please :) Thanks!

I guess if this phone is set for Android API Level 7... then I just can't set a requirement that was designed for API Level 8 (Like microphone).
This is the proper way to request features of the phone from Android.
So... this sucks... oh well. But still weird that this phone does report back some features from API Level 8, but you shouldn't rely upon that.

Related

SpeechRecognizerListener giving Bundle[EMPTY_PARCEL] in onResults(Bundle results) majority devices which have android 11

I am Using
speech = SpeechRecognizer.createSpeechRecognizer(getReactApplicationContext().getApplicationContext());
speech.setRecognitionListener(VoiceAppModule.this);
recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 100000000);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.languageacademy");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 10000);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, 10000);
The Above code for Speech recognition.
#Override
public void onResults(Bundle results) {
in about On Result the result is giving Bundle[EMPTY_PARCEL] in Result.
ArrayList matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
I tried in many of the Devices it is mainly giving problem in MI phones having android 11 and also some samsung phones.
Same problem here, this bug started to occur like few days ago.
I think the reason of this bug is the new version of "Google"
app (https://play.google.com/store/apps/details?id=com.google.android.googlequicksearchbox), as SpeechRecognizer uses this app to recognize voice.
If you click uinstall "Google"
app, it will roll back to older version and onResult callback will work fine.
Solution that fixed my problem was removing:
EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS extras
Note that it is extremely rare you'd want to specify this value in an intent. Generally, it should be specified only when it is also used as the value for EXTRA_SEGMENTED_SESSION to enable segmented session mode. Note also that certain values may cause undesired or unexpected results - use judiciously!
https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SEGMENTED_SESSION
I confirm the answer gave by Seba, only in my case I have to remove also
RecognizerIntent.EXTRA_MAX_RESULTS RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS
and affected also Huawei and Samsung devices with Android 9, so it seems the issues's propagating day by day.
I was also facing the same issue. After removing the below intent it started working.
putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 3000)
Previous intent :
recognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en")
putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, packageName)
putExtra(
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH
)
putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 3000)
putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1)
}
Modified Intent:
recognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en")
putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, packageName)
putExtra(
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH
)
putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1)
}

Record a call through MIC on Samsung devices (Android 7.0)

I've simple Android app that record a call and it works fine on Android 6 + Samsung devices (both with MIC source and VOICE_COMMUNICATION). But once Samsung devices updated to Nougat (for ex. S7 / S7 Edge) these methods to record a call failed :( MIC record only my voice but not opponent voice and VOICE_COMMUNICATION does not works at all.
Could anybody advice what can be done here?
same problem.
still looking for the answer.
I've got a samsung s7. Firstly, I'v unlocked native recorder (in dialer) and it's works.
So, android 7 (and samsung) can record calls without inner actions inside of Android.
But, in the same time I've read that developers can't get the access to recording calls from higher level.
It seems like there's only one way to achieve our goals: modification of stock Android's version or catch sound stream before it gets to speaker.
Fix me if I wrong.
Normally for recording phone call, we can use 4 types: DEFAULT, MIC, VOICE_CALL, VOICE_COMMUNICATION. But with 3 types below is enough for all
MIC, VOICE_CALL, VOICE_COMMUNICATION
base on the android version of your phone that will support or don't support some of them.
So to make your app work perfectly with all android versions we should change the AudioSource type following the android version with this rule:
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
callType = "VOICE_CALL";
} else if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
callType = "MIC";
} else {
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
callType = "VOICE_COMMUNICATION";
}
I am using this on my application and it worked on most devices. It's no need to add any C library.
Check my example application to see how they react with a dedicated Android version.
Github: https://github.com/tntkhang/call-recording-master

Citymaps questions on Android studio

I have some new questions in today's citymaps development.
In the Android studio,if I develop the code for citymap, there are always no logs showing but for others that does not happen. Why?
According to the citymaps official website, to create a map instance with CitymapsMapFragment, but in the sample project which citymaps provides, it uses SupportCitymapsMpaFragment ,What is the difference between them?
When the map is loading complete, is it automatically positioning to the current position or some other default position? Where is it?
If I open the GPS location,I can locate to the current position and show a blue arrow quickly, but too much power consumption,are there any other location way like network or base station location?
Code follows:
CitymapsMapFragment fragment = (CitymapsMapFragment)fragmentManager.findFragmentById(R.id.map);
if (fragment != null) {
fragment.setMapViewListener(this);
}
I did not find the fragment have the method setMapViewListener but setMapViewReadyListener,does it right?
Other code:
CitymapsMapView mapView = new CitymapsMapView(this, options, this);
When I add animate in additional methods like this:
mapView.setMapPosition(position, 300, new MapViewAnimationListener() {
#Override
public void onAnimationEnd(boolean completed) {
Log.d("SomeApp", "Move Complete!");
}
});
the project fails and exits,I tried to surround the code with try-catch block to catch exception for purpose, but nothing shows in logcat view. Why?
I am developer on the Citymaps project. I will do my best to answer all your questions
1) If you are not receiving log statements, this is likely an issue with your own application, IDE, or device configuration. In our own application, which uses the Citymaps SDK, we have no issues with logging.
2) Prior to using the Citymaps SDK, it is highly advisable that you familiarize yourself with fragments, but the short version is that SupportCitymapsMapFragment extends from the Fragment class in the v4 support library.
3) It is up to you to set the default position the map.
4) If you create a class which implements from the LocationSource interface, and then call mapView.setLocationSource, you can modify the behaviors of the map's location services. For an example, have a look at CitymapsLocationSource.java, which is the default implementation for this interface used by the SDK.
As for the exception you are having, you have not provided nearly enough information. Please show a stack trace, and I may be able to help.
Thank you for using our SDK, feel free to post again with any more questions.

Get User Android Version

is there any way for my application to get the user's Android Version or API Level ? .. because i am working on an app that supports API 9 (2.3 Gingerbread) .. and since API 9 does not support DialogFragments even with android.support.v4.app.DialogFragment imported, i decided to do an if else statement instead
if (the users Android Version is Lower than API 11)
{
i will show a new class instead of a Dialog Fragment containing all information about the developer
}
else if (the users Android Version is Higher than or equal to API 11)
{
my dialog fragment will show up containing all information about the developer
}
i hope anyone can help me out about this, thanks :)
Use Build.VERSION.SDK_INT to get the API level. You can then compare it against values in Build.VERSION_CODES:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// do something cool
}
Standard how to execute code for different versions.
Android provides a unique code for each platform version in the Build constants class. Use these codes within your app to build conditions that ensure the code that depends on higher API levels is executed only when those APIs are available on the system.
#SuppressWarnings("deprecation")
// We use the new method when supported
#SuppressLint("NewApi")
// We check which build version we are using.
#Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
mapView.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
} else {
mapView.getViewTreeObserver()
.removeOnGlobalLayoutListener(this);
}
Try this:
Build.VERSTION.RELEASE
http://developer.android.com/reference/android/os/Build.VERSION.html

How to support multiple android version in your code?

Take accessing contacts in android
android.jar for versions 1.6 has People.CONTENT_URI for invoking contacts related info whereas in later versions we need to have api support for RawContacts.CONTENT_URI.
Same thing is true for accessing calendar for instance as its URI is changed in android 2.2.
Is there a best practice to manage all different changes without adding additional application or build separately for each version of changes?
For my money, a very good answer is at http://android-developers.blogspot.co.uk/2010/07/how-to-have-your-cupcake-and-eat-it-too.html. However, the example there is a little more complicated than need be, so based on that, here is an example of how to cope with it when building notifications. The underlying reason this works is a consequence of how java engines interpret classes: it only looks at them when needed, so if you wrap version specific code up in a class and only create it when you know you are using that version, it all works ...
There are, as far as I can tell, two generations of approaches to creating notification, and a naming change along the way in the second. So that gives three ways to do it. For each way, create a class with the notification generation in it:
The first approach (used through to Gingerbread):
public class MyNotificationBuilderToGingerBread {
Notification notification = null;
MyNotificationBuilderToGingerBread(Context myContext, int icon, String ticker, String title, String info, Long timeStamp, PendingIntent pendingIntent, int flags) {
notification = new Notification(R.drawable.ic_sb, ticker, timeStamp);
notification.setLatestEventInfo(myContext, title, info, pendingIntent);
notification.flags |= flags;
}
Notification get() {
return notification;
}
}
The second approach, Honeycomb to IceCreamSandwich:
public class MyNotificationBuilderHoneyCombToIceCreamSandwich {
Notification.Builder mb = null;
MyNotificationBuilderHoneyCombToIceCreamSandwich(Context myContext, int icon, String ticker, String title, String info, Long timeStamp, PendingIntent pendingIntent, boolean onGoing) {
mb = new Notification.Builder(myContext);
mb.setSmallIcon(icon);
mb.setContentIntent(pendingIntent);
mb.setContentTitle(title);
mb.setContentText(info);
mb.setWhen(timeStamp);
if (ticker != null) mb.setTicker(ticker);
mb.setOngoing(onGoing);
}
Notification get() {
return mb.getNotification();
}
}
The second generation, with the name change, Jellybean (onwards, so far ...):
public class MyNotificationBuilderJellyBean {
Notification.Builder mb = null;
MyNotificationBuilderJellyBean(Context myContext, int icon, String ticker, String title, String info, Long timeStamp, PendingIntent pendingIntent, boolean onGoing) {
mb = new Notification.Builder(myContext);
mb.setSmallIcon(icon);
mb.setContentIntent(pendingIntent);
mb.setContentTitle(title);
mb.setContentText(info);
mb.setWhen(timeStamp);
if (ticker != null) mb.setTicker(ticker);
mb.setOngoing(onGoing);
}
Notification get() {
return mb.build();
}
}
Then, you just need to pick which class to instantiate on the fly:
// System information
private final int sdkVersion = Build.VERSION.SDK_INT;
// If you want to go really old:
// (actually, there is a question about how this issue should be handled
// systematically. Suggestions welcome.)
// final int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
// This is for a permanent notification. Change the final argument (flags or boolean) if it isn't meant ot be
// For meaning of other variable, see notification documentation on the android website.
if (sdkVersion < Build.VERSION_CODES.HONEYCOMB) {
MyNotificationBuilderToGingerBread mnb = new MyNotificationBuilderToGingerBread(myContext, R.drawable.notification_icon, ticketText, title, infoText, timeStampMillis, pendingIntentForTapOnFullNotitifcation, Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR);
notification = mnb.get();
}
else if (sdkVersion < Build.VERSION_CODES.JELLY_BEAN) {
MyNotificationBuilderHoneyCombToIceCreamSandwich mnb = new MyNotificationBuilderHoneyCombToIceCreamSandwich(myContext, R.drawable.notification_icon, ticketText, title, infoText, timeStampMillis, pendingIntentForTapOnFullNotitifcation, true);
notification = mnb.get();
}
else {
MyNotificationBuilderJellyBean mnb = new MyNotificationBuilderJellyBean(myContext, R.drawable.notification_icon, ticketText, title, infoText, timeStampMillis, pendingIntentForTapOnFullNotitifcation, true);
notification = mnb.get();
}
// Send the notification.
notificationManager.notify(idForNotificationManager, notification);
Hope this helps!
There are many resources for you to utilize to help support multiple versions of android.
Read this blog post here and
then read this one here, they
will help you address API level
version support issues.
Read this blog post on multiple
screen support, especially how the
asset hierarchy in parsed in res
folder. This will help you
understand and design how to do
asset folder structure to support
different screen size/densities and
android versions.
Lastly write your own custom ant build
scripts so that you can compile with
all versions of android.
Quite Honestly, it's a pain.
I usually, just isolate parts of code that are different and access them using abstract classes. So technically creating different version for different OS.
But there are other ways. The best one i've seen involves using reflection.
If you don't really need the new functionnalities, and really have to support old Android versions, drop it. Build your app for the oldest version, and don't bother with this kind of thing.
In the other case, you can detect the version using Build, and use reflection to load the classes you need. An example of that can be found in the source code of the K9Mail app
There's a nice article on android.com about it:
http://developer.android.com/resources/articles/backward-compatibility.html
Personally I would suggest the wrapper class or wrapper library solution. But in small cases the reflection should be fine (and in case performance is not a problem for you).
If you need more info, ask in comments.
This is a great article for when you have to do reflection in Android (to support multiple API levels).
And when you have to have different resources for different API Levels, this is the reference to use (see the section on "Platform Version (API level)").
If on Eclipse, from ADT version 17 you can specify code to run with some version simply as described in Lint API Check.
The code word is #TargetAPI(XX)
Hope it helps
Best practice (though not for Android, but for J2ME) to my knowledge is to use preprocessing C/C++ styled statements, like:
//#if S40
...
//#else
...
//#endif
Some IDE's support these kind of preprocessing, e.g. Netbeans. To my knowledge Eclipse has some plugins to enable preprocessing also. I don't really know are they applicable to Android development. Try to google yourself.

Categories