天道酬勤,学无止境

android-service

Xiaomi Redmi Note 3 custom service not working?

Xiaomi Redmi Note 3 ,Any Custom service creating using code is disable when you clear application from background, issue not happen in samsung and other phone but happen in similar phones.

2021-09-24 02:58:46    分类:问答    android   android-service

service killed when app cloes just in huawei device

I make service to Toast a text always but just in huawei device service killed when i kill app. I don't know why? My service is: @Override public int onStartCommand(Intent intent, int flags, int startId) { onTaskRemoved(intent); new CountDownTimer(99999999L,5000 ) { @Override public void onTick(long arg0) { Toast.makeText(getApplicationContext(), "hihihi", Toast.LENGTH_LONG).show(); } @Override public void onFinish() { } }.start(); return START_STICKY; } @Override public IBinder onBind(Intent intent) { // TODO: Return the communication channel to the service. throw new

2021-09-23 22:00:25    分类:问答    android   android-service

Handler not executing Runnable in Instrumentation Test

I have written an Android instrumentation test that calls my service and receives an answer via an broadcast. The code to be tested, which speaks to the service, uses handler. In process of testing my test ^^ I noticed that the handlers are not behaving as expected. So I've written an test to check on this behaviour: import android.os.Handler; import android.support.test.annotation.UiThreadTest; import org.junit.Assert; import org.junit.Test; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @RunWith(AndroidJUnit4.class) public class HandlerTest { private

2021-09-23 18:52:19    分类:问答    java   android   testing   android-service   android-handler

What is the format for an android intent?

I'd like to know what is the format for an android intent. IE, what should I pass to the method : getBaseContext().startService(Intent); If I want to pass this: android.provider.CallLog.Calls.CONTENT_URI can i? What would be the format. Can someone give a good explanation of how to use Intents, and how to use it on Service implementation, like, startService(), or onStartCommand (Intent intent, int flags, int startId). Thanks!

2021-09-23 15:43:02    分类:问答    android   android-intent   android-service   android-contentprovider

Android - 如何从 Google Maps App Intent 获取 ETA? (还是位智?)(Android - How to get ETA from Google Maps App Intent? (Or Waze?))

问题 我正在开发 android 应用程序,女巫将导航到一个地方并根据 ETA 做一些事情。 我根本不想处理导航,这就是我使用 Intent 打开 Google Maps App 的原因。 有什么方法可以运行服务以从 Google Maps App 获取 ETA? 我可以使用 Waze 或任何其他导航应用程序吗? 如果不, 您如何看待每隔几分钟运行一次将从 Google Maps API 获得 ETA 的服务? 谢谢你的时间。 耶米。

2021-09-22 04:34:55    分类:技术分享    google-maps   android-intent   android-service   android-location

Android:如何解决来自服务的 Google API 连接失败?(Android: How to resolve Google API connection fail from a Service?)

问题 这是官方指南提供的代码,而这是导致问题的片段。 @Override public void onConnectionFailed(ConnectionResult result) { if (mResolvingError) { // Already attempting to resolve an error. return; } else if (result.hasResolution()) { try { mResolvingError = true; result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR); } catch (IntentSender.SendIntentException e) { // There was an error with the resolution intent. Try again. mGoogleApiClient.connect(); } } else { // Show dialog using GooglePlayServicesUtil.getErrorDialog() mResolvingError = true; GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this

2021-09-22 04:21:34    分类:技术分享    android   arguments   android-service   google-play-services

从正在运行的应用程序列表中关闭应用程序后,Android BroadcastReceiver 未被调用(Android BroadcastReceiver Not being called after app closed from Running App List)

问题 在尝试在 android 应用程序中实现通知时,我发现如果用户从正在运行的应用程序列表中关闭应用程序,通知将不再起作用(顶部向下滑动然后水平滑动 - 不是强制退出,这将关闭所有未来的调用根据谷歌规范)。 使用后退按钮有时会导致相同的行为,但并非总是如此。 从我研究的所有内容中,我的理解是,只有用户强制停止才能阻止广播接收器被调用。 这是 Android 清单中的相关代码和设置,请注意,当应用程序打开或通过主页按钮离开时,一切正常。 Android 清单相关部分: <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/> <uses-permission android:name="android.permission.WAKE_LOCK" /> <receiver android:name="mypackage.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" android:exported="true"> <intent-filter> <action android:name="com.google.android.c2dm.intent

2021-09-21 23:18:58    分类:技术分享    android   broadcastreceiver   android-service   google-cloud-messaging   android-notifications

绑定到服务时,IBinder 强制转换 *有时* 会导致 ClassCastException(IBinder casting *sometimes* results in ClassCastException when binding to service)

问题 我们在 Application 子类中绑定到我们的本地服务(同一进程),但有时我们会收到 ClassCastException。 我不知道如何修复它,因为每个人都说如果服务进程与您的应用程序不同,则会发生异常。 如何解决这个问题? 应用子类: public class App extends Application implements ServiceConnection { private ServiceApi exposedServiceApi; private EventBus eventBus; @Override public void onCreate() { super.onCreate(); bindToService(); } public void bindToService() { if (isConnectedToService()) { return; } boolean successfulBindCall = bindService(new Intent(this, MainService.class), this, BIND_IMPORTANT | BIND_AUTO_CREATE); if (successfulBindCall) { Timber.d("bindService() returned true -->

2021-09-21 22:36:37    分类:技术分享    android   android-service   android-service-binding

同步适配器不调用 onCreate(Sync Adapter not calling onCreate)

问题 我们需要启动 Sync Adapter 服务还是隐式启动框架? 我在Constructor 、 onCreate 、 onDestroy of Sync Adapter 服务上放置了一个日志,当我启动应用程序时,我没有在 logcat 中看到日志。 但是当我进行onCreate活动时 Intent serviceIntent = new Intent(context, SyncService.class); context.startService(serviceIntent); 我看到了日志。 请建议。 干杯,拉吉 回答1 同步适配器通过调用显式启动: ContentResolver.requestSync(ACCOUNT, AUTHORITY, null); 或类似方法: ContentResolver.addPeriodicSync( ACCOUNT, AUTHORITY, Bundle.EMPTY, SYNC_INTERVAL); https://developer.android.com/training/sync-adapters/running-sync-adapter.html 我强烈推荐这本书,尤其是前 200 页 http://www.wrox.com/WileyCDA/WroxTitle/Enterprise-Android-Programming

2021-09-21 16:16:31    分类:技术分享    android   android-intent   android-activity   android-service   android-syncadapter

将服务绑定到多个活动(binding a service to multiple activities)

问题 我的服务已正确绑定到我的第一个活动,但是当我尝试将其绑定到第二个活动时,它不起作用这是我的第一个活动的 onresume 和暂停代码 @Override protected void onResume() { super.onResume(); connection = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { service = null; } @Override public void onServiceConnected(ComponentName name, IBinder service) { shareInfos.this.service = (IService) service; } }; bindService(new Intent(this, shareInfos.class), connection, Context.BIND_AUTO_CREATE); } @Override protected void onPause() { super.onPause(); if (service != null) { service = null; unbindService(connection); } }

2021-09-21 09:00:09    分类:技术分享    android   android-service   android-service-binding