当前位置: 编程技术>移动开发
本页文章导读:
▪蓝牙范例 蓝牙实例
转载自:http://www.aisidachina.com原创文章:http://www.aisidachina.com/forum/thread-134-1-1.html 转载请注明出处介绍一下这个实例实现的是两个带有蓝牙设备的touch之间的一个小游戏,在界面上.........
▪ apk的封装与安装 apk的打包与安装
1. 什么是apk文件
(1)定义:APK是Android Package Kit的缩写,即Android安装包。APK文件其实是zip格式,但后缀名被修改为apk,通过UnZip解压后,可以看到Dex文件,Dex是Dalvik VM execute.........
▪ WCDMA频率段 WCDMA频段
WCDMA频段
2010年5月25日14:47:56
UMTS与WCDMA之间的关系与区别
......
[1]蓝牙范例
来源: 互联网 发布时间: 2014-02-18
蓝牙实例
转载自:http://www.aisidachina.com
原创文章:http://www.aisidachina.com/forum/thread-134-1-1.html 转载请注明出处
介绍一下这个实例实现的是两个带有蓝牙设备的touch之间的一个小游戏,在界面上有个可以响应事件的UIView(之前说过)可以点击,然后看谁新达到WINNING_TAP_COUNT (游戏中一常量可以自己设置)谁先达到谁就赢了,然后通知对方。还要引入GameKit.framework框架
头文件BlueToothViewController.h:
下面是BlueToothViewController.m:
//
// BlueToothViewController.m
// BlueTooth
//
// Created by mingchun liu on 09-11-24.
// Copyright sdie 2009. All rights reserved.
//
转载自:http://www.aisidachina.com
原创文章:http://www.aisidachina.com/forum/thread-134-1-1.html 转载请注明出处
介绍一下这个实例实现的是两个带有蓝牙设备的touch之间的一个小游戏,在界面上有个可以响应事件的UIView(之前说过)可以点击,然后看谁新达到WINNING_TAP_COUNT (游戏中一常量可以自己设置)谁先达到谁就赢了,然后通知对方。还要引入GameKit.framework框架
头文件BlueToothViewController.h:
//
//
// BlueToothViewController.h
// BlueTooth
//
// Created by mingchun liu on 09-11-24.
// Copyright sdie 2009. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <GameKit/GameKit.h>
#define START_GAME_KEY @"startgame"
#define END_GAME_KEY @"endgame"
#define TAP_COUNT_KEY @"taps"
#define WINNING_TAP_COUNT 50
#define AMIPHD_P2P_SESSION_ID @"amiphdp2p2"//这个是蓝牙协议
@interface BlueToothViewController : UIViewController<GKPeerPickerControllerDelegate,GKSessionDelegate>{
BOOL actingAsHost;//是否提供服务,客户端还是服务器端
int playerTapCount;//记录玩家点击次数
int opponentTapCount;//对方点击次数
IBOutlet UILabel *playerTapCountLabel;//显示玩家点击次数
IBOutlet UILabel *opponentTapCountLabel;//显示对手点击次数
NSString *opponentID;//对方标识符
GKSession *gkSession;
IBOutlet UILabel *startQuitButton;//开始退出按钮
}
@property BOOL actingAsHost;
@property int playerTapCount;
@property int opponentTapCount;
@property (nonatomic,retain) GKSession *gkSession;
@property (nonatomic,retain) NSString *opponentID;
@property (nonatomic,retain)UILabel *playerTapCountLabel;
@property (nonatomic,retain)UILabel *opponentTapCountLabel;
@property (nonatomic,retain)UILabel *startQuitButton;
-(IBAction) handleStartQuitTapped;//处理开始退出操作
-(IBAction) handleTapViewTapped;//处理点击UIView的操作
-(void) updateTapCountLabels;//更新显示
-(void) initGame;//初始化游戏
-(void) hostGame;
-(void) joinGame;//加入游戏
-(void) endGame;//结束游戏
-(void) showEndGameAlert;//弹出结束游戏对话框
@end
下面是BlueToothViewController.m:
//
// BlueToothViewController.m
// BlueTooth
//
// Created by mingchun liu on 09-11-24.
// Copyright sdie 2009. All rights reserved.
//
#import "BlueToothViewController.h"
@implementation BlueToothViewController
@synthesize actingAsHost;
@synthesize playerTapCount;
@synthesize opponentID;
@synthesize playerTapCountLabel;
@synthesize opponentTapCountLabel;
@synthesize startQuitButton;
@synthesize gkSession;
@synthesize opponentTapCount;
-(IBAction) handleStartQuitTapped {//建立链接操作,弹出链接窗口显示在线
if (! opponentID) {//如果对手ID为空就建立服务端提供服务
actingAsHost = YES;
GKPeerPickerController *peerPickerController =[[GKPeerPickerController alloc] init];
peerPickerController.delegate = self;
peerPickerController.connectionTypesMask =
GKPeerPickerConnectionTypeNearby;
[peerPickerController show];
}
}
-(IBAction) handleTapViewTapped {//点击操作
playerTapCount++;
[self updateTapCountLabels];
// did we just win?
BOOL playerWins = playerTapCount >= WINNING_TAP_COUNT;//当点击达到一定次数时
// send tap count to peer
NSMutableData *message = [[NSMutableData alloc] init];//传的数据类型为nsdata类型的
NSKeyedArchiver *archiver =
[[NSKeyedArchiver alloc] initForWritingWithMutableData:message];
[archiver encodeInt:playerTapCount forKey: TAP_COUNT_KEY];
if (playerWins)
[archiver encodeBool:YES forKey:END_GAME_KEY];
[archiver finishEncoding];//打包传数据
GKSendDataMode sendMode =
playerWins ? GKSendDataReliable : GKSendDataUnreliable;//判断用可靠的链接还是不可靠的链接
[gkSession sendDataToAllPeers: message withDataMode:sendMode error:NULL];//发送数据
[archiver release];
[message release];
// also end game locally
if (playerWins)
[self endGame];
}
-(void) updateTapCountLabels {
playerTapCountLabel.text =
[NSString stringWithFormat:@"%d", playerTapCount];
opponentTapCountLabel.text =
[NSString stringWithFormat:@"%d", opponentTapCount];
}
-(void) initGame {
playerTapCount = 0;
opponentTapCount = 0;
}
-(void) hostGame {
[self initGame];
NSMutableData *message = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]
initForWritingWithMutableData:message];
[archiver encodeBool:YES forKey:START_GAME_KEY];
[archiver finishEncoding];
NSError *sendErr = nil;
[gkSession sendDataToAllPeers: message
withDataMode:GKSendDataReliable error:&sendErr];
if (sendErr)
NSLog (@"send greeting failed: %@", sendErr);
// change state of startQuitButton
startQuitButton.text = @"Quit";
[message release];
[archiver release];
[self updateTapCountLabels];
}
-(void) joinGame {
[self initGame];
startQuitButton.text = @"Quit";
[self updateTapCountLabels];
}
//一下是代理方法
-(GKSession *) peerPickerController: (GKPeerPickerController*) controller
sessionForConnectionType: (GKPeerPickerConnectionType) type {
if (!gkSession) {//如果没有链接时建立连接
gkSession = [[GKSession alloc]
initWithSessionID:AMIPHD_P2P_SESSION_ID//根据此值判断用的是什么链接
displayName:nil//在线用户名
sessionMode:GKSessionModePeer];
gkSession.delegate = self;
}
return gkSession;
}
- (void)peerPickerController:(GKPeerPickerController *)picker didConnectPeer:(NSString *)peerID toSession:(GKSession *)session
{//当picker接收到数据后将其释放掉,否则进入不了界面
[picker dismiss];
picker.delegate = nil;
[picker autorelease];
}
- (void)session:(GKSession *)session
didReceiveConnectionRequestFromPeer:(NSString *)peerID {//已接受连接请求的代理方法
actingAsHost = NO;//设为客户端
}
- (void)session:(GKSession *)session peer:(NSString *)peerID
didChangeState:(GKPeerConnectionState)state {//状态改变时触发的代理方法
switch (state)
{
case GKPeerStateConnected:
[session setDataReceiveHandler: self withContext: nil];
opponentID = peerID;//改变opponentID的值
actingAsHost ? [self hostGame] : [self joinGame];//
break;
}
}
- (void) receiveData: (NSData*) data fromPeer: (NSString*) peerID
inSession: (GKSession*) session context: (void*) context {//接受数据时的代理操作
NSKeyedUnarchiver *unarchiver =
[[NSKeyedUnarchiver alloc] initForReadingWithData:data];
if ([unarchiver containsValueForKey:TAP_COUNT_KEY]) {
opponentTapCount = [unarchiver decodeIntForKey:TAP_COUNT_KEY];
[self updateTapCountLabels];
}
if ([unarchiver containsValueForKey:END_GAME_KEY]) {
[self endGame];
}
if ([unarchiver containsValueForKey:START_GAME_KEY]) {
[self joinGame];
}
[unarchiver release];
}
//以上是代理方法
-(void) showEndGameAlert {
BOOL playerWins = playerTapCount > opponentTapCount;
UIAlertView *endGameAlert = [[UIAlertView alloc]
initWithTitle: playerWins ? @"Victory!" : @"Defeat!"
message: playerWins ? @"Your thumbs have emerged supreme!":
@"Your thumbs have been laid low"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[endGameAlert show];
[endGameAlert release];
}
-(void) endGame {
opponentID = nil;
startQuitButton.text = @"Find";
[gkSession disconnectFromAllPeers];
[self showEndGameAlert];
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[opponentID release];
[playerTapCountLabel release];
[opponentTapCountLabel release];
[startQuitButton release];
[gkSession release];
[super dealloc];
}
[2] apk的封装与安装
来源: 互联网 发布时间: 2014-02-18
apk的打包与安装
通过\android-sdk-windows-1.5_r1\tools\emulator.exe启动模拟器。这里要注意,这个命令只有在avd配置好后才可以使用,例如我有一个名为android3的avd,所以我要用如下方法启动emulator:
将要安装的apk文件copy到tools目录下(与emulator.exe同目录);
cmd进入命令行输入,进入到\android-sdk-windows-1.5_r1\tools\目录下,输入命令:adb install ***.apk。
1. 什么是apk文件
(1)定义:APK是Android Package Kit的缩写,即Android安装包。APK文件其实是zip格式,但后缀名被修改为apk,通过UnZip解压后,可以看到Dex文件,Dex是Dalvik VM executes的全称,即Android Dalvik执行程序,并非Java ME的字节码而是Dalvik字节码。APK文件结构为:
- META-INF:Jar文件中常可以看到
- res:存放资源文件的目录
- AndroidManifest.xml:程序全局配置文件
- classes.dex:Dalvik字节码
- resources.arsc:编译后的二进制资源文件
(2)机制:Android在运行一个程序时首先需要UnZip,再通过dexdump命令可以反编译,这样做对于程序的保密性和可靠性不是很高但符合发展规律。Dalvik Vm的执行文件被打包为apk格式,最终运行时,加载器会解压apk并获取编译后的androidmanifest.xml文件中的permission中相关的安全访问。
(3)root权限与签名:如果你将apk文件传到/system/app文件夹下会发现执行是不受限制的,android rom中系统的apk文件默认会放入这个文件夹,它们拥有着root权限。但第三方程序并不是安放在这个文件夹的。
2. apk的打包
在Eclipse中,编译好的android project,在该project的bin目录下会自动生成一个apk文件,与J2ME不同,无需手动打包。只要代码有改动就自动build,build出来的apk是签过名的,也可以在project右键菜单的Andoid Tools菜单下export签名的或未签名的apk。
3. 将apk安装到android simulator中
4. 将apk安装到android mobile中
[3] WCDMA频率段
来源: 互联网 发布时间: 2014-02-18
WCDMA频段
WCDMA频段
2010年5月25日14:47:56
UMTS与WCDMA之间的关系与区别
最新技术文章: