AdSense

Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Tuesday, 17 September 2013

Music player - Remote for android mobile phones

(Deutsche Version) As described in this post, I created an own music player in C# and WPF. It can occur that you don't like the current playing song, so there are hotkeys for the computer. But what is, when you are lying on the bed and don't want to get up to switch to the next song? Therefore, I created an App, which can execute the basic commands (play/pause, next song, previous song). The app can be downloaded hier.

The app can be started an then you can click on the buttons, but there is also a widget which does not require the click to open the app. The app contains more functions, you can even look for a song.

In the app, you have to enter IP, Port (the player opens a socket on port 7200) and password (which you can define in the player with F2). The IP can be local (e.g. when the mobile phone is in the same network as the computer) or an internet IP. Therefore, you have to setup the appropriate port forwarding at your router. The mobile phone can now control the player independant of whether it is in the wireless network or in the mobile network.

Monday, 16 September 2013

Android - Write application data

(Deutsche Version) Lots of Android apps use a several (small) amount of memory for "data". These datas are e.g. for saving passwords or similar things. I want to explain how to access these datas. At first the reading:

SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE);
String defaultStringValue = "";
String stringValue = sharedPref.getString("nameOfString", defaultStringValue);


This is analogue to a C# Dictionary with a string as key and (here) a string as value. The value can also be an integer, the syntax is the same. If the key does not exist, defaultStringValue is returned.

Now to the writing of application data:

SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE);
String stringValue = "asdf";
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("
nameOfString", stringValue);
editor.commit();


Here you can also use int instead of string. Additionally, you can have multiple editor.put... commands directly in a row and only at the end there has to be the editor.commit();. This should cover the basic access on application data. If you want to acces on application data via a widget, you have to use SharedPreferences. The only thing that changes in the code is:

SharedPreferences sharedPref = this.getSharedPreferences("nameOfPreferences", 0);

Monday, 2 September 2013

Android - Widget "crashes" when the screen is being rotated

(Deutsche Version) The detailled error is: I have got an widget, when I click on it, I want it to open the corresponding app. This usually works. Sometimes, nothing happens when I click on it, mostly after turning the screen. The reason is: Several things (e.g. rotating the screen) do not call the onUpdate function but only the onReceive function. Because of having the following lines in the onUpdate


Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

remoteViews.setOnClickPendingIntent(R.id.button, pendingIntent);


the MainActivity was started. This did not happen when onReceive was called. Therefore, I had to add these lines to the onReceive function (I had to rename intent in localIntent because onReceive has a parameter Intent intent). Afterwards, everything worked fine.

Tuesday, 18 June 2013

Android - Notes App

(Deutsche Version) Many things come to my mind when I am not at home. Usually I don't have a pencil and a piece of paper with me so I wrote an App for Android. Additionally to this App, I installed Dropbox and DropSync so all my notes will be synchronized with my Dropbox folder.

Dropsync is able to sync single foldert to the Dropbox. I have a folder "toSync" on my mobile in which the notes are saved by the App and DropSync synchronizes them.

On the Computer, I can view the notes.dat file in my Dropbox folder "toSync" or edit the file. I wrote a display and edit program for Linux, maybe I will do the same for Windows. The basic principle is simple, there just has to be a window with a text field and a save button.

The app can be downloaded here. To run successfully, the folder "toSync" has to be present on the SD card and also the file "Notes.dat" has to be in this folder.