Entries tagged android

Using a Perl script because refactoring of a project with Android tools didn’t work

Posted on 20. Dezember 2014 Comments

I wanted to rename my project but I guess since it has a lot of dependencies that caused an error somewhere and I got the error message:

Refactoring
A fatal error occurred while performing the refactoring.
An unexpected exception occurred while creating a change object. See the error log for more details.

So I just the normal refactoring feature of Eclipse which not surprisingly also caused an error. After editing the AndroidManifest package entry, the import of the resources in the sources files didn’t work. It still said

import com.example.oldpackage.R

Only a couple of resource files needed manual editing but the Java files were a problem. What did the trick for me was this one-liner

perl -pi -w -e 's/import com.example.oldpackage.R/import com.example.newpackage.R/g;' `grep -r -l "import com.example.oldpackage.R"`

I realise this is rather quick&dirty (do a backup 😉 ) but it did work for this project. A short explanation:

perl

  • -pi puts the code in a loop (like -n, but sed-style)
  • -w gives you warnings
  • -e is one line of programm and since -pi
  • /g global, for all lines in the file

grep

  • -r recursive
  • -l give out files that matches the following search string

Minimal Mensa Plan

Posted on 9. Dezember 2014 Comments

We’ve been doing a lot of website scraping for a university project latel so I decided a little app to scrape the universitys‘ cantine website for the lunch menu.

minimalmensaplan-screenshot

A network connection in the main Activity is not allowed so I’m using a private class for that. Once the doInBackground method is over onPostExecute is automatically called.

Luckily the jSoup library which is used for parsing also brings a way download a website for parsing.

Document doc = Jsoup.connect("http://speiseplan.studierendenwerk-hamburg.de/de/520/2014/0/").get();

There is only one category class and it contains the date. The dish-description class contains what you will later see in the app. The size is needed for a for-loop later on.

date = doc.select(".category").text();
int maxDishes = doc.getElementsByClass("dish-description").size();

With the next piece of code all the dish descriptions are extracted. The original website contains details about the food (made with alcohol, pork or if it’s vegeterian etc). For blending this out I use a regular expression which filters out:

1 non-word character(\W = an opening bracket), then possibly multiple digits (\d) and non-word characters (\W = commas) and then another non-word character (\W = a closing bracket)

String dish = doc.getElementsByClass("dish-description").get(i).text().replaceAll("(\\W[\\d\\W]*\\W)", " ");

These dishes are then saved together with every second price (the one for students, the other one’s for employees) in a HashMap, which is then added to a list. For recognizing later, the dishes get the key „dish“ and the prices the key „price“.

Once the data extraction is done, onPostExecute is automatically called. The date is set to a TextView above the ListView and a SimpleAdapter is populating the list of HashMaps into the layout

dateTextView.setText(date);
simpleAdapter = new SimpleAdapter(MainActivity.this,
dishList, R.layout.list, new String[] { "dish",
"price" }, new int[] { R.id.text1, R.id.text2 });
setListAdapter(simpleAdapter);

Since i’s called Minimal Mensa Plan, no other features (such as caching or selecting a cantine) are available. The app in the Play Store is used for scraping the cantine at the campus Berliner Tor but it might as well be used for others, just by changing the URL. It’s released under the MIT License and available at GitHub.

Most minimal note taking app for Android

Posted on 2. Oktober 2014 Comments

As of September 2014 the smallest (15KB!), most minimalistic app for simply taking notes is called Zen Notes from Peter Gyorffy.

It doesn’t have any features like reminders, changing the theme or font or any other useless stuff. It’s basically like a sheet of paper where you can write your thoughts on, just digitally. The only thing it can do is share the written text over whatever Android offers you, e.g. email. When you exit the app the notes are saved automatically.

 

Markdown Templates for README files on GitHub

Posted on 7. März 2014 Comments

Every time I upload a new project on GitHub I find myself writing almost an identicially structured README.md file in Markdown. So I thought I could make some templates for the next times. Right now I only have one for mobile apps and websites with GitHub Pages, but there’s more to come.

Also I found that quite a lot of projects have very unstructured and ugly READMEs. It’s always nice to get a quick overview over a project, especially when they don’t have a website. So maybe someone can use this.

Bester Flappy Bird Klon für Android: Flappy Cow

Posted on 13. Februar 2014 Comments

Nicht erst seit Entwickler Dong Nguyen sein populäres Spiel Flappy Bird vom Markt genommen hat, tauchen vor allem in Androids Google Play Store zahlreiche Klone mit allerlei Getier auf. Ich habe ein paar ausprobiert und fand Flappy Cow am besten.

Die Kuh könnte man schon von Space Cowboy kennen; jetzt als Superman verkleidet umfliegt sie Spinnen und Rohre. Es gibt einen Highscore, Medallien(ich hab schon Bronze geschafft 🙂 ) und häufig Updates.

Ein perfektes Spiel für die Langeweile zwischendurch. Seit Version 1.7 gibt es auch einen Pause Button, falls man mal unterbrochen wird.

Ausserdem ist die App Open Source und liegt auf GitHub

Download Flappy Cow im Google Play Store

edit: Aufgrund von einer seltsamen Google Policy (und Apple auch für iOS) darf in den Namen der Apps nicht mehr das Wort Flappyvorkommen. Die App heisst im Play Store jetzt Flutter Cow.

Disclaimer: Ich kenne den Entwickler.

Minimal Open Source Flashlight

Posted on 1. Januar 2014 Comments

Nachdem OI Flashlight bei mir nicht funktioniert habe ich gestern Nacht kurzerhand entschloßen mal AIDE auszuprobieren und mir meine eigene Taschenlampen App zu schreiben. Stellt sich raus, dass das garnicht so schwer ist. Der Developer Account bei Google kostet $25 und ist super einfach zu bedienen. Details folgen noch.

update: Ich habe eine Version für Smartphones mit Android < 4.0 hochgeladen. Je nach Androidversion wird automatisch die richtige App ausgewählt.

Screenshot
   

Market Link

Google Play

Get it on Google Play

Github

APK SHA1SUM(15 Jan 2014/v 1.0.2)

$adb pull /data/app/de.repat.mosf-2.apk
$sha1sum de.repat.mosf-2.apk
  • c5b311b6d85ab1f4e3e99fe3bdcfc4f104a4a375 for 4.0+
  • 1db8ad27f07f60dc843eefb3df6a7ee35f1fd880 for < 4.0

Droid-Break

10 best Android apps for the paranoid

Posted on 15. Dezember 2013 Comments

So I compiled a few apps that even the most paranoid people would feel safe to use. Privacy is mostly enforced through encryption but beware: if you don’t use encryption correctly by e.g. chosing a weak password, it’s totally useless. You can download from Google Play (GP) or F-Droid (FD)

 

TextSecure (GP)

TextSecure encrypts your text messages(SMS) locally. Also, if your partner also has TextSecure, you can encrypt the messages, so not even the carrier could intercept them.

update: No SMS encryption functionality anymore, but this app is now called Signal and can still encrypt the SMS and message database on the phone. For SMS encryption use Silence (GP).

textsecure

Cost: free

RedPhone (GP)

RedPhone is basically an open source Skype replacement with even better encryption. It’s dead simple to use. If a contact in your phonebook also uses RedPhone, you will be asked if you want to upgrade to a secure call.

update: Now merged with TextSecure in the Signal Messenger App.

redphone

Cost: free

 

Google Authenticator (GP)

Whether it’s your bank, your WordPress blog, github, Dropbox or facebook. Two factor authentication with One Time Passwords(OTPs) is getting popular! With this app, you will not only need your password to login, but a code from your smartphone that’s generated and valid for 30 seconds. Just in case your phone gets stolen or lost, make sure to print out extra backup code. Don’t want them laying around your house? Use the next app!

google-authenticator

Cost: free

 

EDSLite (GP)

EDSLite works much like Truecrypt/Veracrypt for your computer. You can create containers, where you can store your Pins, Tans, Backup OTP Backup Codes and more. Because TrueCrypt can read those containers you can just save them to your Dropbox and keep them in sync with your computer. If you don’t trust Dropbox, maybe the next app is for you.

update: Use Veracrypt instead of Truecrypt, since Truecrypt is not actively developed anymore. EDS can use both.

edslite

Cost: free

 

ownCloud (GP/FD)

ownCloud is an app that works with your owncloud installation. You can download your private cloud and host it from home on a Rapberry Pi or chose a hosted solution in a data center that you trust.

owncloud

Cost: 0.79€

 

F-Droid

So, from where should you download all these apps? Trust Google or Amazon that the binaries you’re getting are what the developers uploaded? f-droid.org is another alternative app store that you might consider to trust. The apps are all open source and you can probably even get a couple of apps for free that would cost a few cents in the Google Play Store.

Cost: free

 

Threema (GP/Website)

Threema is probably the best app available for secure encrypted messaging; it works very much like Whatsapp. The servers are in Switzerland. The only downturn is: it’s not open source. But: you can verify that the encryption works correctly. If you just add a contact with his/her Threema ID, the contact appears read. If you sync your phonebook with Threema(your phone number is only transmitted as a hash) and Threema recognizes a contact, it’s getting orange. And if you meet your contact in person and scan his QR-code, the contact finally turns green. This is the most paranoid messaging app I’ve seen.

threema

Cost: 1.60€

 

k-9 Mail (GP/FD)

If you want to send only encrypted emails, this is for you. Together with the APG app, it’s super easy to send encrypted and receive/decrypt emails.

k9mail

Cost: free

 

Built-in Android encryption

With Android 4.x on you can encrypt your whole device. Make sure you chose and remember a good password or PIN.

Cost: free

 

NoteCipher (GP/FD)

Evernote is great for keeping your notes in sync. But if you want to keep them secret, you might want to consider using this app. Every entry is encrypted via sqlcipher with AES 256.

notecipher

Cost: free

 

More stuff

  • Heml.is looks promising but has been under development for quite some time now. Hope to hear more soon.
    • Heml.is is dead.
  • Telegram is another open source messaging app. The encryption only works, when both participants are online, so be careful.
  • Droid-Break has a lot more high quality open source apps

 

GP: Google Play, FD: F-Droid, Pictures from play.google.com

Owncloud News Reader Error after update to 5.0.11

Posted on 21. Oktober 2013 Comments

After updating to owncloud 5.0.11 I got the following error in my Owncloud News Reader:

Screenshot_2013-10-21-10-20-56

(For Google: A Toast saying „End of input at line 1 column 1“)

In my owncloud instance, I got an error in the administrator menu saying:

SQLSTATE[HY000]: General error: 1 no such column: feeds.articles_per_update at db.php#391

I updated the owncloud instance and app framework/news app but it still showed me that everything was uptodate, even when 5.0.12 was released. Via phpMyAdmin I could see that the feeds were still in the database but I couldn’t see them in the web app or Android app. So I just deleted the owncloud folder, downloaded the new .tar.bz2 from owncloud.org, removed the oc_news tables(do not delete e.g. the contacts or bookmarks!). Then I changed my username in oc_users, used my old username as my new username and reinstalled owncloud, this time version 5.0.12.  I could then delete the old (changed) username via the admin panel.

This is the third time I had to reinstall owncloud, because the update mechanism didn’t work properly… And yes, as advised, I did deactivate the news app and app framework for the update process 😉

I just had a look at the SQL-statements from my last backup and saw that articles_per_update is supposed to be a column in oc_news_feeds in the new version of the news app. Somehow, the owncloud update process didn’t update the news app or didn’t trigger a 3rd-party update process. Anyways, I guess this could also be solved by just adding this column manually:
`articles_per_update` bigint(20) NOT NULL DEFAULT '0'

crond mit busybox auf einem nook simple touch

Posted on 9. August 2013 Comments

Ich habe einen Nook gemäß den Anleitungen von nookdevs.org gerootet. Danach ist busybox, eine Sammlung von Unix-Tools, verfügbar(update: falls nicht: nachinstallieren). Eines dieser Tools ist der Scheduler cron, mit dem sich regelmässig Tasks ausführen lassen. Ich setzt hier vorraus, dass das Android SDK/ADT installiert ist und ihr root-Zugriff über USB habt.

$ adb shell

# cd /system/bin

Unter /system/bin habe ich ein paar Skripte hinterlegt mit denen er Crons starten und beenden kann. Die Zeit ist wichtig, damit er das auch zu eurer Zeit ausführt, nicht  UTC oder wie auch immer.

#cat startcron
export TZ=Europe/Berlin
busybox crond -f -c /data/cron &

Die verschiedenen Crondienste stehen in der Datei /data/cron/root. Damit ich nicht immer diesen langen Befehl aufrufen muss gibt es dafür ebenfalls ein Shortcut dafür.

#cat editcron
busybox vi /data/cron/root

Zum Beenden benutze ich ganz einfach brutal den killall-Befehl

#cat killcron
busybox killall crond

Mit Arduino und Android 434MHz Funk Steckdosen schalten

Posted on 10. April 2013 Comments

Schon lange wollte ich die Funksteckdosen wieder hervorräumen und mit meinem ebenfalls schon eingestaubten Arduino Uno (rev 3)und einem 434MHz Sender von watterot wieder in Gange bringen. Das Ganze gestaltet sich aufgrund der RCSwitch Library relativ einfach. Ich benutze hier im Gegensatz zum homecontrol4me-Projekt (mit kostenpflichtiger Android App) die Arduino IDE 1.0 aus den Ubuntu Repositories. Das hatte zur Folge, dass man den Beispielcode etwas anpassen muss. Dazu muss man aber auch sagen, dass ich hier keine Sicherheit eingebaut habe, jeder der die (interne) IP vom Arduino kennt, kann HTTP-Requests absenden und damit wild meine Geräte an- und ausschalten, NAT ist ja nicht wirklich ein Sicherheitsfeature.

Arduino

Sketch: Download (github)

Weil Arduino 1.0 die neuen libraries enthält muss für Server immer EthernetServer und für Client immer EthernetClient geschrieben werden. Ausserdem müssen die beiden Dateien EthernetServer.h und EthernetClient.h included werden. Am besten kann man das mit Strg+F(Suchen+Ersetzen) machen.

Die Funktion httpResponseHome() stellt die Website dar. Im Grunde bräuchte man das nicht, wenn man nur die Android App benutzen möchte.

 

Android

Android-Projekt für Eclipse: Download (github)screenshot-lichtsteuerung

Im Grunde muss man nur HTTP-Requests absetzen, die /?1-On usw. hinter der IP stehen haben. In Android dürfen keine langen Operationen, also hier Netzwerkverbindungen, in der MainActivity aufgebaut werden. Dafür habe ich die Klasse Network.java geschrieben, welche über einen AsyncTask Threads mit den HTTP-Requests startet. Weil sich das bei Lampen anbietet, habe ich ToggleButtons genommen. Diese haben das Attribut  android:onClick=“onToggleButton1Clicked“. Für jeden dieser Button habe ich eine entsprechende Methode in der mainActivity.java, die diesem Schema folgen. update: weil es manchmal hakte, hab ich eine loop eingebaut, die die Requests an die Network-Klasse drei mal sendet. Das löst zwar nicht das Problem(was immer es war), aber es funktioniert.

public void onToggleButton1Clicked(View v) {

boolean on = ((ToggleButton) v).isChecked();

        if (on) {
            loop(LICHT1ON);
        } else {
            loop(LICHT1OFF);
        }

 

In Requests.java finden sich ein Haufen Strings nach dem Schema:

public static final String IP = "http://192.168.1.42/";
public static final String LICHT1ON = IP + "?1-on";

Da ich den Code hier sehr simpel (und damit natürlich auch unsicher) gehalten habe, war’s das auch schon. Den Arduino und den Sender habe ich dann in eine Box hinter den Schrank gestellt und ein altes Netzteil zur Stromversorgung benutzt.

arduino-lichtsteuerung

Credits
Den Async Task Code habe ich (leicht editiert) von Konstantin Burov von stackoverflow.com.

Den Code für die ToggleButtons habe ich aus der Developer API von Google.

Der Arduino Code stammt überwiegend von RCSwitch aus der Datei /examples/Webserver/Webserver.pde. Ich habe die oben genannten Anpassungen an Arduino 1.0 vorgenommen, mal abgesehen von der Anpassung an meine Steckdosen.