- 浏览: 123777 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (110)
- android动画 (9)
- android(xml相关) (2)
- android sqlite3 (0)
- android 组件学习 (5)
- android 小技巧 (8)
- android自定义组件 (2)
- android 手机服务 (5)
- android 网络相关 (9)
- android 用户界面 (6)
- 基本概念 (30)
- java基本知识 (3)
- 面试题 (2)
- android sdcard (3)
- android 文件操作 (4)
- 闲谈android风云变幻 (10)
- JNI (3)
- NDK (5)
- linux (6)
- IOS学习 (1)
- Android源码 (1)
最新评论
-
AndLi:
高手
Android 实现书籍翻页效果----原理篇 -
niuniulife2011:
没听懂,任何事情任何人都可以做吧
程序员感想 -
chenliang1234576:
程序员开网店有木有搞头撒?
程序员感想 -
liyanginchina:
请问一下,
1、 A和B分别与S的【主连接】保持联系。
那么 ...
TCP实现P2P通信、TCP穿越NAT的方法、TCP打洞 -
niuniulife2011:
一起进步,我的东西,有些是看了别人的,但是在看了别人的之后,都 ...
windows系统上使用Android NDK r5
1.界面操作类:
Java代码
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;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class TestServiceHolder extends Activity {
private boolean _isBound;
private TestService _boundService;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setTitle("Service Test");
initButtons();
}
private ServiceConnection _connection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
_boundService = ((TestService.LocalBinder)service).getService();
Toast.makeText(TestServiceHolder.this, "Service connected",
Toast.LENGTH_SHORT).show();
}
public void onServiceDisconnected(ComponentName className) {
// unexpectedly disconnected,we should never see this happen.
_boundService = null;
Toast.makeText(TestServiceHolder.this, "Service connected",
Toast.LENGTH_SHORT).show();
}
};
private void initButtons() {
Button buttonStart = (Button) findViewById(R.id.start_service);
buttonStart.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
startService();
}
});
Button buttonStop = (Button) findViewById(R.id.stop_service);
buttonStop.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
stopService();
}
});
Button buttonBind = (Button) findViewById(R.id.bind_service);
buttonBind.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
bindService();
}
});
Button buttonUnbind = (Button) findViewById(R.id.unbind_service);
buttonUnbind.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
unbindService();
}
});
}
private void startService() {
Intent i = new Intent(this, TestService.class);
this.startService(i);
}
private void stopService() {
Intent i = new Intent(this, TestService.class);
this.stopService(i);
}
private void bindService() {//调用onCreate(),onBind()方法
Intent i = new Intent(this, TestService.class);
bindService(i, _connection, Context.BIND_AUTO_CREATE);
_isBound = true;
}
private void unbindService() {
if (_isBound) {
unbindService(_connection);
_isBound = false;
}
}
}
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;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class TestServiceHolder extends Activity {
private boolean _isBound;
private TestService _boundService;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setTitle("Service Test");
initButtons();
}
private ServiceConnection _connection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
_boundService = ((TestService.LocalBinder)service).getService();
Toast.makeText(TestServiceHolder.this, "Service connected",
Toast.LENGTH_SHORT).show();
}
public void onServiceDisconnected(ComponentName className) {
// unexpectedly disconnected,we should never see this happen.
_boundService = null;
Toast.makeText(TestServiceHolder.this, "Service connected",
Toast.LENGTH_SHORT).show();
}
};
private void initButtons() {
Button buttonStart = (Button) findViewById(R.id.start_service);
buttonStart.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
startService();
}
});
Button buttonStop = (Button) findViewById(R.id.stop_service);
buttonStop.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
stopService();
}
});
Button buttonBind = (Button) findViewById(R.id.bind_service);
buttonBind.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
bindService();
}
});
Button buttonUnbind = (Button) findViewById(R.id.unbind_service);
buttonUnbind.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
unbindService();
}
});
}
private void startService() {
Intent i = new Intent(this, TestService.class);
this.startService(i);
}
private void stopService() {
Intent i = new Intent(this, TestService.class);
this.stopService(i);
}
private void bindService() {//调用onCreate(),onBind()方法
Intent i = new Intent(this, TestService.class);
bindService(i, _connection, Context.BIND_AUTO_CREATE);
_isBound = true;
}
private void unbindService() {
if (_isBound) {
unbindService(_connection);
_isBound = false;
}
}
}
2.服务类:
Java代码
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
public class TestService extends Service {
private static final String TAG = "TestService";
private NotificationManager _nm;
@Override
public IBinder onBind(Intent i) {
Log.e(TAG, "============> TestService.onBind");
return null;
}
public class LocalBinder extends Binder {
TestService getService() {
return TestService.this;
}
}
@Override
public boolean onUnbind(Intent i) {
Log.e(TAG, "============> TestService.onUnbind");
return false;
}
@Override
public void onRebind(Intent i) {
Log.e(TAG, "============> TestService.onRebind");
}
@Override
public void onCreate() {// 服务第一次被启动时调用
Log.e(TAG, "============> TestService.onCreate");
_nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
showNotification();
}
@Override//在onCreate()方法后被调用
public void onStart(Intent intent, int startId) {
Log.e(TAG, "============> TestService.onStart");
}
@Override
public void onDestroy() {//停止服务的时候被调用
_nm.cancel(R.string.service_started);
Log.e(TAG, "============> TestService.onDestroy");
}
private void showNotification() {
Notification notification = new Notification(R.drawable.face_1,
"Service started", System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, TestServiceHolder.class), 0);
// must set this for content view, or will throw a exception
notification.setLatestEventInfo(this, "Test Service",
"Service started", contentIntent);
_nm.notify(R.string.service_started, notification);
}
}
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
public class TestService extends Service {
private static final String TAG = "TestService";
private NotificationManager _nm;
@Override
public IBinder onBind(Intent i) {
Log.e(TAG, "============> TestService.onBind");
return null;
}
public class LocalBinder extends Binder {
TestService getService() {
return TestService.this;
}
}
@Override
public boolean onUnbind(Intent i) {
Log.e(TAG, "============> TestService.onUnbind");
return false;
}
@Override
public void onRebind(Intent i) {
Log.e(TAG, "============> TestService.onRebind");
}
@Override
public void onCreate() {// 服务第一次被启动时调用
Log.e(TAG, "============> TestService.onCreate");
_nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
showNotification();
}
@Override//在onCreate()方法后被调用
public void onStart(Intent intent, int startId) {
Log.e(TAG, "============> TestService.onStart");
}
@Override
public void onDestroy() {//停止服务的时候被调用
_nm.cancel(R.string.service_started);
Log.e(TAG, "============> TestService.onDestroy");
}
private void showNotification() {
Notification notification = new Notification(R.drawable.face_1,
"Service started", System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, TestServiceHolder.class), 0);
// must set this for content view, or will throw a exception
notification.setLatestEventInfo(this, "Test Service",
"Service started", contentIntent);
_nm.notify(R.string.service_started, notification);
}
}
3.配置文件:
Java代码
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TestServiceHolder" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:enabled="true" android:name=".TestService"
android:process=":remote" />
</application>
Java代码
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;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class TestServiceHolder extends Activity {
private boolean _isBound;
private TestService _boundService;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setTitle("Service Test");
initButtons();
}
private ServiceConnection _connection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
_boundService = ((TestService.LocalBinder)service).getService();
Toast.makeText(TestServiceHolder.this, "Service connected",
Toast.LENGTH_SHORT).show();
}
public void onServiceDisconnected(ComponentName className) {
// unexpectedly disconnected,we should never see this happen.
_boundService = null;
Toast.makeText(TestServiceHolder.this, "Service connected",
Toast.LENGTH_SHORT).show();
}
};
private void initButtons() {
Button buttonStart = (Button) findViewById(R.id.start_service);
buttonStart.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
startService();
}
});
Button buttonStop = (Button) findViewById(R.id.stop_service);
buttonStop.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
stopService();
}
});
Button buttonBind = (Button) findViewById(R.id.bind_service);
buttonBind.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
bindService();
}
});
Button buttonUnbind = (Button) findViewById(R.id.unbind_service);
buttonUnbind.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
unbindService();
}
});
}
private void startService() {
Intent i = new Intent(this, TestService.class);
this.startService(i);
}
private void stopService() {
Intent i = new Intent(this, TestService.class);
this.stopService(i);
}
private void bindService() {//调用onCreate(),onBind()方法
Intent i = new Intent(this, TestService.class);
bindService(i, _connection, Context.BIND_AUTO_CREATE);
_isBound = true;
}
private void unbindService() {
if (_isBound) {
unbindService(_connection);
_isBound = false;
}
}
}
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;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class TestServiceHolder extends Activity {
private boolean _isBound;
private TestService _boundService;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setTitle("Service Test");
initButtons();
}
private ServiceConnection _connection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
_boundService = ((TestService.LocalBinder)service).getService();
Toast.makeText(TestServiceHolder.this, "Service connected",
Toast.LENGTH_SHORT).show();
}
public void onServiceDisconnected(ComponentName className) {
// unexpectedly disconnected,we should never see this happen.
_boundService = null;
Toast.makeText(TestServiceHolder.this, "Service connected",
Toast.LENGTH_SHORT).show();
}
};
private void initButtons() {
Button buttonStart = (Button) findViewById(R.id.start_service);
buttonStart.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
startService();
}
});
Button buttonStop = (Button) findViewById(R.id.stop_service);
buttonStop.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
stopService();
}
});
Button buttonBind = (Button) findViewById(R.id.bind_service);
buttonBind.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
bindService();
}
});
Button buttonUnbind = (Button) findViewById(R.id.unbind_service);
buttonUnbind.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
unbindService();
}
});
}
private void startService() {
Intent i = new Intent(this, TestService.class);
this.startService(i);
}
private void stopService() {
Intent i = new Intent(this, TestService.class);
this.stopService(i);
}
private void bindService() {//调用onCreate(),onBind()方法
Intent i = new Intent(this, TestService.class);
bindService(i, _connection, Context.BIND_AUTO_CREATE);
_isBound = true;
}
private void unbindService() {
if (_isBound) {
unbindService(_connection);
_isBound = false;
}
}
}
2.服务类:
Java代码
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
public class TestService extends Service {
private static final String TAG = "TestService";
private NotificationManager _nm;
@Override
public IBinder onBind(Intent i) {
Log.e(TAG, "============> TestService.onBind");
return null;
}
public class LocalBinder extends Binder {
TestService getService() {
return TestService.this;
}
}
@Override
public boolean onUnbind(Intent i) {
Log.e(TAG, "============> TestService.onUnbind");
return false;
}
@Override
public void onRebind(Intent i) {
Log.e(TAG, "============> TestService.onRebind");
}
@Override
public void onCreate() {// 服务第一次被启动时调用
Log.e(TAG, "============> TestService.onCreate");
_nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
showNotification();
}
@Override//在onCreate()方法后被调用
public void onStart(Intent intent, int startId) {
Log.e(TAG, "============> TestService.onStart");
}
@Override
public void onDestroy() {//停止服务的时候被调用
_nm.cancel(R.string.service_started);
Log.e(TAG, "============> TestService.onDestroy");
}
private void showNotification() {
Notification notification = new Notification(R.drawable.face_1,
"Service started", System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, TestServiceHolder.class), 0);
// must set this for content view, or will throw a exception
notification.setLatestEventInfo(this, "Test Service",
"Service started", contentIntent);
_nm.notify(R.string.service_started, notification);
}
}
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
public class TestService extends Service {
private static final String TAG = "TestService";
private NotificationManager _nm;
@Override
public IBinder onBind(Intent i) {
Log.e(TAG, "============> TestService.onBind");
return null;
}
public class LocalBinder extends Binder {
TestService getService() {
return TestService.this;
}
}
@Override
public boolean onUnbind(Intent i) {
Log.e(TAG, "============> TestService.onUnbind");
return false;
}
@Override
public void onRebind(Intent i) {
Log.e(TAG, "============> TestService.onRebind");
}
@Override
public void onCreate() {// 服务第一次被启动时调用
Log.e(TAG, "============> TestService.onCreate");
_nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
showNotification();
}
@Override//在onCreate()方法后被调用
public void onStart(Intent intent, int startId) {
Log.e(TAG, "============> TestService.onStart");
}
@Override
public void onDestroy() {//停止服务的时候被调用
_nm.cancel(R.string.service_started);
Log.e(TAG, "============> TestService.onDestroy");
}
private void showNotification() {
Notification notification = new Notification(R.drawable.face_1,
"Service started", System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, TestServiceHolder.class), 0);
// must set this for content view, or will throw a exception
notification.setLatestEventInfo(this, "Test Service",
"Service started", contentIntent);
_nm.notify(R.string.service_started, notification);
}
}
3.配置文件:
Java代码
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TestServiceHolder" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:enabled="true" android:name=".TestService"
android:process=":remote" />
</application>
发表评论
-
Android图片加载框架最全解析(二),从源码的角度理解Glide的执行流程
2018-05-10 17:33 513https://blog.csdn.net/guolin_bl ... -
Volley配置OkHttp的那些事儿
2018-04-27 15:26 988前言 打一来这公司, ... -
阿里云ECS上APP访问异常或超时
2018-04-27 15:14 894App访问ECS连接超时或访问慢: 具体情况描述: 1. ... -
Android中我为什么发不了邮件--Android邮件发送详解
2012-04-16 11:01 1183Android中我为什么发不了邮件???我手机里明 ... -
TCP实现P2P通信、TCP穿越NAT的方法、TCP打洞
2011-08-20 15:37 2817这个标题用了两个顿号 ... -
代码中如何通过intent安装apk文件
2011-06-30 14:50 1438在系统安装的的底层常规应用中,是通过PackageInstal ... -
远程下载安装apk文件到手机或模拟器
2011-06-30 14:45 917废话少说,直接上代码,会加上详细注释: 测试地址:http: ... -
Android客户端Socket连接PC服务器端(转载加评论)
2011-06-30 14:39 1963先上代码: 1. SocketConnect.java文件 ...
相关推荐
通过`QName`指定命名空间和服务名,创建`Service`对象,进一步获取`MyServices`接口的实现,从而调用服务方法。例如,`ms.add(12, 55)`会执行加法操作。 最后,如果需要在本地生成Web服务的客户端代理类,可以使用`...
在本案例中,"webservices简单的测试用例,必须可用" 涉及的是Android平台上的Web服务测试,特别是针对返回JSON数据的处理。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,广泛用于服务器向客户端...
描述中提到"google_play_services 最新",意味着这个压缩包可能包含了Google Play服务的最新更新或SDK,供开发者在开发和测试应用时使用。开发者可以使用这些更新来升级他们应用程序中的Google Play服务依赖,以确保...
- 使用 Reporting Services 配置工具来配置报表服务器模式(本地模式或 SharePoint 集成模式)、网络服务、Web 服务 URL、数据库实例等信息。 2. **验证配置**: - 访问 Web 服务 URL 来确认报表服务器是否配置...
"webService通用客户端测试工具"的使用方法通常包括以下几个步骤: 1. **配置服务URL**:首先,用户需要输入Web服务的地址,即WSDL(Web Services Description Language)文件的URL。WSDL文件描述了服务的接口,...
文档《四款主流测试工具的测试流程.doc》可能涵盖了LoadRunner、JMeter、 Gatling 和 Locust 等工具的使用方法。这些工具能够帮助我们创建复杂的真实世界场景,模拟多种用户行为,并收集详细的性能数据。 1. ...
总之,C#为Webservice测试提供了强大的支持,而使用专门的测试工具能够进一步提升测试效率和质量。无论是手动编写测试代码还是利用现成的工具,都需要全面考虑接口的功能性、健壮性和性能,确保Web服务的可靠性和...
在本书中,作者Charitha Kankanamge以实践者和QA领导者的身份,详细讲解了soapUI的使用方法和最佳实践。作为WSO2公司质量保证和高级技术领导,拥有超过9年的软件质量保证经验,专注于面向服务架构(SOA)和中间件...
### SQL Server 2005 Analysis Services 数据挖掘算法扩展方法 #### 一、引言 在数据挖掘领域,SQL Server 2005 Analysis Services (SSAS) 提供了一套强大的工具集,用于构建和管理复杂的多维数据模型以及进行预测...
- **测试 Web Service**:可以通过调用服务接口进行进一步的测试。 #### 三、常见问题及解决方案 1. **BOM Signature 问题**: - 当使用某些文本编辑器(如 EmEditor)编写测试用例时,这些编辑器可能会在文件...
根据压缩包子文件的文件名称列表,我们只有一个条目`qwc-services-core-0.1.3`,这通常意味着解压后会得到一个包含Python源代码、元数据文件(如`setup.py`和`MANIFEST.in`)、测试用例、文档等的目录结构。...
- 使用 `@WebMvcTest` 进行单元测试,模拟 HTTP 请求,验证控制器方法的行为。 - 利用 `MockMvc` 工具进行集成测试,检查整个 MVC 请求处理链路。 9. **API 文档和版本管理** - 通过 Swagger 或其他工具自动生成...
- **软件测试流程**:详述了软件测试在软件开发周期中的具体步骤,包括需求测试、单元测试、集成测试、系统测试、性能测试、用户测试和回归测试等,每一项测试的目的、方法和注意事项都被详细介绍。 - **软件项目...
"xfire_demo java_webservices webservices xfire_demo xfire_tomcat" 进一步强调了关键概念:XFire的演示(xfire_demo)、Java Web服务(java_webservices)、Web服务(webservices)以及XFire与Tomcat的结合使用...
总的来说,"webservices_helloworld_javabean"项目旨在教授初学者如何使用JavaBean构建Web服务,涵盖从创建JavaBean、定义服务接口、部署服务到测试服务的基本流程。通过学习这个项目,开发者可以深入理解Web服务的...