Valentine's Day gift for my wife-an Android Program

Source: Internet
Author: User

The day before yesterday was Valentine's Day. Although I had been married for many years, my wife had always liked the romantic surprise. Unfortunately, I was a dull nerd and could not do anything that was sensational. At noon that day, I was about to go home from work. I suddenly saw someone talking about geek's Valentine's Day gift on Weibo. Although I am not a geek, I recently learned Android and my wife's mobile phone is also in the Android system, why don't I create a program for her?
 
The idea is commendable, but it is not the case to get started. I have learned this for so many days, but I have not yet learned it. There is only less than an hour left. I will only display a few words on the screen: XXX, I love you!
 
Later I thought it would seem too monotonous. If I could add some background music, it would be better, but I haven't learned how to use it. I searched the internet for it. Fortunately, it was very easy to use MediaPlayer, several statements can be done. How can music files come from? Online playing through the network is the simplest, so I searched Baidu MP3 for "Happy Valentine's Day". I remember a song that was always shouting "Happy Valentine's Day, finally, I found the song named "Valentine's Day without a lover"...
 
Forget it. You just need to have a wife. www.2cto.com has no Valentine's Day, and the link is found to be Baidu. In the past, Baidu did not say that it is only responsible for searching and not storing it, why are MP3 files stored on Baidu's servers? Copy the link and run it well on the simulator, because it uses computer broadband. However, after a while, I was prompted that the download failed. I posted the address to the browser, but it really couldn't be opened. The original download link such as Baidu was valid. I just wanted you to try it and download it, not always valid. This is troublesome. Isn't it difficult to install it on a mobile phone?
 
Search again. Fortunately, you can put the MP3 file in assets and include it in the apk when releasing the program. You don't need to connect to the Internet.
 
Now, you can play "Valentine's Day without a lover" www.2cto.com while displaying big words. After reading the results, it was still a bit weird. the status bar of the mobile phone and the title of the program were not matched with the black background, and the big red characters seemed to be different, so I continued to search for full-screen code, this is so dazzling.
 
However, I have been watching those words without any response. It seems too monotonous, so I want them to change color or change, but I can't make it any way. It's time to get off work, you have to pick up your wife.
 
I used to run it on a simulator, or run it on a mobile phone with a USB, but I still don't know how to package it into an apk. I didn't find it yet. It may be too simple, but I didn't say it. So right-click the project and you will see the export apk menu. I chose the unsigned method to export it, but it cannot be installed on the mobile phone. Search again. Oh, it turns out to be exported to signed apk for installation, but I don't have a certificate. How can I signed it? I didn't expect that ADT could generate a certificate, but it would be easier than the Symbian signature, but it may also be one of the reasons for the Android malware flooding.
 
When I picked up my wife, I sent the apk to her mobile phone via Bluetooth, installed it, and ran it. I saw from her face that my efforts were not in vain. However, a serious bug was found at the end. The song was not completed, and another sound had restarted, forming the effect of "two-way singing, the program is still singing after exiting, and the tragedy is caused by the rush of work.
 
The following code is used:
Public class LoveActivity extends Activity {
TextView text;
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
GetWindow (). setFlags (WindowManager. LayoutParams. FLAG_FULLSCREEN,
WindowManager. LayoutParams. FLAG_FULLSCREEN );
RequestWindowFeature (Window. FEATURE_NO_TITLE );
SetContentView (R. layout. main );
MediaPlayer mp = new MediaPlayer ();
Try {
AssetManager assetManager = getAssets ();
AssetFileDescriptor afd = assetManager. openFd ("a.mp3 ");
Mp. setDataSource (afd. getFileDescriptor (), afd. getStartOffset (), afd. getLength ());
Mp. prepare ();
Mp. start ();
}
Catch (Exception e ){
E. printStackTrace ();
}
}
} Main. xml:
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<TextView
Android: id = "@ + id/textView1"
Android: text = "@ string/loveyou"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: gravity = "center"
Android: textColor = "# ff0000"
Android: textStyle = "bold"
Android: textSize = "50dip"
/>


</LinearLayout> strings. xml:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "hello"> Hello World, LoveActivity! </String>
<String name = "app_name"> Love </string>
<String name = "loveyou"> XXX \ n I LOVE YOU </string>
</Resources> put the first mp3in assets and change it to a.mp3.
 
 
From amp @ java
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.