sqlite SQLiteStatement please help with extending my INSERT statement - Android Software/Hacking General [Developers Only]

HI,
I am new to android and I am experimenting with sqlite. I would like
to extend my SQL insert statement so I can insert into more than one
row.
I have extended my table as follows including a column called actor
db.execSQL("CREATE TABLE " + TABLE_NAME + "(id INTEGER PRIMARY KEY,
name TEXT, actor TEXT");
I am using SQLiteStatement and would like to extend the insert to
include actors along with names
private static final String TABLE_NAME = "testtable ";
private SQLiteStatement insertStmt;
private static final String INSERT = "insert into "
+ TABLE_NAME + "(name) values (?)"; <----------------where is
name coming from ?????
This is my insert function, but how can I call it and execute an
INSERT to include the column actor
public long insert(String name) {
this.insertStmt.bindString(1, name);
return this.insertStmt.executeInsert();
}
call to use insert
this.dh.insert("Inception");
I would like to change this to
this.dh.insert("Inception", "Leo");
Thank you
Graham

Related

MediaPlayer.setDataSource(url) not working

MediaPlayer.setDataSource(url) is not working in my app.
Im puttin the file "hello.mp3" in the assets-folder, and Im using the following
Code:
String soundUrl = "file:///android_asset/hello.mp3";
mp = new MediaPlayer();
try {
mp.setDataSource(soundUrl);
mp.prepare();
mp.start();
}
catch (IOException e) {}
catch (IllegalArgumentException e) {}
catch (IllegalStateException e) {}
This code works when I put the "hello.mp3" in the res/raw-folder:
Code:
mp = new MediaPlayer();
mp = MediaPlayer.create(getBaseContext(), R.raw.hello);
mp.start();
Problem with the last code is that I need to load the sound-files dynamically, and apparently you cant create a string or a uri with the correct sound-file at the end and insert that as the second parameter in the MP.create()-function.
Pseudocode - NOT WORKING
Code:
String mySound = "hello";
Uri myUri = "R.raw." + mySound;
...
mp = MediaPlayer.create(getBaseContext(), myUri);
Any ideas?
Amazing, several months later and still no one is able to realte how to play a local sound dynamically.
An issue with what you are trying to do is that there are multiple versions of MediaPlayer.create() and MediaPlayer.setDataSource() which take different types of parameters.
R.raw.hello is NOT a string. It is an int. Look in the gen directory to find the generated file R.java and in this file you will find raw which has a public static final int definition for R.raw.hello
R.raw.hello has to be passed to one of the routines which takes an int for the parameter and not a string.

sqlite database items don't show up in listview

I have a simple Sql lite database that just has an “ _id” column, a “word” column and a “definition” column. I can open the database, do queries on it and get the data back properly. Apparently, I can’t bind the data to a listview using a SimpleCursorAdapter.
I query the database to return a cursor containing just the “_id” column below:
String[] from = new String[] {"_id"};
int[] to = new int[] { android.R.id.text1};
c = mydatabase.query("words",from, null, null, null,null,null);
startManagingCursor(c);
When I do, the cursor contains one column and 4095 rows like I think that it should.
//c.getcount=4095
//c.getColumnCount = 1;
Next, I try to bind a SimpleCursorAdapter to my listview01 as shown below. I am trying to bind the “_id” column to a listview with one item per row.
adapter = new SimpleCursorAdapter(
this,android.R.layout.simple_list_item_1,
c,
from,
to);
listview01.setAdapter(adapter);
Nothing bombs, but nothing shows up on the listview. Any suggestions?

[Q] Need help to populate a listview from external source

I'm pretty new to java and somewhat new to android and I've been looking everywhere for the past 3 or 4 days but cant seem to find the answer to my question. I'm making an app that is pretty simple and has only one real main function and that is to pull movie names, release dates, and the movie's format (dvd, blu-ray etc) into the app automatically from a very simple file that I will host on my server.
Now I I'm currently able to input the needed information manually via a base-adapter and a strings file within each months activity but I want to have the ability to push the information remotely which will then give my app (and myself) the ability to update the information as well as to place it into the 3 line listview format that I've already established.
Now I've been reading about Simple:XML, gson, SAX, etc but seeing as the information is just 3 small lines of text (again just the movie name, date and format which doesn't use much space and will be using the same string format for all 12 months) my question is what would be the best route as to the format of the file (i.e. xml, json, plain text, etc) and how would I go about getting this information into my app on the fly? I've included some code snippets below in the hopes they will make my question a little more clear.
I've posted this on several other forums and android dev sites and nobody seems to be able to give me some guidance or simply will not reply at all. I cannot continue on my app until I'm able to figure this out and seeing as it is completed aside from this problem it is becoming a very frustrating experience. I'm hopeful that someone here will be able to give my some help out. Thank you in advance.
The string for each result
Code:
public class SearchResults {
private String Name = "";
private String Date = "";
private String Format = "";
public String getName() {
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
public String getDate() {
return Date;
}
public void setDate(String Date) {
this.Date = Date;
}
public String getFormat() {
return Format;
}
public void setFormat(String Format) {
this.Format = Format;
}
This below is where the actual list-view is populated and shown. Each new search result creates a three line text-view.
Code:
private ArrayList<SearchResults> GetSearchResults(){
ArrayList<SearchResults> results = new ArrayList<SearchResults>();
SearchResults sr1 = new SearchResults();
sr1.setName("Movie #1");
sr1.setDate("July 24th");
sr1.setFormat("DVD, Blu-Ray");
results.add(sr1);
sr1 = new SearchResults();
sr1.setName("Movie #2");
sr1.seDate("July 19th");
sr1.setFormat("DVD, Blu-Ray, Digital");
results.add(sr1);
return results;
}
Can anybody help me with this please?

How and where my device store fingerprint results and matches with my next attempt ?

MAIN QUESTION IS AT BOTTOM
Where my android devices stores scanned fingerprint data and in what format and how it matches with new scanned.
I also know this: :the scan of fingertip is analysed for certain control points and generates a token which is like a password hash.
It generates hash via this:
Code:
KeyStore mKeyStore;
String KEY_NAME = UUID.randomUUID().toString();
Cipher mCipher;
mKeyStore = KeyStore.getInstance("AndroidKeyStore");
keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
keyGenerator.init(new
KeyGenParameterSpec.Builder(KEY_NAME,
KeyProperties.PURPOSE_ENCRYPT |
KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
.setUserAuthenticationRequired(true)
.setEncryptionPaddings(
KeyProperties.ENCRYPTION_PADDING_PKCS7)
.build());
keyGenerator.generateKey();
mCipher = Cipher.getInstance(
KeyProperties.KEY_ALGORITHM_AES + "/"
+ KeyProperties.BLOCK_MODE_CBC + "/"
+ KeyProperties.ENCRYPTION_PADDING_PKCS7);
SecretKey key = (SecretKey) mKeyStore.getKey(KEY_NAME, null);
mCipher.init(Cipher.ENCRYPT_MODE, key);
Is editing/extracting or using this hash and storing somewhere else and try to match the newly generated hash with this while storing that security key of android(assuming same for all), is it possible OR ANY OTHERWAY ROUND?
ALSO
Code:
KeyStore ks = KeyStore.getInstance("AndroidKeyStore");
ks.load(null);
KeyStore.Entry entry = ks.getEntry(alias, null);
if (!(entry instanceof PrivateKeyEntry)) {
Log.w(TAG, "Not an instance of a PrivateKeyEntry");
return null;
}
Signature s = Signature.getInstance("SHA256withECDSA");
s.initSign(((PrivateKeyEntry) entry).getPrivateKey());
s.update(data);
byte[] signature = s.sign();
boolean valid = s.verify(signature);
I saw this, but can't say helpful or not

MMS to iPhone different behavior...

private static final String TEXT_PART_FILENAME = "notify.htm";
private static final String sSmilText =
"<smil>" +
"<head>" +
"<layout>" +
"<root-layout/>" +
"<region height=\"100%%\" id=\"Text\" left=\"0%%\" top=\"0%%\" width=\"100%%\"/>" +
"</layout>" +
"</head>" +
"<body>" +
"<par dur=\"8000ms\">" +
"<text src=\"%s\" region=\"Text\"/>" +
"</par>" +
"</body>" +
"</smil>";
PduBody body = new PduBody();
PduPart part = new PduPart();
// Set Charset if it's a text media.
part.setCharset(CharacterSets.UTF_8);
// Set Content-Type.
part.setContentType(ContentType.TEXT_HTML.getBytes());
// Set Content-Location
part.setContentLocation(TEXT_PART_FILENAME.getBytes());
int index = TEXT_PART_FILENAME.lastIndexOf(".");
String contentId = (index == -1) ? TEXT_PART_FILENAME
: TEXT_PART_FILENAME.substring(0, index);
part.setContentId(contentId.getBytes());
part.setData("https://www.google.com".getBytes());
body.addPart(part);
final String smil = String.format(sSmilText, TEXT_PART_FILENAME);
addSmilPart(body, smil);
// added some gif data as well...omitted for brevity.
private static void addSmilPart(PduBody pb, String smil) {
final PduPart smilPart = new PduPart();
smilPart.setContentId("smil".getBytes());
smilPart.setContentLocation("smil.xml".getBytes());
smilPart.setContentType(ContentType.APP_SMIL.getBytes());
smilPart.setData(smil.getBytes());
pb.addPart(0, smilPart);
}
Above is some code I found from some web site..and I tested it..then it is working fine...
When I sent MMS to an android phone, I see the clickable http link, "https://www.google.com".........
However, when I sent the same one to an iPhone user, then...they received "notify.htm" like an attachment..then they needed to tap the file..then they saw the clickable link to navigate...
Is there any way I could change somehow this code so that I could provide the same behavior like an Android user for an iPhone user as well?.. I don't want to send like an attached file..
Thanks,
P.s : BTW, I am not sure whether I am posting this under right category. If not, admin, could you please move this to the right category?

Categories

Resources