标签:
1.ActionBar
基本使用
新建Activity要继承自ActionBarActivity,获取一个ActionBar实例时要导入v7下的包getSupportActionBar();
搜索和分享操作栏
(注:由于用的是Eclipse,导入v7包时出现各种错误,ActionBar部分暂时略过)
导航栏
2.电话服务
TelephonyManager
监听电话状态代码
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.onCreate(savedInstanceState); setContentView(R.layout.activity_main); telephoneManager(); } public void telephoneManager(){ TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); tm.listen(new MyPhoneListener(), PhoneStateListener.LISTEN_CALL_STATE); } //这里的MyPhoneListener是一个类而不是接口 private static class MyPhoneListener extends PhoneStateListener{ //重写onCallStateChanged方法 @Override public void onCallStateChanged(int state, String incomingNumber) { // TODO Auto-generated method stub super.onCallStateChanged(state, incomingNumber); switch(state){ case TelephonyManager.CALL_STATE_IDLE: System.out.println("挂机状态……"); break; case TelephonyManager.CALL_STATE_OFFHOOK: System.out.println("接听状态……"); break; case TelephonyManager.CALL_STATE_RINGING: System.out.println("响铃状态……"); break; } } } }
清单文件
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
来电显示案例
3.App内容共享
分享文本和图片内容
分享简单文本内容代码
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 { @Override protected 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, "分享简单文本内容"); startActivity(intent);//startActivity(intent.createChooser(intent, "指定选择器")); } }
分享图片内容代码
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,"分享图片到")); }
分享多件内容和接收
从其他应用程序接收简单数据
使用ShareActionProvider
标签:
原文地址:http://blog.csdn.net/huangluqian/article/details/50997882