Android 如何启动应用程序并允许像whatsapp一样运行
我想在启动时运行应用程序服务器允许随时接收消息 不显示应用程序 此代码仅在引导显示通知两次时出现问题 但我想随时收到消息 这个“android:exported”重要吗?使用了什么 代码AndroidManifestAndroid 如何启动应用程序并允许像whatsapp一样运行,android,server,broadcastreceiver,Android,Server,Broadcastreceiver,我想在启动时运行应用程序服务器允许随时接收消息 不显示应用程序 此代码仅在引导显示通知两次时出现问题 但我想随时收到消息 这个“android:exported”重要吗?使用了什么 代码AndroidManifest <service android:name=".appService" android:exported="true" android:enabled="true"> </servic
<service
android:name=".appService"
android:exported="true"
android:enabled="true">
</service>
<receiver
android:name=".ServiceStarterBoot"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
代码服务
public class appService extends Service {
@Override
public void onCreate() {
super.onCreate();
lood();
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
throw new UnsupportedOperationException("Not yet implemented");
//return mBinder;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "onStartCommand", Toast.LENGTH_SHORT).show();
return super.onStartCommand(intent, flags, startId);
}
private void lood(){
SystemClock.sleep(3000);
Runnable runnable = new Runnable() {
public void run() {
boolean p= true ;
while(p) {
SystemClock.sleep(5000);
showNotification();
}
}
};
Thread mythread = new Thread(runnable);
mythread.start();
}
请帮忙
谢谢您必须使您的服务具有粘性: Service.START\u粘性 然后它是无限的,在被操作系统出于任何原因杀死时会重新启动 当用户未打开引导操作系统和应用程序时,它甚至会自动启动 致以最诚挚的问候。伪代码:
onStartCommand(..){
//e、 威菲利斯特纳
Wifilistener WF=新的Wifilistener(接口yourInterfaceCallBackMethod)
}
类似这样的情况。启动后仅显示两次通知,我该怎么办?这是正常行为。您的服务有创建线程的任务。服务完成后,任务就完成了。您必须实现服务的侦听器。例如,状态更改侦听器。当状态改变时。该服务将获取状态并激发您的方法。当程序打开且服务器正在运行时没有问题,问题是当服务器在引导模式下运行时
onStartCommand(..){