on Sunday, August 31, 2014


So, what I am trying to do is to make a semi-automatic page monitor which alerts user when some part of screen has changed, and the biggest benefit of my app is that user can record some actions because some login or register forms are changing by clicking JavaScript element, not just by refreshing. What I've done so far is that I made zoomable WebView and programmed a button which starts and stops touch movement recording. Everything works like a charm, except when user presses JavaScript spinner. When it appears, my app stops recording touches, and also, android layout buttons hide. So, what I want to do is to force my touch recording system to respond to every possible element, event it is written in JavaScript. Here is my code:



package com.example.automatikaandroidui;

import java.util.ArrayList;

import android.support.v7.app.ActionBarActivity;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.PointF;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity implements OnClickListener, OnTouchListener {

WebView webView;
Button mygtukasSeka;
boolean isPressed = false;
boolean halfWay = false;
boolean eile = false;
ArrayList<PointF> masyvas = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
masyvas = new ArrayList<PointF>();

webView = (WebView)findViewById(R.id.webView1);
webView.loadUrl("https://www.eregitra.lt/viesa/interv/Index.php");
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webView.setOnTouchListener(this);


mygtukasSeka = (Button)findViewById(R.id.mygtukas_seka);
mygtukasSeka.setOnClickListener(this);
}

@Override
public void onClick(View v) {

switch(v.getId()){

case R.id.mygtukas_seka: {
TextView notify = (TextView)findViewById(R.id.ispek_irasyma);

if(!isPressed){

notify.setTextColor(Color.RED);
notify.setText("Įrašoma...");
isPressed = true;

}

else {
notify.setText("");
isPressed = false;
}
}

}

}

@Override
public boolean onTouch(View v, MotionEvent event) {

switch (event.getActionMasked()){

case MotionEvent.ACTION_DOWN : {
if(!halfWay && isPressed)
halfWay = true;
}

case MotionEvent.ACTION_UP : {
if(halfWay && isPressed){
PointF taskas = new PointF(event.getX(),event.getY());
masyvas.add(taskas);
halfWay = false;
Toast.makeText(MainActivity.this, taskas.x+" "+taskas.y, Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, masyvas.size()+"", Toast.LENGTH_SHORT).show();
}
}

}

if(isPressed){
if(eile)
eile = false;
else eile = true;
}

return eile;
}

}


And here are some screenshots : Here is the registration form. When you press on B spinner appears, and when you change different element from it, all page refreshes. As you can see there are three buttons on the bottom, and the middle one called Seka records touches.


http://i.stack.imgur.com/UJxjg.png


There is spinner that I've talked before. Ignore toast message


http://i.stack.imgur.com/ekWTo.png


Thanks in advance ! :)




This my code used for usage of key store to save an arbitrary text as a key in the keystore how I am getting the "Keystore is not initialized error", how can I fix this?



public void secretKeyGeneration(View view) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {

KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
byte[] sek = "eru9tyighw34ilty348934i34uiq34q34ri".getBytes();
SecretKey sk = new SecretKeySpec(sek, 0, sek.length, "AES");
char[] password = "keystorepassword".toCharArray();
KeyStore.ProtectionParameter protParam =
new KeyStore.PasswordProtection(password);

KeyStore.SecretKeyEntry skEntry = new KeyStore.SecretKeyEntry(sk);
ks.setEntry("secretKeyAlias", skEntry, protParam);

}



What I am trying to accomplish is, starting from an app's ActivityInfo (third party app), I would like to launch it from my Service in the state it was. In the same way that if an user presses the home button and there touches, for example, Whatsapp's icon, Whatsapp will launch to the conversation he previously was. I have managed to launch any app. What I don't know is how to launch the app to the previous state, that is, the particular conversation I (or the user) was in -assuming it is still in memory, of course.


I first tried:



ActivityInfo app = (ActivityInfo) getActivityInfo();
String packName = app.packageName;
Intent appIntent = pm.getLaunchIntentForPackage(packName);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(appIntent);


Then I tried:



ActivityInfo app = (ActivityInfo) getActivityInfo();
String packName = app.packageName;
Intent appIntent = pm.getLaunchIntentForPackage(packName);
appIntent.setFlags(0);
appIntent.setPackage(null);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(appIntent);


I have also tried:



ActivityInfo app = (ActivityInfo) getActivityInfo();
Intent appIntent = new Intent();
appIntent.setComponent(new ComponentName(app.applicationInfo.packageName, app.name));
appIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(appIntent);


So, does anyone know how to achieve this?




I am making a system (Android) for my software engineering class and this is a brief description of the system: It is an app for a gym that shows the list of the workouts that can be done. This is the step-by-step processes that I made for the system:




  1. Admin log in (in order to access the app- only the admin can open the app because the app serves as a kioks) THIS PART IS DONE




  2. Current Users page (this is a page that shows who are currently using the app in the gym) this part is not done yet but I am doing this part by database: DESCRIPTION: a. users are required to register to the app (done by database: involves username and password columns) b. if the user is registered and ready to add into current users they will login their username and password




  3. User Workout page (after logging in from current users page this page will show) this part is not done yet DESCRIPTION: a. This page shows the user's history workout (I need a suggestion on how will I record the workout history, is it from database?) b. If the user wants a NEW WORKOUT it will display a ListView of workouts (please read this, this is where I have a hard time) i. Each Workout has: (name, muscletype, rating, machineOrNot, videopath) ii. I am having a hard time putting many workouts in a database, I tried parsing it from XML file and somewhat I know the entries get inserted successfully but i cant make it into the listview for nullpointerexception error




I really need some advices in order to successfully program the system. Also, each workouts has a video in what way I can link it to each workouts?


Thank you all!




Im trying to export android apk with proguard, however this error occured :



Users/thanhnguyen/Documents/mr thao's music/android-sdk-macosx/tools/proguard/bin/proguard.sh: line 10: "/Users/thanhnguyen/Documents/mr thao's music/android-sdk-macosx/tools/proguard": No such file or directory
Unable to access jarfile /Users/thanhnguyen/Documents/mr
at com.android.ide.eclipse.adt.internal.build.BuildHelper.runProguard(BuildHelper.java:623)
at com.android.ide.eclipse.adt.internal.project.ExportHelper.exportReleaseApk(ExportHelper.java:259)
... 4 more


It seems that I must configure file proguard.sh, the default is :



PROGUARD_HOME=`dirname "$0"`/..

java -jar $PROGUARD_HOME/lib/proguard.jar "$@"


My proguard.jar is at : /Users/thanhnguyen/Documents/mr thao's music/android-sdk-macosx/tools/proguard on Mac OS.


I tried to set but didn't work :



PROGUARD_HOME="\"/Users/thanhnguyen/Documents/mr thao's music/android-sdk-macosx/tools/proguard\""

java -jar "$PROGUARD_HOME/lib/proguard.jar" "$@"


How could I change proguard.sh, if not change, what could be the rearson for proguard error?


Thanks a lot!




Hi everyone i start Learning android and i want to make a login registration system with my app but is not working properly here the code where i think i've got an error.


PHP LOGIN SCRIPT :



<?php

//load and connect to MySQL database stuff
require("config.inc.php");

if (!empty($_POST)) {
//gets user's info based off of a username.
$query = "
SELECT
id,
username,
password
FROM users
WHERE
username = :username
";

$query_params = array(
':username' => $_POST['username']
);


try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
// For testing, you could use a die and message.
//die("Failed to run query: " . $ex->getMessage());

//or just use this use this one to product JSON data:
$response["success"] = 0;
$response["message"] = "Database Error1. Please Try Again!";
die(json_encode($response));

}

//This will be the variable to determine whether or not the user's information is correct.
//we initialize it as false.
$validated_info = false;

//fetching all the rows from the query
$row = $stmt->fetch();
if ($row) {
//if we encrypted the password, we would unencrypt it here, but in our case we just
//compare the two passwords
if ($_POST['password'] === $row['password']) {
$login_ok = true;
}
}

// If the user logged in successfully, then we send them to the private members-only page
// Otherwise, we display a login failed message and show the login form again
if ($login_ok) {
$response["success"] = 1;
$response["message"] = "Login successful!";
die(json_encode($response));
} else {
$response["success"] = 0;
$response["message"] = "Invalid Credentials!";
die(json_encode($response));
}
} else {
$response["message"] = "Enter username and password!";
die(json_encode($response));
}
?>
<h1>Login</h1>
<form action="login.php" method="post">
Username:<br />
<input type="text" name="username" placeholder="username" />
<br /><br />
Password:<br />
<input type="password" name="password" placeholder="password" value="" />
<br /><br />
<input type="submit" value="Login" />
</form>
<a href="register.php">Register</a>
<?php


?>


LoginActivity :



public class LoginActivity extends ActionBarActivity {
Button btnLogin;
Button btnLinkToRegister;
EditText inputEmail;
EditText inputPassword;
TextView loginErrorMsg;

private ProgressDialog pDialog;

JSONParser jsonParser = new JSONParser();

// JSON Response node names
private static String KEY_SUCCESS = "success";
private static String KEY_ERROR = "error";
private static String KEY_ERROR_MSG = "error_msg";
private static String KEY_UID = "uid";
private static String KEY_NAME = "name";
private static String KEY_EMAIL = "email";
private static String KEY_CREATED_AT = "created_at";
private static final String TAG_MESSAGE = "message";

// Testing on emulator
private static String LOGIN_URL = "http://10.0.2.2/webservice/login.php";

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.login);

// Importing all assets like buttons, text fields
inputEmail = (EditText) findViewById(R.id.loginEmail);
inputPassword = (EditText) findViewById(R.id.loginPassword);
btnLogin = (Button) findViewById(R.id.btnLogin);
btnLinkToRegister = (Button) findViewById(R.id.btnLinkToRegisterScreen);
loginErrorMsg = (TextView) findViewById(R.id.login_error);

// Login button Click Event
btnLogin.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {
new LoginProcess().execute();

}
});

// Link to Register Screen
btnLinkToRegister.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {
Intent i = new Intent(getApplicationContext(),
RegisterActivity.class);
startActivity(i);
finish();
}
});

}

private class LoginProcess extends AsyncTask<String, String, String> {

@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(LoginActivity.this);
pDialog.setMessage("Attempting login...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();

}

@Override
protected String doInBackground(String... args) {
// Check for success tag
int success;
String username = inputEmail.getText().toString();
String password = inputPassword.getText().toString();
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", username));
params.add(new BasicNameValuePair("password", password));

Log.d("request!", "starting");
// getting product details by making HTTP request
JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "POST",
params);

// check your log for json response
Log.d("Login attempt", json.toString());

// json success tag
success = json.getInt(KEY_SUCCESS);
if (success == 1) {
Log.d("Login Successful!", json.toString());
Intent i = new Intent(LoginActivity.this,
MainActivity.class);
finish();
startActivity(i);
return json.getString(TAG_MESSAGE);
} else {
Log.d("Login Failure!", json.getString(TAG_MESSAGE));
return json.getString(TAG_MESSAGE);

}
} catch (JSONException e) {
e.printStackTrace();
}

return null;
}

/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once product deleted
pDialog.dismiss();
if (file_url != null) {
Toast.makeText(LoginActivity.this, file_url, Toast.LENGTH_LONG).show();
}

}

}
}


JSONParser Class:



public class JSONParser {

static InputStream is = null;
static JSONObject jObj = null;
static String json = "";

// constructor
public JSONParser() {

}

public JSONObject getJSONFromUrl(String url, List<NameValuePair> params) {

// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));

HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "n");
}
is.close();
json = sb.toString();
Log.e("JSON", json);
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}

// try parse the string to a JSON object
Log.d("JSON Parser", json);
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}

// return JSON String
return jObj;

}

public JSONObject makeHttpRequest(String url, String method,
List<NameValuePair> params) {
// Making HTTP request
try {

// check for request method
if(method == "POST"){
// request method is POST
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));

HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();

}else if(method == "GET"){
// request method is GET
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);

HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}

// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}

// return JSON String
return jObj;

}
}


When i want to login with the right username and password it's working but if i put right username and wrong password i've got an error . But if i delete query_params at : $result = $stmt->execute($query_params);


I don't have any errors but i can't login anymore


The logcat :



08-31 10:40:39.885: E/Trace(1239): error opening trace file: No such file or directory (2)
08-31 10:40:40.785: D/dalvikvm(1239): GC_FOR_ALLOC freed 118K, 2% free 10936K/11143K, paused 55ms, total 57ms
08-31 10:40:40.845: I/dalvikvm-heap(1239): Grow heap (frag case) to 13.346MB for 2764816-byte allocation
08-31 10:40:40.954: D/dalvikvm(1239): GC_CONCURRENT freed 1K, 2% free 13635K/13895K, paused 24ms+6ms, total 108ms
08-31 10:40:41.334: D/libEGL(1239): loaded /system/lib/egl/libEGL_emulation.so
08-31 10:40:41.345: D/(1239): HostConnection::get() New Host Connection established 0x2a126450, tid 1239
08-31 10:40:41.357: D/libEGL(1239): loaded /system/lib/egl/libGLESv1_CM_emulation.so
08-31 10:40:41.376: D/libEGL(1239): loaded /system/lib/egl/libGLESv2_emulation.so
08-31 10:40:41.455: W/EGL_emulation(1239): eglSurfaceAttrib not implemented
08-31 10:40:41.465: D/OpenGLRenderer(1239): Enabling debug mode 0
08-31 10:40:45.545: D/request!(1239): starting
08-31 10:40:45.645: W/EGL_emulation(1239): eglSurfaceAttrib not implemented
08-31 10:40:48.205: E/JSON Parser(1239): Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
08-31 10:40:48.355: W/dalvikvm(1239): threadid=11: thread exiting with uncaught exception (group=0x40a13300)
08-31 10:40:48.754: E/AndroidRuntime(1239): FATAL EXCEPTION: AsyncTask #1
08-31 10:40:48.754: E/AndroidRuntime(1239): java.lang.RuntimeException: An error occured while executing doInBackground()
08-31 10:40:48.754: E/AndroidRuntime(1239): at android.os.AsyncTask$3.done(AsyncTask.java:299)
08-31 10:40:48.754: E/AndroidRuntime(1239): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
08-31 10:40:48.754: E/AndroidRuntime(1239): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
08-31 10:40:48.754: E/AndroidRuntime(1239): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
08-31 10:40:48.754: E/AndroidRuntime(1239): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-31 10:40:48.754: E/AndroidRuntime(1239): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
08-31 10:40:48.754: E/AndroidRuntime(1239): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-31 10:40:48.754: E/AndroidRuntime(1239): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
08-31 10:40:48.754: E/AndroidRuntime(1239): at java.lang.Thread.run(Thread.java:856)
08-31 10:40:48.754: E/AndroidRuntime(1239): Caused by: java.lang.NullPointerException
08-31 10:40:48.754: E/AndroidRuntime(1239): at com.example.diycenter.LoginActivity$LoginProcess.doInBackground(LoginActivity.java:118)
08-31 10:40:48.754: E/AndroidRuntime(1239): at com.example.diycenter.LoginActivity$LoginProcess.doInBackground(LoginActivity.java:1)
08-31 10:40:48.754: E/AndroidRuntime(1239): at android.os.AsyncTask$2.call(AsyncTask.java:287)
08-31 10:40:48.754: E/AndroidRuntime(1239): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-31 10:40:48.754: E/AndroidRuntime(1239): ... 5 more
08-31 10:40:51.844: E/WindowManager(1239): Activity com.example.diycenter.LoginActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4148a190 that was originally added here
08-31 10:40:51.844: E/WindowManager(1239): android.view.WindowLeaked: Activity com.example.diycenter.LoginActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4148a190 that was originally added here
08-31 10:40:51.844: E/WindowManager(1239): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
08-31 10:40:51.844: E/WindowManager(1239): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
08-31 10:40:51.844: E/WindowManager(1239): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
08-31 10:40:51.844: E/WindowManager(1239): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
08-31 10:40:51.844: E/WindowManager(1239): at android.view.Window$LocalWindowManager.addView(Window.java:547)
08-31 10:40:51.844: E/WindowManager(1239): at android.app.Dialog.show(Dialog.java:277)
08-31 10:40:51.844: E/WindowManager(1239): at com.example.diycenter.LoginActivity$LoginProcess.onPreExecute(LoginActivity.java:96)
08-31 10:40:51.844: E/WindowManager(1239): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
08-31 10:40:51.844: E/WindowManager(1239): at android.os.AsyncTask.execute(AsyncTask.java:534)
08-31 10:40:51.844: E/WindowManager(1239): at com.example.diycenter.LoginActivity$1.onClick(LoginActivity.java:69)
08-31 10:40:51.844: E/WindowManager(1239): at android.view.View.performClick(View.java:4084)
08-31 10:40:51.844: E/WindowManager(1239): at android.view.View$PerformClick.run(View.java:16966)
08-31 10:40:51.844: E/WindowManager(1239): at android.os.Handler.handleCallback(Handler.java:615)
08-31 10:40:51.844: E/WindowManager(1239): at android.os.Handler.dispatchMessage(Handler.java:92)
08-31 10:40:51.844: E/WindowManager(1239): at android.os.Looper.loop(Looper.java:137)
08-31 10:40:51.844: E/WindowManager(1239): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-31 10:40:51.844: E/WindowManager(1239): at java.lang.reflect.Method.invokeNative(Native Method)
08-31 10:40:51.844: E/WindowManager(1239): at java.lang.reflect.Method.invoke(Method.java:511)
08-31 10:40:51.844: E/WindowManager(1239): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-31 10:40:51.844: E/WindowManager(1239): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-31 10:40:51.844: E/WindowManager(1239): at dalvik.system.NativeStart.main(Native Method)


Thank you




In my android application am doing voice recording operation. Just am getting the path and storing as a String object. But when i try to save in the Sqlite, IT throws SqliteException : no such column. I tried to print the String and am getting this path - /storage/sdcard/rec_31_8_201462058.mp3. Can someone help me why i can't store this value in Sqlite. Thanks in advance.