I want to make glass application with offline voice recognition with no ok glass
what I want to know is changing ok glass to other words ( something like "start").
I saw the source decompiled GlassHome.apk and GlassVoice.apk.
I knew that setting to ok glass is related with VoiceInputHelper, voice_label_ok_glass in String.xml
so I tried to change all of string "ok glass" to "nice"(temp guard phrase) in String.xml
but when I said any word (like "hahaha" or "kakaka") , all of word I said is recognized to my guard phrase ("nice") by VoiceService.
what should I do for changing "ok glass" to my guard phrase and working it right ???????
(P.S sorry my bad english. I hope you understand what question means)
here is my code ( I tried to set VoiceConfig to "nice")
public class MainActivity extends GlassActivity implements VoiceListener {
public static final String TEST_SERVICE_EXTRAS_KEY = "serviceExtras";
private ImageView gradientView;
private GuardHintAnimator guardHintAnimator;
private TextView guardPhraseView;
private boolean isRunning = false;
private final FormattingLogger logger = FormattingLoggers.getLogger(this);
private VoiceConfig onWindowFocusChangedRecoverConfig;
private VoiceConfig voiceConfig;
#VisibleForTesting
VoiceInputHelper voiceInputHelper;
private IVoiceMenuDialog voiceMenuDialog;
public FormattingLogger getLogger()
{
return this.logger;
}
public boolean isRunning()
{
return this.isRunning;
}
#Override
protected void onCreateInternal(Bundle bundle) {
super.onCreateInternal(bundle);
this.voiceInputHelper = new VoiceInputHelper(this, new DelegatingVoiceListener(this)
{
public VoiceConfig onVoiceCommand(VoiceCommand paramAnonymousVoiceCommand)
{
if ((!MainActivity.this.hasWindowFocus()) && (!MainActivity.this.isMessageShowing()))
{
MainActivity.this.logger.d("Ignoring voice command because we don't have window focus.", new Object[0]);
return null;
}
Log.d("listener",paramAnonymousVoiceCommand.toString());
//return super.onVoiceCommand(paramAnonymousVoiceCommand);
return null;
}
}, getVoiceServiceExtras());
}
protected void onPauseInternal()
{
this.isRunning = false;
super.onPauseInternal();
closeVoiceMenu();
this.voiceInputHelper.setVoiceConfig(VoiceConfig.OFF);
this.voiceInputHelper.unregisterGrammarLoaders();
}
public void closeVoiceMenu()
{
if (this.voiceMenuDialog != null)
{
this.voiceMenuDialog.dismiss(false);
this.voiceMenuDialog = null;
}
}
public void onPrepareVoiceMenu(VoiceMenuDialog paramVoiceMenuDialog) {}
public boolean onResampledAudioData(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
{
return false;
}
protected void onResumeInternal()
{
this.isRunning = true;
super.onResumeInternal();
this.voiceInputHelper.registerGrammarLoaders();
this.voiceInputHelper.setWantAudioData(shouldProvideAudioData());
NetworkUtil.checkNetwork();
VoiceConfig localVoiceConfig = new VoiceConfig();
String[] arrayOfString = new String[1];
arrayOfString[0] = "nice";
localVoiceConfig = localVoiceConfig.setCustomPhrases(arrayOfString).setShouldSaveAudio(true);
voiceInputHelper.setVoiceConfig(localVoiceConfig);
}
public boolean isVoiceMenuShowing()
{
return (this.voiceMenuDialog != null) && (this.voiceMenuDialog.isShowing());
}
public VoiceConfig onVoiceCommand(VoiceCommand paramVoiceCommand)
{
Log.d("hhh",paramVoiceCommand.toString());
this.logger.w("Unrecognized voice command: %s", new Object[] { paramVoiceCommand });
return null;
}
protected Bundle getVoiceServiceExtras()
{
Bundle localBundle = new Bundle();
/* if (getIntent().hasExtra("serviceExtras"))
{
localBundle.putAll(getIntent().getBundleExtra("serviceExtras"));
}*/
return localBundle;
}
public void setVoiceConfig(VoiceConfig paramVoiceConfig)
{
this.voiceConfig = paramVoiceConfig;
if (paramVoiceConfig != null) {
this.voiceInputHelper.setVoiceConfig(this.voiceConfig);
}
}
public boolean shouldProvideAudioData()
{
return false;
}
public void onVoiceConfigChanged(VoiceConfig paramVoiceConfig, boolean paramBoolean) {}
}
DelegatingVoiceListener :
class DelegatingVoiceListener implements VoiceListener
{
private final VoiceListener delegate;
DelegatingVoiceListener(VoiceListener paramVoiceListener)
{
this.delegate = paramVoiceListener;
}
public FormattingLogger getLogger()
{
return this.delegate.getLogger();
}
public boolean isRunning()
{
return this.delegate.isRunning();
}
public boolean onResampledAudioData(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
{
return this.delegate.onResampledAudioData(paramArrayOfByte, paramInt1, paramInt2);
}
public VoiceConfig onVoiceCommand(VoiceCommand paramVoiceCommand)
{
return this.delegate.onVoiceCommand(paramVoiceCommand);
}
public void onVoiceConfigChanged(VoiceConfig paramVoiceConfig, boolean paramBoolean)
{
this.delegate.onVoiceConfigChanged(paramVoiceConfig, paramBoolean);
}
}
You need to request special permissions in your manifest to implement unlisted voice commands. Go here. However, I doubt you can change the 'ok glass' voice command. You can still try if you really want to.
Related
i know actually a lot of these kinds of questions, and i have searched on google but i can't find where the error is in my code.
I tried to send a request to fetch data, but it runs the onFailure method which reads "NumberFormatException: Empty string" and the data can't be displayed in the recyclerview, even though I'm also getting a json response as I wanted.
i got this response:
{
"kode":1,
"pesan":"Barang ditemukan",
"data":[
{
"Sat_1":"PT",
"Sat_2":"",
"Isi_2":"",
"KdBrg":"280349191",
"NmBrg":"SILICONE PACIFIER STEP 1A",
"Stock_Akhir":"0",
"Hrg":28000
}
]
}
my object model
public class ModelDataBarang {
private int Isi_2;
private int Isi_3;
private int Isi_4;
private String KdBrg;
private String NmBrg;
private String Sat_1;
private String Sat_2;
private String Sat_3;
private String Sat_4;
private String KdHrgList;
private double Stock_Akhir;
private double HrgJl11;
public double getHrgJl11() {
return HrgJl11;
}
public void setHrgJl11(double hrgJl11) {
HrgJl11 = hrgJl11;
}
private String Hrg;
public String getHrg() {
return Hrg;
}
public void setHrg(String hrg) {
Hrg = hrg;
}
public String getKdHrgList() {
return KdHrgList;
}
public void setKdHrgList(String kdHrgList) {
KdHrgList = kdHrgList;
}
public String getSat_3() {
return this.Sat_3;
}
public void setSat_3(String sat_3) {
this.Sat_3 = sat_3;
}
public String getSat_4() {
return this.Sat_4;
}
public void setSat_4(String sat_4) {
this.Sat_4 = sat_4;
}
public int getIsi_3() {
return this.Isi_3;
}
public void setIsi_3(int isi_3) {
this.Isi_3 = isi_3;
}
public int getIsi_4() {
return this.Isi_4;
}
public void setIsi_4(int isi_4) {
this.Isi_4 = isi_4;
}
public String getKdBrg() {
return this.KdBrg;
}
public void setKdBrg(String kdBrg) {
this.KdBrg = kdBrg;
}
public String getNmBrg() {
return this.NmBrg;
}
public void setNmBrg(String nmBrg) {
this.NmBrg = nmBrg;
}
public String getSat_1() {
return this.Sat_1;
}
public void setSat_1(String sat_1) {
this.Sat_1 = sat_1;
}
public String getSat_2() {
return this.Sat_2;
}
public void setSat_2(String sat_2) {
this.Sat_2 = sat_2;
}
public int getIsi_2() {
return this.Isi_2;
}
public void setIsi_2(int isi_2) {
this.Isi_2 = isi_2;
}
public double getStock_Akhir() {
return this.Stock_Akhir;
}
public void setStock_Akhir(double stock_Akhir) {
this.Stock_Akhir = stock_Akhir;
}
public String toString() {
return this.NmBrg;
}
}
my recyclerview data holder
ModelDataBarang modelBarangResto= listModel.get(position);
holder.tvKdBrg.setText(modelBarangResto.getKdBrg());
holder.tvNmBarang.setText(modelBarangResto.getNmBrg());
holder.tvHrgBrg.setText(String.valueOf(modelBarangResto.getHrg()));
all answers i will appreciate
Your model class values are not defined as per your response. Try to check and modify respective return type. You are getting this error because you have defined Isi_2 as int in your model class but in response you are getting empty string.
Replace this
private int Isi_2;
With this
private String Isi_2;
I want to start (on background) sync with Realm Object Server when launching my Android app. And after data was successfully downloaded I want to show toast.
How I can do this? What method do I need to use?
Thanks.
I have not tried this but it should work.
private void setRealmDefaultConfiguration(SyncUser syncUser, String realmURL) {
SyncConfiguration config = new SyncConfiguration.Builder(syncUser, realmURL)
.waitForInitialRemoteData()
.build();
Realm.setDefaultConfiguration(config);
}
public abstract class BaseActivity extends Activity {
private static boolean firstInit = true;
protected Realm realm = null;
#Override
public void onCreate(Bundle bundle) {
final boolean shouldShowToast;
if(firstInit) {
firstInit = false;
shouldShowToast = true;
} else {
shouldShowToast = false;
}
super.onCreate(bundle);
Realm.getInstanceAsync(Realm.getDefaultConfiguration(), new Realm.Callback() {
#Override
public void onSuccess(Realm realm) {
if(isChangingConfigurations() || isFinishing()) {
realm.close();
} else {
BaseActivity.this.realm = realm;
onRealmLoaded(realm);
}
if(shouldShowToast) {
Toast.makeText(BaseActivity.this, R.string.data.loaded, Toast.LENGTH_LONG).show();
}
}
#Override
public void onError(Throwable throwable) {
// boop
}
});
}
protected void onRealmLoaded(Realm realm) {
// override this if needed
}
}
I have the problem with idling resources while testing using Espresso.
It doesn't work. It is called only twice and that's all, even if return false.
public class MyIdlingResource implements IdlingResource {
private boolean mIdle;
private ResourceCallback mResourceCallback;
public MyIdlingResource () {
this.mIdle = false;
this.mResourceCallback = null;
}
#Override
public final String getName() {
return MyIdlingResource .class.getSimpleName();
}
#Override
public final boolean isIdleNow() {
ArrayList<View> views = doStuff();
mIdle = views != null && !views.isEmpty();
if (mIdle) {
if (mResourceCallback != null) {
mResourceCallback.onTransitionToIdle();
}
}
return false;
}
#Override
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
mResourceCallback = resourceCallback;
}
}
So in this case I return false all the time, but it doesn't work either.
What is wrong ?
You missed return true; in below peace of code:
if (mIdle) {
if (mResourceCallback != null) {
mResourceCallback.onTransitionToIdle();
return true; // this one is missed
}
}
I am implementing an android fingerprint authentication. I want to know which user, who has registered in device before, is authenticating. Is there any information about the user, who has registered and is valid for the device, in the FingerprintManager.AuthenticationResult argument in onAuthenticationSucceeded method?!
I am using this sample.
this is my class, which is implementing FingerprintManager.AuthenticationCallback:
public class FingerprintUiHelper extends FingerprintManager.AuthenticationCallback {
private static final long ERROR_TIMEOUT_MILLIS = 1600;
private static final long SUCCESS_DELAY_MILLIS = 1300;
private final FingerprintManager mFingerprintManager;
private final ImageView mIcon;
private final TextView mErrorTextView;
private final Callback mCallback;
private CancellationSignal mCancellationSignal;
private boolean mSelfCancelled;
/**
* Constructor for {#link FingerprintUiHelper}.
*/
FingerprintUiHelper(FingerprintManager fingerprintManager,
ImageView icon, TextView errorTextView, Callback callback) {
mFingerprintManager = fingerprintManager;
mIcon = icon;
mErrorTextView = errorTextView;
mCallback = callback;
}
public boolean isFingerprintAuthAvailable() {
// The line below prevents the false positive inspection from Android Studio
// noinspection ResourceType
return mFingerprintManager.isHardwareDetected()
&& mFingerprintManager.hasEnrolledFingerprints();
}
public void startListening(FingerprintManager.CryptoObject cryptoObject) {
if (!isFingerprintAuthAvailable()) {
return;
}
mCancellationSignal = new CancellationSignal();
mSelfCancelled = false;
// The line below prevents the false positive inspection from Android Studio
// noinspection ResourceType
mFingerprintManager
.authenticate(cryptoObject, mCancellationSignal, 0 /* flags */, this, null);
mIcon.setImageResource(R.drawable.ic_fp_40px);
}
public void stopListening() {
if (mCancellationSignal != null) {
mSelfCancelled = true;
mCancellationSignal.cancel();
mCancellationSignal = null;
}
}
#Override
public void onAuthenticationError(int errMsgId, CharSequence errString) {
if (!mSelfCancelled) {
showError(errString);
mIcon.postDelayed(new Runnable() {
#Override
public void run() {
mCallback.onError();
}
}, ERROR_TIMEOUT_MILLIS);
}
}
#Override
public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
showError(helpString);
}
#Override
public void onAuthenticationFailed() {
showError(mIcon.getResources().getString(
R.string.fingerprint_not_recognized));
}
#Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
mErrorTextView.removeCallbacks(mResetErrorTextRunnable);
mIcon.setImageResource(R.drawable.ic_fingerprint_success);
mErrorTextView.setTextColor(
mErrorTextView.getResources().getColor(R.color.success_color, null));
mErrorTextView.setText(
mErrorTextView.getResources().getString(R.string.fingerprint_success));
mIcon.postDelayed(new Runnable() {
#Override
public void run() {
mCallback.onAuthenticated();
}
}, SUCCESS_DELAY_MILLIS);
}
private void showError(CharSequence error) {
mIcon.setImageResource(R.drawable.ic_fingerprint_error);
mErrorTextView.setText(error);
mErrorTextView.setTextColor(
mErrorTextView.getResources().getColor(R.color.warning_color, null));
mErrorTextView.removeCallbacks(mResetErrorTextRunnable);
mErrorTextView.postDelayed(mResetErrorTextRunnable, ERROR_TIMEOUT_MILLIS);
}
private Runnable mResetErrorTextRunnable = new Runnable() {
#Override
public void run() {
mErrorTextView.setTextColor(
mErrorTextView.getResources().getColor(R.color.hint_color, null));
mErrorTextView.setText(
mErrorTextView.getResources().getString(R.string.fingerprint_hint));
mIcon.setImageResource(R.drawable.ic_fp_40px);
}
};
public interface Callback {
void onAuthenticated();
void onError();
}
}
from AudioPlayService class onCreate() i call following code on line 168.-
line168- CustomAuxEffectStats aa = CustomAuxEffectStats.getInstance();
if (aa == null) {
createCustomAuxEffect();
}
CustomAuxEffectStats class-
public class CustomAuxEffectStats implements Serializable {
private static CustomAuxEffectStats customAuxEffectStats = null;
public static int CustomPresetID = -100;
public static final int DEFAULT_BASS_BOOST_STRENGTH = 900;
private boolean isEnabled;
private int numBands;
private int actualNumPreset;
private short selectedPreset;
private short minBandLevel;
private short maxBandLevel;
private short bassboostStrength;
private short[] bandLevels;
private String[] bandFreq;
private String[] presetNames;
private CustomAuxEffectStats(short curPreset, String[] presetNamesArr, String[] bandFreqs, short[] bandLevelRange, short[] bandlevels, boolean isEnabled) {
this.isEnabled = isEnabled;
selectedPreset = curPreset;
minBandLevel = bandLevelRange[0];
maxBandLevel = bandLevelRange[1];
numBands = bandlevels.length;
bandFreq = bandFreqs;
actualNumPreset = presetNamesArr.length - 1;
CustomPresetID = presetNamesArr.length;
presetNames = presetNamesArr;
this.bandLevels = bandlevels;
bassboostStrength = 1000;
}
public static CustomAuxEffectStats getInstance() {
return customAuxEffectStats;
}
public static CustomAuxEffectStats createInstance(short curPreset, String[] presetNamesArr, String[] bandFreqs, short[] bandLevelRange, short[] bandlevels, boolean isEnabled) {
if (customAuxEffectStats == null) {
customAuxEffectStats = new CustomAuxEffectStats(curPreset, presetNamesArr, bandFreqs, bandLevelRange, bandlevels, isEnabled);
}
return customAuxEffectStats;
}
public boolean isEnabled() {
return isEnabled;
}
public void setEnabled(boolean isEnabled) {
this.isEnabled = isEnabled;
}
public int getNumBands() {
return numBands;
}
public void setNumBands(int numBands) {
this.numBands = numBands;
}
public short getSelectedPreset() {
return selectedPreset;
}
public void setSelectedPreset(short selectedPreset) {
this.selectedPreset = selectedPreset;
}
public short getMinBandLevel() {
return minBandLevel;
}
public void setMinBandLevel(short minBandLevel) {
this.minBandLevel = minBandLevel;
}
public short getMaxBandLevel() {
return maxBandLevel;
}
public void setMaxBandLevel(short maxBandLevel) {
this.maxBandLevel = maxBandLevel;
}
public short[] getBandLevels() {
return bandLevels;
}
public void setBandLevels(short[] bandLevels) {
this.bandLevels = bandLevels;
}
public String[] getBandFreq() {
return bandFreq;
}
public void setBandFreq(String[] bandFreq) {
this.bandFreq = bandFreq;
}
public static int getCustompresetid() {
return CustomPresetID;
}
public short getBassBoostStrength() {
return bassboostStrength;
}
public void setBandLevel(short band, short progress) {
bandLevels[band] = progress;
}
public short getbandLevel(short band) {
return bandLevels[band];
}
public int getNumberOfPresets() {
return actualNumPreset;
}
public String[] getPresetNames() {
return presetNames;
}
public void setPresetNames(String[] presetNames) {
this.presetNames = presetNames;
}
public void setBassboostStrength(short bassboostStrength) {
this.bassboostStrength = bassboostStrength;
}
}
this always crashes on kitkat(dalvik run time) device when i run my app.
but it works fine in L+(ART) devices and emulators.
error log-
FATAL EXCEPTION: main
Process: com.newwave.musicsquare, PID: 26143
java.lang.VerifyError: com/newwave/musicsquare/audio/data/CustomAuxEffectStats
at com.newwave.musicsquare.services.AudioPlayService.onCreate(AudioPlayService.java:168)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2574)
at android.app.ActivityThread.access$1800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
So i figured it out..
As i was maintaining this legacy project..
the serialized class CustomAuxEffectStats had a lot of arguments in constructor that were causing problem and a lot of getters, setters...
i removed the methods and made all the fields class level.
removed all arguments from constructor...
everything is working fine.