AndroidStudio 2.0 preview generated APK shows error on Dalvik - android

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.

Related

Retrofit response return " NumberFormatexception : Empty string"

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;

retrieving firebase data to listview with a unique ID using android studio

How can I retrieve my data from firebase to android studio listview? I watch many tutorials on youtube. I use the codes of what did the tutorial gave, but it doesn't work on mine and also every data in my firebase has a unique ID to separate each data.
Here are the codes that I used:
public class ExisActivity extends AppCompatActivity {
private DatabaseReference mdatabase;
private ListView mListView;
private ArrayList<String> marralist = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_exis);
mdatabase = FirebaseDatabase.getInstance().getReference();
mListView = (ListView)findViewById(R.id.lvexist);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,marralist);
mListView.setAdapter(arrayAdapter);
}
}
and this is the other code that i used to get the data:
public class SaveData {
public String getEtOwnername() {
return etOwnername;
}
public void setEtOwnername(String etOwnername) {
this.etOwnername = etOwnername;
}
public String getEtAnimalname() {
return etAnimalname;
}
public void setEtAnimalname(String etAnimalname) {
this.etAnimalname = etAnimalname;
}
public String getEtAddress() {
return etAddress;
}
public void setEtAddress(String etAddress) {
this.etAddress = etAddress;
}
public String getEtContactNo() {
return etContactNo;
}
public void setEtContactNo(String etContactNo) {
this.etContactNo = etContactNo;
}
public String getEtDobAge() {
return etDobAge;
}
public void setEtDobAge(String etDobAge) {
this.etDobAge = etDobAge;
}
public String getEtEmail() {
return etEmail;
}
public void setEtEmail(String etEmail) {
this.etEmail = etEmail;
}
public String getEtClinicalNotes() {
return etClinicalNotes;
}
public void setEtClinicalNotes(String etClinicalNotes) {
this.etClinicalNotes = etClinicalNotes;
}
public String getEtMedication() {
return etMedication;
}
public void setEtMedication(String etMedication) {
this.etMedication = etMedication;
}
public String getEtPayMent() {
return etPayMent;
}
public void setEtPayMent(String etPayMent) {
this.etPayMent = etPayMent;
}
public SaveData(String etOwnername, String etAnimalname, String etAddress, String etContactNo, String etDobAge, String etEmail, String etClinicalNotes, String etMedication, String etPayMent) {
this.etOwnername = etOwnername;
this.etAnimalname = etAnimalname;
this.etAddress = etAddress;
this.etContactNo = etContactNo;
this.etDobAge = etDobAge;
this.etEmail = etEmail;
this.etClinicalNotes = etClinicalNotes;
this.etMedication = etMedication;
this.etPayMent = etPayMent;
}
this is my DB structure of my fire base i'm also new to fire base
{
"rules":{
".read": true,
".write": true,
}
}
Can any help me? please provide some link
PLEASE RESPECT MY POST

how to pass Array list <Object> to another activity

I pass Array list to intent but give an error . so please tell me what is wrong.
This is my code
For Sending
addToCartList=new ArrayList<>();
Intent intent=new Intent(ShopingCart.this,SelectedProductFromShopingCartShow.class);
intent.putExtra("selectedList", (Serializable) addToCartList);
startActivity(intent);
And its my Receiver code
public class SelectedProductFromShopingCartShow extends AppCompatActivity{
ArrayList<ShowProducts> arrayList=new ArrayList<>();
String condition="SelectedItemsFromShoppingCart";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selected_product_from_shoping_cart_show);
arrayList= (ArrayList<ShowProducts>) getIntent().getSerializableExtra("selectedList");
}
}
Here's my error
07-25 20:15:54.280 16503-16503/com.sizdom.sizdomstockmanager E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Parcel: unable to marshal value ShowProducts{product_name='Almost new', product_photo='http://192.168.1.39:81/sizdom/sizdomstock/product_images/1-Almost-new-17-07-11-10-27-21.jpg', product_sizes=0, product_created_date='null'}
at android.os.Parcel.writeValue(Parcel.java:1235)
at android.os.Parcel.writeList(Parcel.java:622)
at android.os.Parcel.writeValue(Parcel.java:1195)
at android.os.Parcel.writeMapInternal(Parcel.java:591)
at android.os.Bundle.writeToParcel(Bundle.java:1627)
at android.os.Parcel.writeBundle(Parcel.java:605)
at android.content.Intent.writeToParcel(Intent.java:6660)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1865)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
at android.app.Activity.startActivityForResult(Activity.java:3370)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:3331)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:3566)
at android.app.Activity.startActivity(Activity.java:3534)
at com.sizdom.sizdomstockmanager.ShopingCart$1.onClick(ShopingCart.java:66)
at android.view.View.performClick(View.java:4204)
at android.view.View$PerformClick.run(View.java:17355)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5069)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
07-25 20:20:54.325 700-910/system_process E/InputDispatcher: channel '536cf278 com.sizdom.sizdomstockmanager/com.sizdom.sizdomstockmanager.SplashScrean (server)' ~ Channel is unrecoverably broken and will be disposed!
07-25 20:20:54.325 700-910/system_process E/InputDispatcher: channel '535f9848 com.sizdom.sizdomstockmanager/com.sizdom.sizdomstockmanager.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
07-25 20:20:54.381 21855-21855/? E/Trace: error opening trace file: No such file or directory (2)
07-25 20:20:54.557 21855-21855/? E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
ShowProducts class
public class ShowProducts {
String product_name;
String product_photo;
int product_sizes;
String product_created_date;
int size_id;
String size_name;
int size_price;
int size_cost;
int size_quantity;
int product_id;
public int getProduct_id() {
return product_id;
}
public void setProduct_id(int product_id) {
this.product_id = product_id;
}
public String getProduct_name() {
return product_name;
}
public void setProduct_name(String product_name) {
this.product_name = product_name;
}
public String getProduct_photo() {
return product_photo;
}
public void setProduct_photo(String product_photo) {
this.product_photo = product_photo;
}
public int getProduct_sizes() {
return product_sizes;
}
public void setProduct_sizes(int product_sizes) {
this.product_sizes = product_sizes;
}
public String getProduct_created_date() {
return product_created_date;
}
public void setProduct_created_date(String product_created_date) {
this.product_created_date = product_created_date;
}
public int getSize_id() {
return size_id;
}
public void setSize_id(int size_id) {
this.size_id = size_id;
}
public String getSize_name() {
return size_name;
}
public void setSize_name(String size_name) {
this.size_name = size_name;
}
public int getSize_price() {
return size_price;
}
public void setSize_price(int size_price) {
this.size_price = size_price;
}
public int getSize_cost() {
return size_cost;
}
public void setSize_cost(int size_cost) {
this.size_cost = size_cost;
}
public int getSize_quantity() {
return size_quantity;
}
public void setSize_quantity(int size_quantity) {
this.size_quantity = size_quantity;
}
}
Please write ShowProducts implements Serializable in your model class.
This will resolve the issue.
There is no built in method to pass array list of objects from one activity to another activity via intents. You need to implement Parcelable interface.
Checkout developer console for the documentation.
https://developer.android.com/reference/android/os/Parcelable.html
The following code works for me:
Intent intent = new Intent(this, editList.class);
intent.putStringArrayListExtra("list", list);
startActivity(intent);
You can get the result using:
ArrayList<String>() array_list = new ArrayList<String>();
array_list = getIntent().getStringArrayListExtra("list");
First of all, serializing the items and passing it as the serializable list in Android is not recomended.
Android provides a secure and fast way to do this. We can use "Parcelable" interface. Use something like the below "Parcelable pojo" to move your list items from one activity to another.
public class ShowProducts implements Parcelable {
// THis class implents pracellable but does not create a CREATOR field
String product_name;
String product_photo;
int product_sizes;
String product_created_date;
int size_id;
String size_name;
int size_price;
int size_cost;
int size_quantity;
int product_id;
protected ShowProducts(Parcel in) {
product_name = in.readString();
product_photo = in.readString();
product_sizes = in.readInt();
product_created_date = in.readString();
size_id = in.readInt();
size_name = in.readString();
size_price = in.readInt();
size_cost = in.readInt();
size_quantity = in.readInt();
product_id = in.readInt();
}
public static final Creator<ShowProducts> CREATOR = new Creator<ShowProducts>() {
#Override
public ShowProducts createFromParcel(Parcel in) {
return new ShowProducts(in);
}
#Override
public ShowProducts[] newArray(int size) {
return new ShowProducts[size];
}
};
public int getProduct_id() {
return product_id;
}
public void setProduct_id(int product_id) {
this.product_id = product_id;
}
public String getProduct_name() {
return product_name;
}
public void setProduct_name(String product_name) {
this.product_name = product_name;
}
public String getProduct_photo() {
return product_photo;
}
public void setProduct_photo(String product_photo) {
this.product_photo = product_photo;
}
public int getProduct_sizes() {
return product_sizes;
}
public void setProduct_sizes(int product_sizes) {
this.product_sizes = product_sizes;
}
public String getProduct_created_date() {
return product_created_date;
}
public void setProduct_created_date(String product_created_date) {
this.product_created_date = product_created_date;
}
public int getSize_id() {
return size_id;
}
public void setSize_id(int size_id) {
this.size_id = size_id;
}
public String getSize_name() {
return size_name;
}
public void setSize_name(String size_name) {
this.size_name = size_name;
}
public int getSize_price() {
return size_price;
}
public void setSize_price(int size_price) {
this.size_price = size_price;
}
public int getSize_cost() {
return size_cost;
}
public void setSize_cost(int size_cost) {
this.size_cost = size_cost;
}
public int getSize_quantity() {
return size_quantity;
}
public void setSize_quantity(int size_quantity) {
this.size_quantity = size_quantity;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(product_name);
parcel.writeString(product_photo);
parcel.writeInt(product_sizes);
parcel.writeString(product_created_date);
parcel.writeInt(size_id);
parcel.writeString(size_name);
parcel.writeInt(size_price);
parcel.writeInt(size_cost);
parcel.writeInt(size_quantity);
parcel.writeInt(product_id);
}
}
You can use below code to move your array list to another activity.
addToCartList=new ArrayList<>();
Intent intent=new Intent(ShopingCart.this,SelectedProductFromShopingCartShow.class);
intent.putParcelableArrayListExtra("selectedList",addToArrayList);
startActivity(intent);
Use below code to receive it in another activity.
getIntent().getParcelableArrayListExtra("selectedList");
For Android Studio the shortcut for implementing Parcelable interface is ALT+ENTER.
Just implement the Parcelable interface with implementing the Java class.
Android studio will intimate you with red error to implement and create the CREATOR. Android Studio will generate the beautiful code for you.
That's it. Enjoy.
Your ShowProducts object must implements Parcelable.
You can easily make your Object parcelable with an online tool like : http://www.parcelabler.com/
This post can help you : How can I make my custom objects Parcelable?
Please try this ...
addToCartList=new ArrayList<>();
Intent intent=new
Intent(ShopingCart.this,SelectedProductFromShopingCartShow.class);
intent.putStringArrayListExtra("selectedList", addToCartList);
startActivity(intent);
In Your receiving Activity...
public class SelectedProductFromShopingCartShow extends AppCompatActivity{
ArrayList<ShowProducts> arrayList=new ArrayList<>();
String condition="SelectedItemsFromShoppingCart";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selected_product_from_shoping_cart_show);
arrayList= (ArrayList<ShowProducts>)
getIntent().getStringArrayListExtra("selectedList");
}}

I dont know how to change ok glass phrase in google glass

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.

Android sound pool function

is it possible to check the status of "Sound pool". i want to perform some function when it will start and stop. like ;mediaplayer's function "isplaying() ". is sound pool has this type of functionality...
Unfortunately it looks like the SoundPool API doesn't provide that functionality; it lets you start and stop a sound but doesn't have a method to check its status. In one of my apps I basically hacked around it by maintaining my own boolean that I set true when I started the sound, then set false when I stopped it or enough time had passed.
//your code to start sound here
long soundStartTime = System.currentTimeMillis();
soundPlaying=true;
//other code here
if(System.currentTimeMillis()-soundStartTime > SOUND_LENGTH_MILLIS){
soundPlaying=false;
//also set false at beginning of level and whenever you stop it manually
Refer this code..
SoundPoolManager Class
package com.demosoft.music;
import android.media.SoundPool;
import android.media.JetPlayer;
class SoundPoolEvent
{
public SoundPoolEvent(int eventType,int eventSound)
{
this.eventType = eventType;
this.eventSound = eventSound;
}
public int eventType;
public int eventSound;
public static final int SOUND_PLAY=0;
public static final int SOUND_STOP=1;
public static final int SOUND_MUSIC_PLAY=2;
public static final int SOUND_MUSIC_PAUSE=3;
public static final int SOUND_MUSIC_STOP=4;
public static final int SOUND_MUSIC_RESUME=5;
}
class SoundStatus
{
public SoundStatus()
{
}
public static final int STATUS_LOOPING_NOT_STARTED=0;
public static final int STATUS_LOOPING_PAUSED=1;
public static final int STATUS_LOOPING_PLAYING=2;
}
public class SoundPoolManager implements Sound
{
SoundPoolManager(android.content.Context context)
{
this.context = context;
soundEvents = new java.util.LinkedList();
sounds = new java.util.HashMap();
handles = new java.util.HashMap();
streamIds = new java.util.HashMap();
isRunning = false;
finished = false;
this.musicPlayer =JetPlayer.getJetPlayer();
this.musicPlayer.loadJetFile(context.getResources().openRawResourceFd(R.raw.notify));
byte segmentId = 0;
this.musicPlayer.queueJetSegment(0, -1, -1, 0, 0, segmentId++);
}
public void addSound(int resid, boolean isLooping)
{
sounds.put(resid, new Boolean(isLooping));
}
public void startSound()
{
this.soundPool = new android.media.SoundPool(this.sounds.size(),android.media.AudioManager.STREAM_MUSIC,100);
java.util.Iterator iterator = sounds.keySet().iterator();
while(iterator.hasNext())
{
int soundid = iterator.next().intValue();
int soundhandle = this.soundPool.load(this.context, soundid, 1);
handles.put(new Integer(soundid), new Integer(soundhandle));
}
}
public void stopSound()
{
try
{
java.util.Iterator iterator = sounds.keySet().iterator();
while(iterator.hasNext())
{
int soundid = iterator.next().intValue();
this.soundPool.pause( this.handles.get(soundid).intValue());
this.soundPool.stop(this.handles.get(soundid).intValue());
}
}
catch(Exception e)
{
}
finally
{
try
{
this.musicPlayer.pause();
}
catch(Exception e1)
{
}
try
{
this.musicPlayer.release();
}
catch(Exception e2)
{
}
try
{
this.soundPool.release();
}
catch(Exception e3)
{
}
}
}
public int currentPlayer;
private boolean isRunning;
private java.util.HashMap sounds;
private java.util.HashMap handles;
private java.util.HashMap streamIds;
private android.content.Context context;
private java.util.LinkedList soundEvents;
private java.util.HashMap mediaPlayers;
public void stopSound(int resid)
{
}
public void playSound(int resid)
{
if(soundEvents!=null)
{
try
{
android.media.AudioManager mgr = (android.media.AudioManager) context.getSystemService(android.content.Context.AUDIO_SERVICE);
int streamVolume = mgr.getStreamVolume(android.media.AudioManager.STREAM_MUSIC);
int streamID = soundPool.play(handles.get( resid).intValue(), streamVolume, streamVolume, 1, 0, 1.0f);
int maxvolume = mgr.getStreamMaxVolume(android.media.AudioManager.STREAM_MUSIC);
mgr.setStreamVolume(android.media.AudioManager.STREAM_MUSIC, maxvolume, 0);
this.streamIds.put(resid, streamID);
}
catch(Exception e)
{
}
}
}
public void startMusic(int resid)
{
this.musicPlayer.play();
}
public void stopMusic(int resid)
{
this.musicPlayer.pause();
}
public void pauseMusic(int resid)
{
this.musicPlayer.pause();
}
public void resumeMusic(int resid)
{
this.musicPlayer.play();
}
SoundPool soundPool;
JetPlayer musicPlayer;
boolean finished = false;
}
And add the interface of Sound..... to the above package
package com.demosoft.music;
public interface Sound {
public void addSound(int resid, boolean isLooping);
public void startSound();
public void stopSound();
public void stopSound(int resid);
public void playSound(int resid);
public void startMusic(int resid);
public void stopMusic(int resid);
public void pauseMusic(int resid);
public void resumeMusic(int resid);
}
And u can use in difffernt ways ....
1. creating the soundpoolmanager instance class ......
2. by using Sound interface instance,....
SoundPoolManager m = new SoundPoolManager(context);
m.addSound(R.raw.demo, false);
m.addSound(R.raw.soft,true);
m.startSound();
m.playSound(R.raw.demo);
m.playMusic(R.raw.soft);
or
private Sound soundManager;
soundManager.playSound(R.raw.demo);
public synchronized void stopMusic()
{
soundManager.stopSound();
//message.sendToTarget();
this.soundManager.stopSound();
}

Categories

Resources