1. notifications in Android
Generally, there is a status bar on the phone, showing the battery power, signal strength, missed calls, text messages .... A status bar is displayed at the top of the android screen. The notification here is to display the notification on this status bar.
To send a notification, follow these steps:
1). Get notification Manager
Icationicationmanager mnotificationmanager = (notificationmanager) getsystemservice (context. icationication_service );
2) create a notification and specify its icon and title.
Int icon = Android. R. drawable. stat_policy_chat;
Long when = system. currenttimemillis ();
// The first parameter is the icon, the second parameter is the title, and the third parameter is the notification time.
Notification = new notification (icon, null, when );
Intent openintent = new intent (this, otheractivity. Class );
// Openintent intent will be sent to the system when a message is clicked
Pendingintent contentintent = pendingintent. getactivity (this, 0, openintent, 0 );
Notification. setlatesteventinfo (this, "title", "content", contentintent );
Micationicationmanager. Y (0, notification );
Ii. styles and themes in Android
Similar to CSS styles, Styles in Android are used to define display styles for interface elements. They are a set of one or more view control attributes. For example, you need to define the font color and size.
1) Add styles. XML in the values directory:
& Quot; 1.0 & quot; encoding ="UTF-8"?>
2) In the layout file, you can set the style or topic through the style or theme attribute.
3. Use HTML as the UI
Layoutui is troublesome and cannot be involved by artists. However, we can design and operate the UI through HTML + Js.
1). Add the HTML page in assets
2) Add a webview control in main. XLM.
& Quot; 1.0 & quot; encoding ="UTF-8"?>
Http://schemas.android.com/apk/res/android"
Android: Orientation ="Vertical"
Android: layout_width ="Fill_parent"
Android: layout_height ="Fill_parent"
>
Android: layout_width ="Fill_parent"
Android: layout_height ="Fill_parent"
Android: Id ="@ + ID/webview"
3). Activity Class
PackageCn.itcast.html;
ImportJava. util. arraylist;
ImportJava. util. List;
ImportOrg. JSON. jsonarray;
ImportOrg. JSON. jsonobject;
ImportCN. itcast. domain. contact;
ImportAndroid. App. activity;
ImportAndroid. content. intent;
ImportAndroid.net. Uri;
ImportAndroid. OS. Bundle;
ImportAndroid. OS. Handler;
ImportAndroid. util. log;
ImportAndroid. WebKit. webview;
Public ClassContactactivityExtendsActivity {
Private Static FinalStringTag= "Contactactivity ";
PrivateWebview;
PrivateHandler handler =NewHandler ();
@ Override
Public VoidOncreate (bundle savedinstancestate ){
Super. Oncreate (savedinstancestate );
Setcontentview (R. layout.Main);
Webview = (webview)This. Findviewbyid (R. Id.Webview);
Webview. getsettings (). setjavascriptenabled (True); // Supports JavaScript
Webview. getsettings (). setsaveformdata (False); // Do not save form data
Webview. getsettings (). setsavepassword (False); // Do not save the password
Webview. getsettings (). setsupportzoom (False); // Page enlargement is not supported
// The Java object and method to be bound in the addjavascriptinterface method must be run in another thread and cannot be run in the thread that constructs the interface.
Webview. addjavascriptinterface (NewMyjavascript (), "itcast ");
Webview. loadurl ("file: // android_asset/index.html ");
}
Private Final ClassMyjavascript {
Public VoidCall (FinalString phone ){
Handler. Post (NewRunnable (){
@ Override
Public VoidRun (){
Intent intent =NewIntent (intent.Action_call, Uri.Parse("Tel:" + phone ));
Startactivity (intent );
}
});
}
/**
* Get all contacts
*/
Public VoidGetcontacts (){
Handler. Post (NewRunnable (){
@ Override
Public VoidRun (){
// You can obtain contacts by accessing the sqllite database.
List contacts =NewArraylist ();
Contacts. Add (NewContact (27, "Lu Fei", "12345 "));
Contacts. Add (NewContact (28, "suo long", "67890 "));
String JSON = buildjson (contacts );
Webview. loadurl ("javascript: Show ('" + JSON + "')");
}
});
}
// Generate data in JSON format
PrivateString buildjson (list contacts ){
Try{
Jsonarray array =NewJsonarray ();
For(Contact contact: contacts ){
Jsonobject item =NewJsonobject ();
Item. Put ("ID", contact. GETID ());
Item. Put ("name", contact. getname ());
Item. Put ("phone", contact. getphone ());
Array. Put (item );
}
ReturnArray. tostring ();
}Catch(Exception e ){
Log.E(Tag, E. tostring ());
}
Return"";
}
}
}
The method implemented by the myjavascript interface is provided for JS Code calls on the page!
4. Package and install Android applications
1.Export Android applications
Right-click the project --> export --> Android --> export Android Application to export the project as an APK package.
2.Put the APK package in the sdcard directory
In the upper-right corner of the fileexplorer panel, there is an import mobile phone icon that imports the generated APK package to the sdcard directory.
3.Compile the android program for installing the APK package
1) add permissions in andoirdmanifest. xml:
"Android. Permission. install_packages"/>
2). Install APK through the functions provided by Android:
Intent intent = new intent ();
Intent. addflags (intent. flag_activity_new_task );
Intent. setaction (Android. content. Intent. action_view );
Uri DATA = URI. fromfile (new file (environment. getexternalstoragedirectory (), filename ));
Intent. setdataandtype (data, "application/vnd. Android. Package-Archive ");
Startactivity (intent );
This is the end of Android learning!