基本信息
源码名称:android 广播的接收与发送 service实现 附完整源码
源码大小:0.12M
文件格式:.zip
开发语言:Java
更新时间:2013-04-20
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍




client源码:

 

package com.client;

import com.aidl.MyServiceBinder;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;

public class MainActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}

	ServiceConnection connection = new ServiceConnection() {

		@Override
		public void onServiceConnected(ComponentName name, IBinder service) {
			MyServiceBinder myb = MyServiceBinder.Stub.asInterface(service);
			try {
				System.out.println(myb.showName());
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}

		@Override
		public void onServiceDisconnected(ComponentName name) {

		}

	};

	public void myBind(View view) {

		/*
		 * Intent intent = new Intent(); intent.setAction("com.anbo.service");
		 * 
		 * this.bindService(intent, connection, Context.BIND_AUTO_CREATE);
		 */

		/*
		 * android.text.ClipboardManager manager =
		 * (android.text.ClipboardManager) this
		 * .getSystemService(Context.CLIPBOARD_SERVICE);
		 * manager.setText("hello");
		 */

		/*
		 * android.view.WindowManager manager = (android.view.WindowManager)
		 * this .getSystemService(Context.WINDOW_SERVICE);
		 * System.out.println(manager.getDefaultDisplay().getHeight());
		 * System.out.println(manager.getDefaultDisplay().getWidth());
		 */

		/*
		 * android.media.AudioManager manager = (android.media.AudioManager)
		 * this .getSystemService(Context.AUDIO_SERVICE);
		 * manager.setMode(android.media.AudioManager.R);
		 */

		android.telephony.TelephonyManager manager = (android.telephony.TelephonyManager) this
				.getSystemService(Context.TELEPHONY_SERVICE);
		manager.listen(listener,
				android.telephony.PhoneStateListener.LISTEN_CALL_STATE);
	}

	android.telephony.PhoneStateListener listener = new android.telephony.PhoneStateListener() {
		public void onCallStateChanged(int state, String incomingNumber) {
			// android.telephony.TelephonyManager.CALL_STATE_IDLE
			// android.telephony.TelephonyManager.CALL_STATE_OFFHOOK
			// android.telephony.TelephonyManager.CALL_STATE_RINGING
		}
	};
}

service源码:

package com.service;

import com.aidl.MyServiceBinder;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

public class MyService extends Service {

	class MyBinder extends MyServiceBinder.Stub {

		public String showName() {
			return "anbo";
		}

	}

	public IBinder onBind(Intent arg0) {
		return new MyBinder();
	}

	public boolean onUnbind(Intent intent) {
		System.out.println("onUnbind");
		return super.onUnbind(intent);
	}

	public void onCreate() {
		super.onCreate();
		System.out.println("create");
	}

	public void onDestroy() {
		super.onDestroy();
		System.out.println("destroy");
	}

}