标签:
<!-- android:exported 这个属性用于指示该服务是否能够被其他应用程序组件调用或跟它交互。
如果设置为true,则能够被调用或交互,否则不能。设置为false时,
只有同一个应用程序的组件或带有相同用户ID的应用程序才能启动或绑定该服务。-->
<service android:name=".ServiceDemo" android:exported="false">
<!--android:name=“” The name of the Service subclass that implements the service 继承了Service的类,绝对路径:包名+类名-->
<intent-filter><!--隐式调用才会用到这个;代表了一种Intent的组合方式;一个组件可以有多个Intent-filter-->
<action android:name="com.demo.SERVICE_DEMO" /> <!--外界使用的名字-->
<category android:name="android.intent.category.DEFAULT" /> <!--只有加上这个别的应用才能通过上面的action找到该Service-->
</intent-filter>
</service><service android:name="com.yq.RemoteService" android:process=":remote" android:exported="true">
<!--android:name=“”The name of the Service subclass that implements the service 继承了Service的类,绝对路径:包名+类名-->
<intent-filter><!--隐式调用才会用到这个;代表了一种Intent的组合方式;一个组件可以有多个Intent-filter-->
<action android:name="com.yq.RemoteService" /> <!--Service对应名字-->
<category android:name="android.intent.category.DEFAULT" /> <!--只有加上这个别的应用才能通过上面的action找到该Service-->
</intent-filter>
</service>@Override
public int onStartCommand(Intent intent, int flags, int startId) {
new Thread(new Runnable() {
@Override
public void run() {
// 开始执行后台任务
}
}).start();
return super.onStartCommand(intent, flags, startId);
}
class MyBinder extends Binder {
public void startDownload() {
new Thread(new Runnable() {
@Override
public void run() {
// 执行具体的下载任务
}
}).start();
}
} CharSequence text = getText(R.string.remote_service_started);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Controller.class), 0); //指定点击该Notification的时候,应该跳转到的Activity
Notification notification = new Notification.Builder(this)
.setSmallIcon(R.drawable.stat_sample) // the status icon
.setTicker(text) // the status text
.setWhen(System.currentTimeMillis()) // the time stamp
.setContentTitle(getText(R.string.local_service_label)) // the label of the entry
.setContentText(text) // the contents of the entry
.setContentIntent(contentIntent) // The intent to send when the entry is clicked
.build();标签:
原文地址:http://blog.csdn.net/evan_man/article/details/51800263