How to make all information stay after app store update? - Android Software/Hacking General [Developers Only]

I just released my first update for my app, and apparently it wiped all data from each person's app as if it was a fresh install. There are list objects primarily that are stored with a FileInputStream as shown in the code and the settings are stored with SharedPreferences. Does anyone know how to make it where each time I update, these don't dissappear? Thanks!
Code:
public ObjectStorage readListFromFile()
{
ObjectStorage temp = null;
String filename = "storefileobj";
FileInputStream fis;
try {
fis = getActivity().openFileInput(filename);
ObjectInputStream is = new ObjectInputStream(fis);
temp = (ObjectStorage) is.readObject();
is.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (StreamCorruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return temp;
}
public void updateStorage()
{
String filename = "storefileobj";
FileOutputStream fos;
try {
fos = getActivity().openFileOutput(filename, Context.MODE_PRIVATE);
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(mainObjectList);
os.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

Related

Save calculator result problem

Here's where the button is pressed:
btnMP.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
memNum = memNum + Double.parseDouble(txtCalc.getText().toString());
operator = 0; }
});
Here's a thingie I hammered together from parts:
// Save MEMORY
public void WriteMemory(OnClickListener onClickListener, double
memNum){
File sdcard = Environment.getExternalStorageDirectory();
File destinationdir = new File(sdcard,"/download/calculator");
destinationdir.mkdir();
File destinationfile = new File(destinationdir,"memory.dat");
FileOutputStream fOut = null;
OutputStreamWriter osw = null;
try{
destinationfile.createNewFile();
fOut = new FileOutputStream(destinationfile);
osw = new OutputStreamWriter(fOut);
osw.write((int) memNum);
osw.flush();
Toast.makeText((Context) onClickListener, "Memory
saved",Toast.LENGTH_SHORT).show();
}
catch (Exception e) {
e.printStackTrace();
// Toast.makeText((Context) onClickListener, "Memory not
saved",Toast.LENGTH_SHORT).show();
}
finally {
try {
osw.close();
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
This is called by inserting WriteMemory(this,memNum); in the button
routine thusly:
btnMP.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
memNum = memNum + Double.parseDouble(txtCalc.getText().toString());
operator = 0; }
WriteMemory(this,memNum);
});
The file is created but only a 0 is written in it. What's missing?
Brian

[Q] Problem when sending string to server

Hi i am new to android developing. I don't know is this the right section to post but i really need help on this. My app is a remote control and and it has to send strings to the server (PC) by clicking the buttons. Somehow my app crashes when i click the button . I cant figure out the problem. Can anyone help me please?? .
here I'm pasting the code:
Code:
public class MyAppActivity extends Activity {
/** Called when the activity is first created. */
Button mButton;
EditText mEdit;
TextView mTextView;
String ip;
Socket s;
InputStream is;
InputStreamReader isr;
BufferedReader br;
DataOutputStream os;
//PrintWriter pw;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.addip);
mButton = (Button) findViewById(R.id.button1);
mEdit = (EditText) findViewById(R.id.editText1);
mTextView = (TextView) findViewById(R.id.tConnectStatus);
mButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String ip = mEdit.getText().toString();
try {
s = new Socket(ip, 2222);
is = s.getInputStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
os = new DataOutputStream(s.getOutputStream());
//pw = new PrintWriter(os, true);
// s.close();
} catch (Exception ex) {
// System.out.println(ex);
CharSequence statusMesg = "Please Enter the Correct IP ";
mTextView.setText(statusMesg);
}
// Wificlient conState = new Wificlient();
if (s.isConnected()) {
CharSequence statusMesg = "Connected";
mTextView.setText(statusMesg);
Intent startAcontroller = new Intent(
"my.hasham.joy.app.ACONTROLLER");
startActivity(startAcontroller);
} else {
CharSequence statusMesg = "Please Enter the Correct IP ";
mTextView.setText(statusMesg);
// finish();
}
// Intent startAcontroller = new
// Intent("my.hasham.joy.app.ACONTROLLER");
// startActivity(startAcontroller);
}
});
}
public void sendForward(String cmd) throws IOException {
os.writeUTF(cmd);
}
public void sendBackward(String cmd) throws IOException {
os.writeUTF(cmd);
}
public void sendLeft(String cmd) throws IOException {
os.writeUTF(cmd);
}
public void sendRight(String cmd) throws IOException {
os.writeUTF(cmd);
}
public void sendStart(String cmd) throws IOException {
os.writeUTF(cmd);
}
public void sendSelect(String cmd) throws IOException {
os.writeUTF(cmd);
}
public void sendB(String cmd) throws IOException {
os.writeUTF(cmd);
}
public void sendA(String cmd) throws IOException {
os.writeUTF(cmd);
}
}
and the other activity:
Code:
public class Acontroller extends Activity {
Button bForward;
Button bBackward;
Button bRight;
Button bLeft;
Button bSelect;
Button bStart;
Button bB;
Button bA;
public MyAppActivity command = new MyAppActivity();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.nesskin);
bForward = (Button) findViewById(R.id.bForward);
bBackward = (Button) findViewById(R.id.bBackward);
bRight = (Button) findViewById(R.id.bRight);
bLeft = (Button) findViewById(R.id.bLeft);
bSelect = (Button) findViewById(R.id.bSelect);
bStart = (Button) findViewById(R.id.bStart);
bA = (Button) findViewById(R.id.bA);
bB = (Button) findViewById(R.id.bB);
bForward.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
try {
command.sendForward("forward");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
bBackward.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// MyAppActivity command = new MyAppActivity();
try {
command.sendBackward("backward");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
bLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// MyAppActivity command = new MyAppActivity();
try {
command.sendLeft("Left");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
bRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// MyAppActivity command = new MyAppActivity();
try {
command.sendRight("right");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
bSelect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// MyAppActivity command = new MyAppActivity();
try {
command.sendSelect("select");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
bStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// MyAppActivity command = new MyAppActivity();
try {
command.sendStart("start");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
bA.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// MyAppActivity command = new MyAppActivity();
try {
command.sendA("a");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
bB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// MyAppActivity command = new MyAppActivity();
try {
command.sendB("b");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
}
Please if anyone can help me . I really need to get this done.

Simple MediaPlayer project, problems WP7

I'm trying to create simple mediaplayer and using MediaPlayer Class, but I have some problems. When I select song from the list, my buttons Next and Prev stopped working. I try some things but nothing works, what I have to do, to fix this problem. I don't know how to use EventHandler - MediaStateChanged, will see this in the code below. I want to add simple progress bar, but this class don't have current position event. I read some about DispatcherTimer, but ...
The code:
Code:
namespace MediaViewer
{
public partial class MainPage : PhoneApplicationPage
{
private App app;
int songIndexForDetails;
public MainPage()
{
InitializeComponent();
app = Application.Current as App;
List<CategoryDetailsViewModel> items = new List<CategoryDetailsViewModel>();
items.Add(app.MusicModel);
PivotControl.ItemsSource = items;
ProgressBar.Visibility = Visibility.Collapsed;
txtCurrentState.Text = MediaPlayer.State.ToString();
}
private void ItemsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBox list = (ListBox)sender;
int selectedCategoryIndex = list.SelectedIndex;
songIndexForDetails = list.SelectedIndex;
if (selectedCategoryIndex == -1)
return;
List<CategoryDetailsViewModel> model = PivotControl.ItemsSource as List<CategoryDetailsViewModel>;
if (model[PivotControl.SelectedIndex].IsAnyItemAvailable())
{
if (model[PivotControl.SelectedIndex].PrepareItemForPreview(selectedCategoryIndex))
{
if (model[PivotControl.SelectedIndex] is MusicCategoryModel)
{
MediaLibrary library = new MediaLibrary();
FrameworkDispatcher.Update();
MediaPlayer.Play(library.Songs[selectedCategoryIndex]);
ProgressBar.Visibility = Visibility.Visible;
txtCurrentState.Text = MediaPlayer.State.ToString();
}
}
else
MessageBox.Show("Warining!\n\nUnable to open selected file.\nMake sure that your device is disconnected from the computer.");
}
}
private void detailsButton_Click(object sender, RoutedEventArgs e)
{
if (songIndexForDetails == -1)
{
return;
}
NavigationService.Navigate(new Uri("/Pages/SongDetailsPage.xaml?SelectedItem=" + songIndexForDetails, UriKind.Relative));
}
private void pauseButton_Click(object sender, RoutedEventArgs e)
{
MediaPlayer.Pause();
ProgressBar.Visibility = Visibility.Collapsed;
txtCurrentState.Text = MediaPlayer.State.ToString();
}
private void stopButton_Click(object sender, RoutedEventArgs e)
{
MediaPlayer.Stop();
ProgressBar.Visibility = Visibility.Collapsed;
txtCurrentState.Text = MediaPlayer.State.ToString();
}
private void playButton_Click(object sender, RoutedEventArgs e)
{
MediaLibrary library = new MediaLibrary();
FrameworkDispatcher.Update();
if (MediaPlayer.State == MediaState.Paused)
{
MediaPlayer.Resume();
}
else
{
MediaPlayer.Play(library.Songs);
ProgressBar.Visibility = Visibility.Visible;
txtCurrentState.Text = MediaPlayer.State.ToString();
}
}
private void nextButton_Click(object sender, RoutedEventArgs e)
{
MediaPlayer.MoveNext();
}
private void previousButton_Click(object sender, RoutedEventArgs e)
{
MediaPlayer.MovePrevious();
}
public Song GetModelForIndex(int itemIndex)
{
if (itemIndex < Songs.Count)
return Songs[itemIndex];
else
return null;
}
private List<Song> Songs { get; set; }
}
}

[Q] Tropo SMS Integration In Android Api

I'm building a complete build of Android with tropo: (Google tropo)
Here's my tropo hosted script in javascript:
Code:
if (typeof number == 'undefined') {//IF the call doesn't come from me (there's no variable set)
var callerId=currentCall.callerID;
var textmessage=currentCall.initialText
hangup()
call('(Put your phone number Here', {network: 'SMS'});
//Analyse message and format it for sending
var message = new Array();
var nbMessages=((textmessage.length())/149) ;//.length() ????? why????
var i=0;
for(i=0;i<nbMessages;i++){
message[i]=callerId+textmessage.substr(i*149,149);
say(message[i]);
wait(1000);
}
hangup()
}
else //SENDING PART:number and text are parameters
{
call(number, {network:"SMS"});
say(text);
}
I've used the CM9 source code for the galaxy s2 that I downloaded and builded following this guide: (Google teamhacksung CyanogenMod9 How to build)
For sending, I simply post an HTTP Post request to my tropo app
Here's the code
I modified the SMSManager.java class in android.telephony package
Code:
public void sendTextMessage(
String destinationAddress, String scAddress, String text,
PendingIntent sentIntent, PendingIntent deliveryIntent) {
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (TextUtils.isEmpty(text)) {
throw new IllegalArgumentException("Invalid message body");
}
/* OLD METHOD FOR SMS BY CARRIER
try {
ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (iccISms != null) {
iccISms.sendText(destinationAddress, scAddress, text, sentIntent, deliveryIntent);
}
} catch (RemoteException ex) {
// ignore it
}*/
//My new Method via tropo
//Création de l'objet Tropo SMS
TropoSms sms = new TropoSms(destinationAddress, text, sentIntent,deliveryIntent);
sms.send();
}
/**/
public void sendMultipartTextMessage(
String destinationAddress, String scAddress, ArrayList<String> parts,
ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents) {
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (parts == null || parts.size() < 1) {
throw new IllegalArgumentException("Invalid message body");
}
if (parts.size() > 1) {
/*//OLD METHOD FOR SMS CARRIER
try {
ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (iccISms != null) {
iccISms.sendMultipartText(destinationAddress, scAddress, parts,
sentIntents, deliveryIntents);
}
} catch (RemoteException ex) {
// ignore it
}*/
//My tropo Method
for(int i=0; i< parts.size();i++){
TropoSms sms = new TropoSms(destinationAddress, parts.get(i), sentIntents.get(i),deliveryIntents.get(i));
sms.send();
}
} else {
PendingIntent sentIntent = null;
PendingIntent deliveryIntent = null;
if (sentIntents != null && sentIntents.size() > 0) {
sentIntent = sentIntents.get(0);
}
if (deliveryIntents != null && deliveryIntents.size() > 0) {
deliveryIntent = deliveryIntents.get(0);
}
sendTextMessage(destinationAddress, scAddress, parts.get(0),
sentIntent, deliveryIntent);
}
}
Here I created the Tropo SMS class in the android.telephony.tropo package
Code:
/**
*
*/
package android.telephony.tropo;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.telephony.SmsManager;
/**
* @author kevmegforest
*
*/
public class TropoSms {
protected String destinationAddress="Undefined";
protected String message="Undefined";
protected PendingIntent sentIntent;
protected PendingIntent deliveryIntent;
private static String token="1...4c";
public TropoSms(){
}
public TropoSms(String sendAddress, String text, PendingIntent sendIntent, PendingIntent deliverIntent){
destinationAddress=sendAddress;
message=text;
sentIntent=sendIntent;
deliveryIntent=deliverIntent;
}
/**------------------------------------------
* SETTERS AND GETTERS
* @return
*/
public String getDestinationAddress() {
return destinationAddress;
}
public String getMessage() {
return message;
}
//--------------------------------------------------
/**
* Methods
*/
public void send(){ //Success return true //Fail return false
boolean success=true;
this.message=manageText();
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
HttpResponse response;
HttpPost post = new HttpPost("https://api.tropo.com/1.0/sessions");
//Creating JSON object
JSONObject json= new JSONObject();
try {
json.put("token", token);
json.put("number", this.destinationAddress );
json.put("text", this.message);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
success=false;
}
try {
StringEntity se = new StringEntity(json.toString());
post.setEntity(se);
//Post headers Setup
post.addHeader("accept", "application/json");
post.addHeader("content-type","application/json");
response=client.execute(post);
//Checking response
//HOW TO
if(response.getStatusLine().getStatusCode() !=200)
success=false;
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
success =false;
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
success=false;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
success=false;
}
this.manageIntent(success);
client.getConnectionManager().shutdown();//Ending connection
}
private void manageIntent(boolean sendsuccess)
{
if(sendsuccess)
{
try {
this.sentIntent.send(Activity.RESULT_OK);
} catch (CanceledException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
try {
this.sentIntent.send(SmsManager.RESULT_ERROR_GENERIC_FAILURE);
} catch (CanceledException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private String manageText()
{
String correctedText=this.message;//The last character in each table is the one to replace with
char characterToReplaceA[]={'à','â','ä','a'};
char characterToReplaceC[]={'ç','c'};
char characterToReplaceE[]={'é','è','ê','ë','e'};
char characterToReplaceI[]={'ì','î','ï','i'};
char characterToReplaceO[]={'ò','ô','ö','o'};
char characterToReplaceU[]={'ù','û','ü','u'};
char characterToReplace[][]={characterToReplaceA,characterToReplaceC,characterToReplaceE,characterToReplaceI,characterToReplaceO,characterToReplaceU};
for(int i=0;i<characterToReplace.length;i++){
for(int j=0;j<(characterToReplace[i].length-1);j++){
correctedText=correctedText.replace(characterToReplace[i][j],characterToReplace[i][characterToReplace[i].length-1]);
correctedText=correctedText.replace(Character.toUpperCase(characterToReplace[i][j]),Character.toUpperCase(characterToReplace[i][characterToReplace[i].length-1]));
}
}
return correctedText;
}
}
The sending part works really well. Since it's an API change I can use any SMS App in android and it would work.
But I have a problem with receiving.
My tropo script can only modify the body message of the sms. So when someone send a SMS message to tropo, I prefixed the body message with 10 characters representing it's phone number like this:
original message: "Hello"
new message:"15551231234Hello"
I then send this message to my phone
The modified class SubmitPdu in android.telephony package in the SMSMessage.java file
It's wherethe SMS app get the sms with the createfrompdu() method
Code:
public static SmsMessage createFromPdu(byte[] pdu, String format) {
SmsMessageBase wrappedMessage;
if (FORMAT_3GPP2.equals(format)) {
wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.createFromPdu(pdu);
} else if (FORMAT_3GPP.equals(format)) {
wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.createFromPdu(pdu);
} else {
Log.e(LOG_TAG, "createFromPdu(): unsupported message format " + format);
return null;
}
//Verify here if it comes from TROPO
Log.d("SMSNumberCompare", "Original number:"+wrappedMessage.getOriginatingAddress());
Log.d("SMSNumberCompare", "Tropo number:"+TropoSmsReceiver.TROPO_APP_PHONE_NUMBER);
if(PhoneNumberUtils.compare(wrappedMessage.getOriginatingAddress(), TropoSmsReceiver.TROPO_APP_PHONE_NUMBER)){
Log.d("SMSNumberCompare", "Comparison:"+(PhoneNumberUtils.compare(wrappedMessage.getOriginatingAddress(), TropoSmsReceiver.TROPO_APP_PHONE_NUMBER)));
//Creating TropoReceive Object
TropoSmsReceiver tropo = (TropoSmsReceiver) wrappedMessage; //Downcasting
tropo.formatFromTropo();
//upcasting
wrappedMessage=tropo;
}
return new SmsMessage(wrappedMessage);
}
And here's my TropoSmsReceiver Class which extends the SmsMessageBase class
Code:
package com.android.internal.telephony.tropo;
import android.telephony.PhoneNumberUtils;
import android.telephony.SmsMessage.MessageClass;
import android.util.Log;
import com.android.internal.telephony.SmsMessageBase;
public class TropoSmsReceiver extends SmsMessageBase {
public final static String TROPO_APP_PHONE_NUMBER="###########";
//My new Methods
//this method will format the text to get the parameters transferred from the tropo text
public void formatFromTropo(){
Log.d("TropoFormat", "old address"+this.originatingAddress.address);
this.originatingAddress.address=PhoneNumberUtils.formatNumber(this.messageBody.substring(0, 10), PhoneNumberUtils.FORMAT_NANP );
Log.d("TropoFormat", "new address"+this.originatingAddress.address);
this.messageBody=this.messageBody.substring(11);
Log.d("TropoFormat", "new Body"+this.messageBody);
}
@Override
public MessageClass getMessageClass() {
// TODO Auto-generated method stub
return null;
}
@Override
public int getProtocolIdentifier() {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean isReplace() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isCphsMwiMessage() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isMWIClearMessage() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isMWISetMessage() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isMwiDontStore() {
// TODO Auto-generated method stub
return false;
}
@Override
public int getStatus() {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean isStatusReportMessage() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isReplyPathPresent() {
// TODO Auto-generated method stub
return false;
}
}
The interesting part is my new method formatFromTropo()
But I have a problem, it doesn't work.
It builds sucessfully
In the logcat, the debug log says it goes in the if statement (it says Comparison: true and it's placement is in the if)
But when the tropo.formatFromTropo() is called the catlog has no mention of any log declared in the TropoSmsReceiver File. How is that possible? Can you help me?
It's my first android project (app or android Source change) and java project so you can give me many recommendations(and comments) too.
Thank you

I need help with my android project

could you help me figure out how can i stop sound with mediaplayer after clicking another soundbutton?
*and how can i set alarm/ringtone/notification when long press
*and i need help with adding admob on my app, ive read all posts i could google but still i get errors, i cant understand what am i doing wrong, if anybody wishes to help me please pm me your skype.
thank you very much.
code:
final MediaPlayer sound01 = MediaPlayer.create(this, R.raw.sound01);
Button s01 = (Button) findViewById(R.id.button01);
s01.setText(this.getString(R.string.quote01));
s01.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
sound01.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sound01.start();
}
Stop sound
Add this in your app:
Button s02 = (Button) findViewById(R.id.button02);
s02.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
sound01.stop();
}
});
thanks for posting mate, but when i added it, it will only play the first sound when i start the app, after i press the second button and then want to play the first button again it wont start...
also i have like 20 sounds, and for example if i want to play like sound 4 and then sound one again how will it stop?
Button s01 = (Button) findViewById(R.id.button01);
s01.setText(this.getString(R.string.quote01));
s01.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
sound01.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sound01.start();
}
});
registerForContextMenu(s01);
Button s02 = (Button) findViewById(R.id.button02);
s02.setText(this.getString(R.string.quote02));
s02.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
sound01.stop();
try {
sound02.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
bump
still need help with my project.... is this thing really so hard that few ppl only know how to do it?
please i still need help with my code | bump
bump
MediaPlayer might not be what you want.
For playing sounds in an app try AsyncPlayer or AudioTrack.
(Note also that MediaPlayer.create() already does a prepare().)
thank you for posting, but im still very noob at this thing, could you copy me a code that works ? or help me add stuff to it? im looking in to that asyncplayer you suggested

Categories

Resources