Okay so I am having a problem getting my app to work. Basically I have an game that needs to get a few pictures and Strings from the user. I have an opening screen (OpeningScreen) that acts as a splash screen that opens up the menu (MenuScreen). From there the user can pick to go to the game or go to the activity that shows the current pictures (PickScreen). The user can go to that activity and from there open up another activity that gives a larger version of the picture they currently have picked or a default picture (PicOne). Here the user has the option to take a new picture and change the current Strings. For the most part all of it works great. My problem occurs when:
After the user picks a picture and backs out of the app. The next time they open it, it will force close either when I go back to PickScreen or after I press done after taking a new picture and sometimes when I go to PicOne activity. It does not do the same thing everytime, it just crashes at one of those points.
The other issue happens when I change the 3 String names. After pressing save and going back to PickScreen, the app crashes when going back to PicOne or if I back out of the app crashes when going from MenuScreen to PickScreen.
I know this is a lot of code to look at, but I have spent a lot of time looking around and getting code from different places for this app and I am at a point that I cannot figure out. I figure there are many people with more knowledge than me out there, so I am asking for your help. I know that you cannot just ask a question without showing you have been doing any work, so here it is.
Why does may app work perfectly once and then crash in various spots the second time in? By the way it does work fine after the force close, again only once. And why does it force close when I change the Strings?
Thanks everyone!!
The PicOne Class
public class PicOne extends Activity implements OnClickListener {
ImageView iv;
EditText c1, c2, c3;
Button cam, save;
Bitmap bit, bmp,other;
Intent i;
Uri uriSavedImage;
String imageFilePath10 = "", name1="", name2="", name3="";
final static int cameraData = 0;
boolean CAMERA;
int camORgal10 = 0;
SharedPreferences gameData;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.picone);
CAMERA = false;
iv = (ImageView)findViewById(R.id.picIV);
cam = (Button)findViewById(R.id.camButton);
save = (Button)findViewById(R.id.savebut);
e1 = (EditText)findViewById(R.id.Enter1);
e2 = (EditText)findViewById(R.id.Enter2);
e3 = (EditText)findViewById(R.id.Enter3);
cam.setOnClickListener(this);
save.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId())
{
//camera
case R.id.camButton:
camORgal10 = 1;
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "MySpot");
imagesFolder.mkdirs(); // <----
String fileName = "image_1.PNG";
File output = new File(imagesFolder, fileName);
uriSavedImage = Uri.fromFile(output);
i.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(i, cameraData);
break;
case R.id.savebut:
CAMERA = true;
name1 = e1.getText().toString();
name2 = e2.getText().toString();
name3 = e3.getText().toString();
SharedPreferences.Editor editor = gameData.edit();
editor.putInt("NUM10CAMGAL", camORgal10);
editor.putString("NUM10NAME1", name1);
editor.putString("NUM10NAME2", name2);
editor.putString("NUM10NAME3", name3);
editor.commit();
Intent goPT = new Intent(this, PickScreen.class);
goPT.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
goPT.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
finish();
startActivity(goPT);
break;
}
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK)
{
CAMERA = true;
name1 = e1.getText().toString();
name2 = e2.getText().toString();
name3 = e3.getText().toString();
SharedPreferences.Editor editor = gameData.edit();
editor.putInt("NUM10CAMGAL", camORgal10);
editor.putString("NUM10NAME1", name1);
editor.putString("NUM10NAME2", name2);
editor.putString("NUM10NAME3", name3);
editor.commit();
Intent goPT = new Intent(this, PickScreen.class);
goPT.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
goPT.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
finish();
startActivity(goPT);
return true;
}
return super.onKeyDown(keyCode, event);
}
#Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == cameraData)
{
if(resultCode == RESULT_OK && data.hasExtra("data"))
{
bmp = (Bitmap) data.getExtras().get("data");
iv.setImageBitmap(bmp);
}
else if (resultCode == RESULT_CANCELED)
{
Toast.makeText(getApplicationContext(), "Cancelled",Toast.LENGTH_SHORT).show();
}
}
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
if(OpeningScreen.isEXIT)
{
finish();
}
gameData = getSharedPreferences(MenuScreen.MYFOLDER, 0);
name1 = slotData.getString("NUM10NAME1", "one");
name2 = slotData.getString("NUM10NAME2", "two");
name3 = slotData.getString("NUM10NAME3", "three");
e1.setText(name1);
e2.setText(name2);
e3.setText(name3);
camORgal10 = gameData.getInt("NUM10CAMGAL", 0);
if(camORgal10 == 0)
{
bit = BitmapFactory.decodeResource(getResources(), R.drawable.red);
}
else if(camORgal10 == 1)
{
File imgFile = new File(Environment.getExternalStorageDirectory() + "/MySpot/image_1.PNG");
if(imgFile.exists())
{
bit = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
}
else
{
bit = BitmapFactory.decodeResource(getResources(), R.drawable.red);
}
}
else
{
bit = BitmapFactory.decodeResource(getResources(), R.drawable.red);
}
iv.setImageBitmap(bit);
super.onResume();
}
}
OpeningScreen
public class OpeningScreen extends Activity {
/** Called when the activity is first created. */
public static boolean isEXIT = false;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
isEXIT = false;
Thread timer = new Thread(){
public void run(){
try{
sleep(2500);
} catch(InterruptedException e){
} finally{
Intent toMenu = new Intent(getApplicationContext(), MenuScreen.class);
toMenu.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//toMenu.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
finish();
startActivity(toMenu);
}
}
};
timer.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
finish();
super.onPause();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
if(isEXIT)
{
finish();
}
super.onResume();
}
}
MenuScreen
public class MenuScreen extends Activity implements OnClickListener {
float x,y;
int camORgal = 0;
ImageButton play, edit, more;
Intent i;
public static String MYFOLDER = "GAMEDATA";
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
play = (ImageButton)findViewById(R.id.IBplay);
edit = (ImageButton)findViewById(R.id.IBedit);
more = (ImageButton)findViewById(R.id.IBmore);
play.setOnClickListener(this);
edit.setOnClickListener(this);
more.setOnClickListener(this);
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK)
{
OpeningScreen.isEXIT = true;
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId())
{
case R.id.IBplay:
i = new Intent(getApplicationContext(), TheGame.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(i);
break;
case R.id.IBedit:
i = new Intent(this, PickScreen.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(i);
break;
case R.id.IBmore:
break;
}
}
}
PickScreen
public class PickScreen extends Activity implements OnClickListener {
Button bPic1, bPic2, bPic3;
ImageView ivpic3,ivpic2, ivpic1;
TextView TVpic3a, TVpic3b, TVpic3c, TVpic2a, TVpic2b, TVpic2c, TVpic1a, TVpic1b, TVpic1c;
Intent pageMove;
SharedPreferences gameData;
int camORgal10 = 0;
String threeNamea = "", threeNameb = "", threeNamec = "", twoNamea = "", twoNameb = "", twoNamec = "", oneNamea = "", oneNameb = "", oneNamec = "";
Bitmap bmp1, bmp2,bmp3;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.paytable);
intitializeThings();
}
public void intitializeThings()
{
bPic1 = (Button)findViewById(R.id.pic1but);
bPic2 = (Button)findViewById(R.id.pic2but);
bPic3 = (Button)findViewById(R.id.pic3but);
ivpic3 = (ImageView)findViewById(R.id.ivpic3a);
ivpic2 = (ImageView)findViewById(R.id.ivpic2a);
ivpic1 = (ImageView)findViewById(R.id.ivpic1a);
TVpic3a = (TextView)findViewById(R.id.pic3TVa);
TVpic3b = (TextView)findViewById(R.id.pic3TVb);
TVpic3c = (TextView)findViewById(R.id.pic3TVc);
TVpic2a = (TextView)findViewById(R.id.pic2TVa);
TVpic2b = (TextView)findViewById(R.id.pic2TVb);
TVpic2c = (TextView)findViewById(R.id.pic2TVc);
TVpic1a = (TextView)findViewById(R.id.pic1TVa);
TVpic1b = (TextView)findViewById(R.id.pic1TVb);
TVpic1c = (TextView)findViewById(R.id.pic1TVc);
bPic1.setOnClickListener(this);
bPic2.setOnClickListener(this);
bPic3.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId())
{
case R.id.pic1but:
pageMove = new Intent(getApplicationContext(), PicOne.class);
pageMove.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
pageMove.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//pageMove.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
finish();
startActivity(pageMove);
break;
case R.id.pic2but:
pageMove = new Intent(getApplicationContext(), PicTwo.class);
pageMove.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//pageMove.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(pageMove);
finish();
break;
case R.id.pic3but:
pageMove = new Intent(getApplicationContext(), PicThree.class);
pageMove.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//pageMove.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(pageMove);
finish();
break;
}
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK)
{
Intent goOP = new Intent(this, MenuScreen.class);
goOP.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
goOP.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
finish();
startActivity(goOP);
return true;
}
return super.onKeyDown(keyCode, event);
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
gameData = getSharedPreferences(MenuScreen.MYFOLDER, 0);
oneNamea = gameData.getString("NUM10NAME1", "one");
oneNameb = gameData.getString("NUM10NAME2", "two");
oneNamec = gameData.getString("NUM10NAME3", "three");
camORgal10 = gameData.getInt("NUM10CAMGAL", 0);
if(camORgal10 == 1)
{
File pic1 = new File(Environment.getExternalStorageDirectory() + "/MySpot/image_1.PNG");
if(pic1.exists())
{
bmp1 = BitmapFactory.decodeFile(pic1.getAbsolutePath());
}
else
{
bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.red);
}
}
else if(camORgal10 == 0)
{
bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.red);
}
else
{
bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.red);
}
File pic2 = new File(Environment.getExternalStorageDirectory() + "/MySpot/image_2.PNG");
File pic3 = new File(Environment.getExternalStorageDirectory() + "/MySpot/image_3.PNG");
if(pic2.exists())
{
bmp2 = BitmapFactory.decodeFile(pic2.getAbsolutePath());
}
else
{
bmp2 = BitmapFactory.decodeResource(getResources(), R.drawable.purple);
}
if(pic3.exists())
{
bmp3 = BitmapFactory.decodeFile(pic3.getAbsolutePath());
}
else
{
bmp3 = BitmapFactory.decodeResource(getResources(), R.drawable.green);
}
ivpic3.setImageBitmap(bmp3);
ivpic2.setImageBitmap(bmp2);
ivpic1.setImageBitmap(bmp1);
TVpic1a.setText(oneNamea);
TVpic1b.setText(oneNameb);
TVpic1c.setText(oneNamec);
}
}
Logcat will give you a stack trace, and then use debug to pinpoint the place where it's crashing. Debugging a modern application by reading through code, especially OOP code, is nearly impossible.
This was probably caused by the fact the AOS does not closes apps really but you might think is does. So on the next start AOS doesn't start your app "from the scratch" but it raises your undead cached app. And since your logic wasn't expected that your app crashes. I'm pretty sure it starts OK once again right after the crash but the next start once again crashes -> the loop. So to avoid that use System.exit(0) (most advanced devs gonna say its a bad practice) to ensure your app wont became a zombie OR change the logic of your app so it wont crash on the next start cuz the main activity is still there.
Related
I am trying to display image on ImageView. I have the image in /storage/sdcard/DCIM/Camera/SAMPLE IMAGES/xxx.png I have used the following code to display image on the ImageView.
public class MainActivity extends Activity
{ Button button,hi,addpic;
final adapter info = new adapter(this);
Runnable m_handlertask = null ;
String path,birth;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button1);
hi = (Button) findViewById(R.id.button3);
final adapter info = new adapter(this);
/* for(int i =1;i<=info.getrowcount();i++)
{
java.lang.String[] images_paths = {};
images_paths[i-1]=info.fetchsingles(i);
Toast.makeText(getApplicationContext(), images_paths[i-1], Toast.LENGTH_LONG).show();
}*/
hi.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(MainActivity.this,newlist.class);
startActivity(i);
}
});
addpic = (Button) findViewById(R.id.button2);
addpic.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(MainActivity.this,adpic.class);
startActivity(i);
}
});
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(MainActivity.this,padd.class);
startActivity(i);
}
});
Date date = new Date(0);
java.text.DateFormat dateFormat =
android.text.format.DateFormat.getDateFormat(getApplicationContext());
dateFormat.format(date);
final ImageView jpgView;
jpgView = (ImageView) findViewById(R.id.imageView1);
//adapter mDbAdapter;
// path = info.getpath(y);
path = info.getPath();
final Handler mHandler = new Handler();
m_handlertask = new Runnable(){
#Override
public void run() {
// TODO Auto-generated method stub
mHandler.postDelayed(m_handlertask,3000);
condition();
}
int i=3;
private void condition() {
// TODO Auto-generated method stub
if((i % 3 )== 0) //running 1 time
{
birthday();
i++;
}
else //running 2 times
{
images();
i++;
}
}
private void birthday() {
// TODO Auto-generated method stub
try
{
birth = info.getBirth();
Toast.makeText(getApplicationContext(), "This is b'day pic : "+birth, Toast.LENGTH_LONG).show();
//Drawable d = Drawable.createFromPath(birth);
//jpgView.setImageDrawable(d);
File sdCardPath = Environment.getExternalStorageDirectory();
Bitmap bitmap = BitmapFactory.decodeFile(sdCardPath+"/DCIM/Camera/SAMPLE IMAGES/"+path);
jpgView.setImageBitmap(bitmap);
// Bitmap bitmap = BitmapFactory.decodeFile(birth);
// jpgView.setImageBitmap(bitmap);
}
catch(NullPointerException er)
{
String ht=er.toString();
Toast.makeText(getApplicationContext(), ht, Toast.LENGTH_LONG).show();
}
}
private void images() {
// TODO Auto-generated method stub
try
{
path = info.getPath();
Toast.makeText(getApplicationContext(), "This is reg pic : "+path, Toast.LENGTH_LONG).show();
// Drawable d = Drawable.createFromPath(path);
// jpgView.setImageDrawable(d);
File sdCardPath = Environment.getExternalStorageDirectory();
Bitmap bitmap = BitmapFactory.decodeFile(sdCardPath+"/DCIM/Camera/SAMPLE IMAGES/"+path);
jpgView.setImageBitmap(bitmap);
// Bitmap bitmap = BitmapFactory.decodeFile(path);
// jpgView.setImageBitmap(bitmap);
}
catch(NullPointerException er)
{
String ht=er.toString();
Toast.makeText(getApplicationContext(), ht, Toast.LENGTH_LONG).show();
}
}
};
m_handlertask.run();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }
I have read other questions and tutorials, but I found same method of displaying, as I did in the code above. No image is displayed here. I did not find any error message in logcat. Please suggest me, any improvements in the code.
Thanks in advance.
You have a space between "/storage/ sdcard/". You should print the stacktrace to see the Exception using er.printStackTrace(). Also, you shouldn't hardcode the string path; use the Environment Class to reference file locations in a consistent way.
1) Make sure you have given permission to read external storage in your android manifest file.
2)
instead of hard coding the path to external storage use this.
File sdCardPath = Environment.getExternalStorageDirectory();
then add your folder and file name..
Bitmap bitmap = BitmapFactory.decodeFile(sdCardPath+"/DCIM/Camera/img_folder/xxx.png");
jpgView.setImageBitmap(bitmap);
I am pulling my hair out! At one point in the last week, I had this working.
I have an Android app that I am trying to add in-ap billing to. I followed the sample TrivialDrive, and my code worked a few times. Now it doesn't.
I am creating a simple trivia game that has a number of free questions, and the option to upgrade to get more questions. When the user completes the list of free questions, they are taken to a "Game Over" screen where they can erase their answers and start again, or upgrade.
When I click the "Upgrade" button, I can make a successful purchase, but as soon as the Google "Payment Successful" dialog goes away, my activity is destroyed and I am sent back to my main activity.
When I try to go back and do my purchase again, my code catches the error ("You already own this item") and handles it appropriately. My code explains to the user that they already own the upgrade, and allows them to click a button to continue playing. So it looks like the OnIabPurchaseFinishedListener is firing at this point.
I have updated the Google helper code with the latest files.
Any help or suggestions as to where to look for answers is much appreciated.
Thanks.
This is the relevant code for my activity:
public class GameOverActivity extends BaseActivity
{
private IabHelper mHelper;
private String m_base64EncodedPublicKey;
private static String THE_UPGRADE_SKU = "upgrade52";
public static int BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED = 7;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_over);
setTitle("Game Over");
Button butPlay = (Button) findViewById(R.id.buttonPlay);
butPlay.setVisibility(View.INVISIBLE);
PrepareIAB();
}
#Override
protected void onResume()
{
super.onResume();
CURRENT_ACTIVITY = ACTIVITY_GAME_OVER;
SetMainText();
}
#Override
protected void onDestroy()
{
super.onDestroy();
try
{
if (mHelper != null)
{
mHelper.dispose();
mHelper = null;
}
}
catch (Exception e)
{
}
}
private void PrepareIAB()
{
m_base64EncodedPublicKey = "MyKey";
// compute your public key and store it in base64EncodedPublicKey
mHelper = new IabHelper(this, m_base64EncodedPublicKey);
mHelper.enableDebugLogging( true, TAG);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener()
{
public void onIabSetupFinished(IabResult result)
{
if (!result.isSuccess())
{
ShowMessage("There was an error connecting to the Google Play Store.");
}
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
try
{
// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data))
{
// not handled, so handle it ourselves (here's where you'd
// perform any handling of activity results not related to in-app
// billing...
super.onActivityResult(requestCode, resultCode, data);
}
else
{
// Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}
catch (Exception e)
{
super.onActivityResult(requestCode, resultCode, data);
}
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener =
new IabHelper.OnIabPurchaseFinishedListener()
{
public void onIabPurchaseFinished(IabResult result, Purchase purchase)
{
try
{
if (result.isFailure())
{
if (result.mResponse==7)
{
UpgradeComplete();
ShowMessage("Thank you for upgrading.\r\n\r\nThis version has 400 more questions.");
}
else
{
ShowMessage("Error purchasing: " + String.valueOf(result.mResponse));
UpgradeError();
return;
}
}
else if (purchase.getSku().equals(THE_UPGRADE_SKU))
{
UpgradeComplete();
ShowMessage("Thank you for upgrading.\r\n\r\nThis version has 400 more questions.");
}
else
{
ShowMessage("Something else happened. ");
}
}
catch (Exception e)
{
Log.e(TAG, e.getLocalizedMessage());
}
}
};
private void HideUpgrade()
{
try
{
Button btnUpgrade = (Button) findViewById(R.id.buttonUpgrade);
if (btnUpgrade != null)
{
btnUpgrade.setVisibility(View.INVISIBLE);
}
TextView txtMessage = (TextView) findViewById(R.id.txtUpgradeFromGameOver);
if (txtMessage!=null)
{
txtMessage.setVisibility(View.INVISIBLE);
}
}
catch (Exception e)
{
}
}
public void onQuitButtonClick(View view)
{
finish();
}
public void onResetDBButtonClick(View view)
{
ConfirmResetDatabase();
}
private void ConfirmResetDatabase()
{
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener()
{
#Override
public void onClick(DialogInterface dialog, int which)
{
switch (which)
{
case DialogInterface.BUTTON_POSITIVE:
ResetDatabase();
Intent gameActivity = new Intent(getApplicationContext(), GameActivity.class);
gameActivity.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
// startActivityForResult(gameActivity, ACTIVITY_GAME);
startActivity(gameActivity);
break;
case DialogInterface.BUTTON_NEGATIVE:
// No button clicked
break;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Do you want to erase your score and start over?").setPositiveButton("Yes", dialogClickListener).setNegativeButton("No", dialogClickListener).show();
}
public void onUpgradeButtonClick(View view)
{
try
{
if (mHelper != null)
{
mHelper.launchPurchaseFlow(this, THE_UPGRADE_SKU, 10001, mPurchaseFinishedListener, m_TriviaAppInstance.AppInstallID());
}
else
{
ShowMessage("Unable to connect to Google Play Store.");
}
}
catch (Exception e)
{
ShowMessage("Unable to connect to Google Play Store.");
SendErrorMessage(e.getLocalizedMessage());
}
}
private void UpgradeComplete()
{
try
{
HideUpgrade();
Button butPlay = (Button) findViewById(R.id.buttonPlay);
if (butPlay!=null)
{
butPlay.setVisibility(View.VISIBLE);
}
TextView txtReset = (TextView) findViewById(R.id.txtGameOverRestDB);
if (txtReset!=null)
{
txtReset.setVisibility(View.INVISIBLE);
}
Button btnReset = (Button)findViewById(R.id.buttonResetDB);
if (btnReset!=null)
{
btnReset.setVisibility(View.INVISIBLE);
}
m_TriviaAppInstance.SetUpgradedStatus(true);
}
catch (Exception e)
{
}
//
}
private void UpgradeError()
{
try
{
Button butUpgrade;
butUpgrade = (Button) findViewById(R.id.buttonUpgrade);
butUpgrade.setVisibility(View.INVISIBLE);
TextView txtMessage = (TextView) findViewById(R.id.txtUpgradeScreen);
txtMessage.setText(R.string.upgradeScreenTextError);
}
catch (Exception e)
{
}
}
public void onPlayButtonClick(View view)
{
Intent myIntent = new Intent(view.getContext(), GameActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivityForResult(myIntent, ACTIVITY_GAME);
}
public void SetMainText()
{
TextView txt = (TextView) findViewById(R.id.txtScoreGlobal);
txt.setText(Integer.toString(m_TriviaAppInstance.getGlobal()) + "%");
SetPlayerScore(1);
if (m_TriviaAppInstance.getUpgradedStatus() == true)
{
HideUpgrade();
}
}
}
FYI: I think I have this figured out - for anyone else that may come across it.
The activity that I was using to launch "In App Billing" was called with a "FLAG_ACTIVITY_NO_HISTORY". I did this because I didn't want the user to be able to click to go back to this "Game Over" activity.
BUT, this causes grief with "In App Billing". So, make sure you don't try to launch "In App Billing" from an activity that has had the "FLAG_ACTIVITY_NO_HISTORY" set.
My original code:
private void GameOver()
{
m_TriviaAppInstance.setGameOver(true);
Intent gameOver = new Intent(getApplicationContext(), GameOverActivity.class);
gameOver.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(gameOver);
}
Updated code:
private void GameOver()
{
m_TriviaAppInstance.setGameOver(true);
Intent gameOver = new Intent(getApplicationContext(), GameOverActivity.class);
startActivity(gameOver);
}
Peace
I'm not high enough to comment, but bless you. I had
android:noHistory="true"
set in AndroidManifest.xml for my activity and was experiencing the same problem.
Took it out and IAB is working. Yay!
Do not forget that your IabHelper.OnIabPurchaseFinishedListener is called on a different thread and before onResume() is called on your Activity!
So your UpgradeComplete() or UpgradeError() can cause a crash on older devices (Crashed every time on my Gingerbread Sony Xperia Mini Pro and worked without any trouble on Samsung Galaxy S4 (Android 4.2.2)
Caused a 3 day delay on my game..
I have a Form with edittexts and a button to call the camera with an intent (return a bitmap that is put into the imageview)...From the portrait mode i enter all edittext filed and then click the camera button which forwards me to the camera - in the camera i take a picture after what I get returned to Activity 1 (staying in portrait orientation - and all editext fields are restore in onRestoreInstanceState()) - and the last callback method of Activity 1 is onResume() (what is ok) - But the problem comes when I make an orientation change from this portrait to landscape mode - the callback methods are following
So the last callback orientation change is onPause(). I do not understand why? The problem is that onSaveInstanceState is called prior of onPause - so when I turn back to portrait mode everything will be empty (editexts, imageview..) - this strange behavior continues on every orientation change (the onPause() is called last).
I am sure this problem has to do something with the taking an image (startInentforResult....) because everything (editext fields) works fine on orientation change prior to taking an image...sometimes I can also take an image and it works fine, but in most cases not...
So my question is what is it that "drives" my Activity up to the onPause() method instead up to the onResume()?
Thanks, I would really appreciate if somebody knows the solution because I am struggling with this already a few days and could not find the solution.
The project has many classes but this is the activity code (Important to note is that the problem arises only when I take an image from camera app, after that the activity lifecycle goes crazy - also this activity is called from the main activity with 'startIntentforResult()'. I do not use 'android:configChanges="orientation|keyboardHidden"' to stop the recreatioin ):
public class NewCounterActivity extends Activity {
Button btnCreate;
Button btnCancel;
Button btnTakeImg;
ImageView counterImgView;
CheckBox existsDamage;
EditText inputNameFirst;
EditText inputNameLast;
EditText inputAdresse;
EditText inputCounterID;
EditText inputCounterValue;
EditText inputDescription;
TextView registerErrorMsg;
DatabaseHandler db;
//Data to be submitted
String nameFirst;
String nameLast;
String adresse;
String counterID;
String counterValue;
String countDescript;
String existsDmg;
Bitmap counterBitmap;
Bitmap recievedBitmap;
String longitude;
String latitude;
LocationTracker gps;
// JSON Response node names
private static String KEY_SUCCESS = "success";
private static String KEY_ERROR = "error";
private static String KEY_ERROR_MSG = "error_msg";
//The dimensions of the ImageView
int targetW;
int targetH;
// Some lifecycle callbacks so that the image can survive orientation change
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Log.e("onSaveInstanceState", "fadsfass");
outState.putParcelable("bitmap", counterBitmap);
outState.putString("fname", inputNameFirst.getText().toString());
outState.putString("lname", inputNameLast.getText().toString());
outState.putString("adrese", inputAdresse.getText().toString());
outState.putString("cID", inputCounterID.getText().toString());
outState.putString("cValue", inputCounterValue.getText().toString());
outState.putString("Descript", inputDescription.getText().toString());
outState.putString("ErrorMsg", registerErrorMsg.getText().toString());
outState.putBoolean("damageCheck", existsDamage.isChecked());
((MyApplicationClass) getApplication()).detach(this);
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
Log.e("onRestoreInstanceState", "fadsfass");
counterBitmap = savedInstanceState.getParcelable("bitmap");
counterImgView.setImageBitmap(counterBitmap);
inputNameFirst.setText(savedInstanceState.getString("fname"));
inputNameLast.setText(savedInstanceState.getString("lname"));
inputAdresse.setText(savedInstanceState.getString("adrese"));
inputCounterID.setText(savedInstanceState.getString("cID"));
inputCounterValue.setText(savedInstanceState.getString("cValue"));
inputDescription.setText(savedInstanceState.getString("Descript"));
registerErrorMsg.setText(savedInstanceState.getString("ErrorMsg"));
existsDamage.setChecked(savedInstanceState.getBoolean("damageCheck"));
((MyApplicationClass) getApplication()).attach(this);
}
#Override
public void onContentChanged() {
// TODO Auto-generated method stub
super.onContentChanged();
Log.e("onContetnChanged", "fadsfass");
}
#Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.e("onDestroy", "fadsfass");
}
#Override
public void onDetachedFromWindow() {
// TODO Auto-generated method stub
super.onDetachedFromWindow();
Log.e("onDetachedFromWindow", "fadsfass");
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.e("onPause", "fadsfass");
}
#Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
Log.e("onRestart", "fadsfass");
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Log.e("onResume", "fadsfass");
}
#Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Log.e("onStart", "fadsfass");
}
#Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Log.e("onStop", "fadsfass");
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newcounteractivity_layout);
Log.e("onCreate", "mActivity equals NULL");
inputNameFirst = (EditText) findViewById(R.id.createFirstName);
inputNameLast = (EditText) findViewById(R.id.createLastName);
inputAdresse = (EditText) findViewById(R.id.createAdresse);
inputCounterID = (EditText) findViewById(R.id.createCounterID);
inputCounterValue = (EditText) findViewById(R.id.createCounterValue);
inputDescription = (EditText) findViewById(R.id.createDescription);
registerErrorMsg = (TextView) findViewById(R.id.create_error);
btnCreate = (Button) findViewById(R.id.btnCreate);
btnCancel = (Button) findViewById(R.id.btnCancel);
btnTakeImg = (Button) findViewById(R.id.btnImage);
counterImgView = (ImageView) findViewById(R.id.counterImgView);
existsDamage = (CheckBox) findViewById(R.id.createDamageExists);
//REGISTER BUTTON CLICK EVENTS
btnCreate.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//new DoBackgroundTask(NewCounterActivity.this).execute();
//CounterUser data to submit
nameFirst = inputNameFirst.getText().toString().trim();
nameLast = inputNameLast.getText().toString().trim();
adresse = inputAdresse.getText().toString().trim();
counterID = inputCounterID.getText().toString().trim();
counterValue = inputCounterValue.getText().toString().trim();
countDescript = inputDescription.getText().toString().trim();
existsDmg = Integer.toString((existsDamage.isChecked()) ? 1 : 0);
// create LocationTracker class object
gps = new LocationTracker(NewCounterActivity.this);
if(!gps.canGetLocation()){
gps.stopUsingGPS();
gps.showSettingsAlert();
//Ovo se mozda treba i izbaciti
gps.getLocation();
}
else{
processInput();
}
}
});
btnCancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent returnIntent = new Intent();
setResult(RESULT_CANCELED, returnIntent);
finish();
}
});
btnTakeImg.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if(isIntentAvailable(NewCounterActivity.this, MediaStore.ACTION_IMAGE_CAPTURE)){
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent,2);
}
else {
Toast.makeText(NewCounterActivity.this, "No Camera Available", Toast.LENGTH_SHORT).show();
}
}
});
}
/************************************************************************************************
* Methods used in this class
* */
public void processInput(){
//Get current Longitude and Latitude
longitude = Double.toString(gps.getLongitude());
latitude = Double.toString(gps.getLatitude());
//Na kraju iskljuci location updatese - ne moze na emulatru jer ja emit coordinate preko DDMS... a kad emit on mora biti ukljucen da bi primio
//gps.stopUsingGPS();
Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + longitude + "\nLong: " + latitude, Toast.LENGTH_LONG).show();
if (!nameFirst.equals("") && !nameLast.equals("") && !adresse.equals("") && !counterID.equals("") && !counterValue.equals("")
&& counterBitmap != null ){
new DoBackgroundTask(NewCounterActivity.this).execute();
}
else{
// Not all fields are filled
registerErrorMsg.setText("Not all fields are filled");
}
}
//Method to check whether an app can handle your intent
public boolean isIntentAvailable(Context context, String action) {
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent(action);
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
/**************************************************************************************************
*
* When the calling activity, Activity #1, resumes after having called another activity, Activity #2, using startActivityForResult,
* the method onActivityResult in Activity #1 is called BEFORE onResume.
* This is important to know if you are instantiating your SQLite Database objects from within onResume in Activity #1. If so, you will also need to instantiate the object from within onActivityResult,
* when returning from Activity #2.
*
* startActivityForResult() is asynchronous. It can feel synchronous to the user since the UI will change and your calling activity will be paused
* (your onPause() method will be called).
*/
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
Log.e("onActivityResult", "fadsfass");
if (requestCode == 2) {
if(resultCode == RESULT_OK){
Bundle extras = data.getExtras();
recievedBitmap = (Bitmap) extras.get("data");
}
if (resultCode == RESULT_CANCELED) {
Toast.makeText(NewCounterActivity.this, "No Image Taken", Toast.LENGTH_SHORT).show();
}
}
}
/**
* Koristim onWindowFocusChanged jer kad se vratim na Activity 1 onda dodje do potpunog recreate Activitija i getWidth()/height() ne mogu dobiti
* ni u jednom od lifecicle methoda - naime ide start onCreate,...onActivityResult(), onResume() - u onactivityResult izvadim bitmap i pohranim ga u receivedBitmap
* te kad getWidth() postane dostupan system invoke ovu dole methodu. :D
*/
#Override
public void onWindowFocusChanged(boolean hasFocus){
if(recievedBitmap != null){
targetW=counterImgView.getWidth();
targetH=counterImgView.getHeight();
Log.e("onWindowFocusChanged", "fadsfass" + " " + targetW + " " + targetH);
// http://stackoverflow.com/questions/4837715/how-to-resize-a-bitmap-in-android
// http://sunil-android.blogspot.com/2013/03/resize-bitmap-bitmapcreatescaledbitmap.html
// Scale or resize Bitmap to ImageView dimensions
counterBitmap = Bitmap.createScaledBitmap(recievedBitmap, targetW, targetH, false);
/**
* Canvas: trying to use a recycled bitmap android.graphics - This exception occurs when you try to recycle a bitmap which is already recycled.
* http://androdevvision.blogspot.com/2011/10/solution-for-out-of-memory-error-and.html
*/
if(recievedBitmap != null && !recievedBitmap.isRecycled()){
recievedBitmap.recycle();
recievedBitmap = null;
}
counterImgView.setImageBitmap(counterBitmap);
}
}
/************************************************************************************************
* Background AsyncTask to create new counterUser - https://github.com/callorico/CustomAsyncTask - najbolje radi
* new DoBackgroundTask(NewCounterActivity.this).execute();
* */
private static class DoBackgroundTask extends CustomAsyncTask<Void, Integer, JSONObject> {
private static final String TAG = "DoBackgroundTask";
private ProgressDialog mProgress;
private int mCurrProgress;
private NewCounterActivity myActivity = null;
public DoBackgroundTask(NewCounterActivity activity) {
super(activity);
}
#Override
protected void onPreExecute() {
super.onPreExecute();
showProgressDialog();
}
#Override
protected void onActivityDetached() {
if (mProgress != null) {
mProgress.dismiss();
mProgress = null;
}
}
#Override
protected void onActivityAttached() {
showProgressDialog();
}
private void showProgressDialog() {
mProgress = new ProgressDialog(mActivity);
mProgress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgress.setIndeterminate(true);
mProgress.setMessage(" Saljem na server... ");
mProgress.setCancelable(true);
mProgress.setOnCancelListener(new OnCancelListener() {
#Override
public void onCancel(DialogInterface dialog) {
cancel(true);
}
});
mProgress.show();
mProgress.setProgress(mCurrProgress);
}
#Override
protected JSONObject doInBackground(Void... params) {
//so you need to either pass an instance of the outer class to the inner class method (or its constructor) as a parameter,
//or create it inside the method.
JSONObject json = null;
if(mActivity != null){
myActivity = (NewCounterActivity) mActivity;
//Prepare counterBitmap as String
ByteArrayOutputStream stream = new ByteArrayOutputStream();
//Write a compressed version of the bitmap to the specified output stream.
myActivity.counterBitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream);
byte [] b_array = stream.toByteArray();
String bitmapString = Base64.encodeBytes(b_array);
//Get workerId from logged worker
Functions workerFunction = new Functions();
DatabaseHandler db = new DatabaseHandler(mActivity);
String workerID = db.retrieveWorker().get("workerId");
if(myActivity != null){
//Get JsonObject from Functions.java
json = workerFunction.newCounterUser(myActivity.counterID, myActivity.counterValue, myActivity.adresse, myActivity.nameFirst, myActivity.nameLast, bitmapString, myActivity.existsDmg, myActivity.countDescript, workerID, myActivity.longitude, myActivity.latitude);
}
}
return json;
}
#Override
protected void onPostExecute(JSONObject jsonObject) {
super.onPostExecute(jsonObject);
if (mActivity != null) {
mProgress.dismiss();
try {
if (jsonObject.getString(KEY_SUCCESS) != null) {
myActivity.registerErrorMsg.setText("");
String res = jsonObject.getString(KEY_SUCCESS);
if(Integer.parseInt(res) == 1){
// counterUser successfully registered
Toast.makeText(mActivity, "New counterUser is created", Toast.LENGTH_LONG).show();
// Return back to MainActivity
Intent returnIntent = new Intent();
returnIntent.putExtra("result",jsonObject.toString());
mActivity.setResult(RESULT_OK,returnIntent);
// Close all views before launching MainActivity
returnIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mActivity.finish();
}else{
// Error in registration
myActivity.registerErrorMsg.setText("Error occured in registration");
}
}
} catch (JSONException e) {
Log.e("Error","NO Json at all");
e.printStackTrace();
}
} else {
Log.d(TAG, "AsyncTask finished while no Activity was attached.");
}
}
}
Same issues on call to recreate(), when activity has been updated it get onPause after onResume. Tested on emulator, bug exists on Marshallow and below.
This is my fix
private static boolean isRecreate = false;
private void reCreateActivity() {
isRecreate = true;
recreate();
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(isRecreate) {
isRecreate = false;
runOnUiThread(new Runnable() {
#Override
public void run() {
onResume();
}
});
}
}
I don't know if that's correct, but it works.
EDIT
Best solution to avoid this issues, call recreate in postDelayed with 0 delayMillis
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
recreate();
}
}, 0);
It is only normal, that strange code produces strange behavior ...
replace this line:
((MyApplicationClass) getApplication()).detach(this);
with this line:
super.onSaveInstanceState(outState);
I was trying to do some data loading in Splash page in my app using asynctask, but the app stuck at the splash screen, and logcat print:
Default buffer size used in BufferedOutputStream constructor. It would be better to be explicit if an 8k buffer is required.
Here are my code
package com.appkon.hdtvs;
public class Splash extends Activity {
private ChannelDB mDB;
private TextView loading;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
AppConnect.getInstance(this);
loading =(TextView)findViewById(R.id.loading);
}
private class SetDB extends AsyncTask<String, String, String> {
#Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
try {
if (tabIsExist(null)==true){
mDB.Reset();
Bitmap bigbang1 = BitmapFactory.decodeResource(getResources(), R.drawable.bigbang1);
Bitmap bigbang2 = BitmapFactory.decodeResource(getResources(), R.drawable.bigbang2);
mDB.createchannelEntry(new ChannelPoster(castle4, "灵书妙探 (第四季)" ,"http://appkon.com/hdtvs/channel/castle4.xml" ,"http://movie.douban.com/subject/6742616/" ));
mDB.createchannelEntry(new ChannelPoster(castle3, "灵书妙探 (第三季)" ,"http://appkon.com/hdtvs/channel/castle4.xml" ,"http://movie.douban.com/subject/4836898/" ));
}
}catch (Exception e) {
Intent i = new Intent();
i.setClassName("com.appkon.hdtvs",
"com.appkon.hdtvs.HDtvs");
finish();
startActivity(i);
}
return null;
}
protected void onProgress(String load) {
loading.setText("载入中···");
}
protected void onPostExecute(String finish) {
loading.setText("载入完成");
}
}
public boolean tabIsExist(String channelS_TABLE){
boolean result = false;
if(channelS_TABLE == null){
return false;
}
Cursor cursor= ChannelDB.check();
startManagingCursor(cursor);
try {
if(cursor.moveToNext()){
int count = cursor.getInt(0);
if(count>0){
result = true;
}
}
} catch (Exception e) {
Log.e(this.toString(),"error:"+e.toString());
Intent intent = new Intent(this,HDtvs.class);
startActivity(intent);
this.finish();
}
return result;
}
}
So what seem to be the problem? Is that because my res images are too big.
Somewhere a BufferedOutputStream is used but not constructed with a size (second argument). Maybe you used libs do the mess.
i am using google transalate api in my application,i have done in text conversion is ok
but translate-text to speech is pending
http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html
this code i am using how can implement translate text voice in android.
http://www.freeimagehosting.net/uploads/c382dd10f8.png
this above screenshot display text conversion is ok,click audiobutton image listen translate text in audioplayer how can implemented
my code
//audio button click event..........
submit = (ImageView) findViewById(R.id.ImageView01);
submit.setOnClickListener(new View.OnClickListener()
{ public void onClick(View v)
{
//speech code how can implemented
}
});
/////////////////// translate button code//////////////////////
((Button)findViewById(R.id.Button01)).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
String fromLan=spineFrom.getSelectedItem().toString();
String toLan=spineTo.getSelectedItem().toString();
Log.v("check",fromLan+" :"+toLan);
translatedText = Translate.execute(((EditText)findViewById(R.id.EditText01)).getText().toString(),converStrtoLan(fromLan),converStrtoLan(toLan));
((TextView)findViewById(R.id.TextView02)).setText(translatedText);
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent,1);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
private TextToSpeech mTts;
protected void onActivityResult(
int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// success, create the TTS instance
mTts = new TextToSpeech(this, null);
} else {
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(
TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
mTts.setLanguage(Locale.US);
String myText1 = "Did you sleep well?";
String myText2 = "I hope so, because it's time to wake up.";
mTts.speak(myText1, TextToSpeech.QUEUE_FLUSH, null);
mTts.speak(myText2, TextToSpeech.QUEUE_ADD, null);
}
private Language converStrtoLan(String lan){
if(lan.equals("ENGLISH") || lan=="ENGLISH"){
return Language.ENGLISH;
}else if (lan.equals("SPANISH") || lan=="SPANISH"){
return Language.SPANISH;
}
return null;
}
}
how can add this audio code in audio click event ,
please forward some valuable response of this code this issue i am struggle for more number of days thanks in advance ..
In order to do Text To Speech with Android you can use eyes-free library