Add Words to Android's UserDictionary - android

I want to add an entire medical dictionary to my android phone (Moto Droid). I would like to be able to send text messages and have the medical words be in the predictable text.
I've been trying to write a small app that would accomplish this, but everything I try the app crashes on startup. I've never written an app for a mobile platform so that is a first for me. Here is what is not working properly.
public class WordAdd extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
UserDictionary.Words.addWord( this , "newMedicalWord", 1, UserDictionary.Words.LOCALE_TYPE_CURRENT);
}
}
It seems so simple to do, yet I am so stuck. Thanks for any help you can provide.
EDIT: I should mention that I am getting this error for Android 2.1 in the AVD (virtual device).
EDIT 2: User Dictionary is found in the Android API. addWord is a static method. I don't declare UserDictionary because I just use the one static method. It's been ages since I developed anything in Java and this is my first attempt at any mobile development, so I don't know if I am doing something wrong.

Add this to your app's AndroidManifest.xml file outside of the <application> element:
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY"></uses-permission>

Try setting a breakpoint at the start of your activity and stepping through the code with the debugger. This should help you isolate whether that call is really what is causing the crash, and what the underlying exception is.

mm mm where UserDictionary is defined? maybe you should just
UserDictionary = new UserDictionaryType();
UserDictionary.Words = new WordsType();
OR define in the class just under the class declaration the fallowing :
static UserDictionaryType UserDictionary;
if that's the case it's obvious why your app crashed ... (do it on kernel mode and "Houston we got a problem" you cant access pointer that you didnt allocated memory for even in java which is managed code... )
but again I am not familiar with your code show us where it defined and I would try to help you more ...
EDIT1: even if UserDictionary exists in the API you didn't declare on one...
you should declare somewhwere static UserDictionary ud = new UserDictionary();

Related

Is it okay to use emojis in Logcat logs?

I am using emojis in log cat messages in order to make the logs easier on the eye. So far it works fine, but I wonder if I'll hit any character compatibility issues on older Android devices. My app's minimumSdkVersion is 16.
Examples:
companion object {
private const val TAG = "\uD83D\uDD36SomeClass"
}
...
Log.d(TAG, "⏰ Something happened!")
Is there anything I should be worried about? Are there any reasons against doing this?
Not sure about your emojis in Logcat but I think that if you want to make your life easier use the TAG that inside your Log.d.
For example, here is a log with a custom TAG:
Log.d("myTag","something to show");
After you run your app all you need to do is to search the same tag name within your logcat, like this:
Another thing that you should think about that if you want to search for a specific log would it be comfortable to search the logcat using emojis?
In my opinion, simply searching your tag name to find your log makes thing super easy.

Unity ScriptableObject is missing on mobile build

I have a MonoBehaviour class that has a property referencing another class which is ScriptableObject.
I've created several prefabs of my first class and created several ScriptableObjects of my second class, I've referenced them in the first class respectively.
In the editor everything works fine, except sometimes my so are shown in the Inspector as Missing Script and in property reference as NameOfSO (), don't know what causing this, but again, Play in the Editor is working just fine.
If build my game for Android and connect to the Debug, to see what's going on, I can clearly see, that's ScriptableObject reference is null. Why? Don't know, came here to ask a question.
Thanks!
I figured it out, turns out this was happening because of the weird thing with namings.
Allow me to explain, when I first created a class from ScriptableObject I used, lets say, MyClas name, I've created several instances of that class, but then I saw the error in the name of the class, I've changed it to the MyClass but only in the file itself, not the actual .cs file, so, this was happening. All I had to do is to ensure that my class and my file names are the same, delete old instances of ScriptableObject and create new ones from scratch and... Voila!
Sorry.

Android `initialize()` is not recognized

So I was following this tutorial and got everything mostly working. But for some reason, the line that says initialize() is not being recognized by Android Studio.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.part_camera_view);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
myContext = this;
initialize(); //This line is not recognized
}
I'm way too new to understanding what's going on, so I'm hoping to be nudged in the right direction. I can't find anything in Android documents that talk about initialize()
I've basically copy and pasted the script from the tutorial and changed the specific elements to fit my project. I am able to see a screen with the buttons provided, but I can not see the live view from the camera, and I believe that line is the problem
Any thoughts?
Initialize is a function. It isn't a prebuilt SDK function- if you want one, you have to write it yourself. If you don't need one, the call to it shouldn't be there.
As an aside, I have serious concerns about this code without even looking at the link to the tutorial- there's no reason to store this in a separate variable, and it makes me doubt the author understands his own code.
If you scroll down to the bottom of the tutorials page you will find a link where you can download the source code of the example project. You will find the initialize method in theAndroidCameraExample class.

Activity is getting too large and becoming more and more difficult to work with. Solutions to solve this issue?

I am working on my second Android Application, first being, hello world. The application code is quite crazy looking because I love to test new libraries and ideas in it. I have been working on this application for well over 3 months and one of my activities is getting way to large and difficult to work with. I find myself getting lost in the code and it is taking longer to do simple things. There might be simple solutions to solving this issue. I really want to split my activity into two and reference each other if possible. Is there are any suggestions to simplifying and organizing code that would be greatly helpful. Even example will help me very much.
Part of my activity is adding a ton of data into a database and the other part is a long equation with multiple values. Another part is implementing the HoloGraphLibrary (Which I love). It is also implementing a listView with custom adapter. It also has a custom dialog............ I can go on and on. I hope you get my point.
EDIT
Going to work with this.
HoloGraphHelper holoGraph = new HoloGraphHelper();
holoGraph.initialize();
Try creating classes for each responsibility.
A Database Helper that has functions to insert data too:
DatabaseHelper database = new DatabaseHelper();
database .insertData(whatever);
A HoloGraphHelper that initializes the HoloGraph
HoloGraphHelper holoGraph = new HoloGraphHelper();
holoGraph.initialize();
And so on.
Break into multiple files. First classes defined in the Activity like the adapter. Change anonymous classes to classes defined in their own file. Look for ways to break out other related code into a class.
Right click on src folder of your Project and select new - class to create a new class. You can use a class for storing methods but you won't be able to display anything on screen.
To display contents to user, you can create a new Activity bu pressing Ctrl + N and selecting Android - Android Activity.
The best way is modularise your code.
I.e split your code into various related modules, for example a separate class for each part that your testing. So you could have a database entry class, a class for Gui testing, i.e. for your custom dialog. That class does all the work for that test, into various functions, I always try to keep functions as small as possible as they are easy to read.
As an example for your database entry, you could have a function which checks the database if the record already exists and then insert it. But a better way would be your insert function only performs the insert code and instead within this function it calls CheckIfDatAlreadyExists function which can return a bool so you know whether you should go ahead and insert the record. This would keep the code tidy and clean to manage.
Then from your main activity all would need to do is instantiate the relative class and call the relevant method.

NullPointerException's on StartActivityForResult, Struggling with SQLite in android i think?

I have one class called Budget.java, within that i start Keypad.java. This was all working fine up until recently when i added a bunch of code to Keypad.java (The added code was to update a row in my SQLite database on the press of a button, all the unrelated methods were working until i tried to implement this). Now using breakpoints i think i've figured out that i get the error message as soon as i try to open the Keypad activity and i don't have a clue what could be the problem.
Maybe it's my misunderstanding of the sqlite open helper? Or perhaps its because i'm using StartActivityForResult?
Any suggestions would be very appreciated! I can upload the logcat if you think that would help.
I uploaded the two little classes to pastebin, you might find it easier to read?
Budget.java ( look for ListItemCommonIntent )
keypad.java
In your Keypad.java, you have the following outside the onCreate:
EditText userAmount=(EditText)this.findViewById(R.id.cost_input);
This wont work because you have to use the setContentView to reference the layout where you want to find the view. And when it initializes userAmount, the object is not available yet (so this is null) .
Try this:
private EditText userAmount;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.keypad);
userAmount=(EditText)findViewById(R.id.cost_input);
MySpinner();
Main();
}

Categories

Resources