The 13th day of Actionbar School notes, telephone service and content sharing

Source: Internet
Author: User

1.ActionBar

Basic use

New activity to inherit from Actionbaractivity, get a Actionbar instance when you want to import V7 under the package Getsupportactionbar ();


Search and share the action Bar

(Note: Due to eclipse, various errors were encountered while importing the V7 package, Actionbar part is temporarily skipped)


Navigation bar



2. Telephone Service

Telephonymanager

Monitor phone status Codes

Mainactivity

Package Com.example.telephonytest;import Android.app.activity;import Android.content.context;import Android.os.bundle;import Android.telephony.phonestatelistener;import Android.telephony.telephonymanager;public Class Mainactivity extends Activity {@Override protected void onCreate (Bundle savedinstancestate) {Super.on        Create (savedinstancestate);        Setcontentview (R.layout.activity_main);    Telephonemanager (); } public void Telephonemanager () {Telephonymanager TM = (Telephonymanager) getsystemservice (Context.telephony_servic    E);    Tm.listen (New Myphonelistener (), phonestatelistener.listen_call_state); }//The Myphonelistener here is a class instead of an interface private static class Myphonelistener extends phonestatelistener{//rewrite Oncallstatechanged method @Override public void oncallstatechanged (int state, String incomingnumber) {//TODO Auto-ge    nerated method Stub super.oncallstatechanged (state, Incomingnumber); Switch (state) {case Telephonymanager.    CALL_STATE_IDLE:System.out.println ("Hanging machine status ...");    Break    Case TelephonyManager.CALL_STATE_OFFHOOK:System.out.println ("Catch status ...");    Break    Case TelephonyManager.CALL_STATE_RINGING:System.out.println ("ringing status ...");    Break }    }    }}

Manifest file

<uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>


Caller ID Display Case



3.APP content Sharing

Share text and picture content

Share Simple text content code

Mainactivity

Package Com.example.appsharetest;import Android.app.activity;import Android.content.intent;import Android.os.bundle;import Android.view.view;public class Mainactivity extends Activity {@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main);} public void Sharetextclick (view view) {Intent Intent = new Intent (); intent.setaction (intent.action_send); Intent.settype ("Text/plain"); Intent.putextra (Intent.extra_text, "Share simple text content"); StartActivity (intent);// StartActivity (Intent.createchooser (Intent, "specify selector"));}}

Share the image content code

Mainactivity

public void Shareimageclick (view view) {URI uri = uri.parse ("/sdcard/1.jpg"); Intent Intent = new Intent (); Intent.setaction (Intent.action_send); Intent.settype ("image/jpg"); Intent.putextra (Intent.extra_stream,uri); StartActivity (Intent.createchooser (Intent, "share picture to"));}


Share multiple pieces of content and receive

Receive simple data from other applications


Using Shareactionprovider

The 13th day of Actionbar School notes, telephone service and content sharing

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.