Is this warning caused by my app? - “Implicit intents with startService are not safe”

て烟熏妆下的殇ゞ 提交于 2019-12-21 03:26:07

问题


I get this warning in Logcat while developing. Is it caused by my app?

16699-16699/tld.me.myapp.debug W/ContextImpl﹕ Implicit intents with startService are not safe: Intent { act=com.google.android.location.internal.GoogleLocationManagerService.START } android.content.ContextWrapper.bindService:517 com.google.android.gms.internal.v.a:-1 com.google.android.gms.internal.u.connect:-1

I can't see where I could be causing this in my code.


回答1:


http://developer.android.com/reference/android/content/Intent.html

Intent Resolution

There are two primary forms of intents you will use.

Explicit Intents have specified a component (via setComponent(ComponentName) or setClass(Context, Class)), which provides the exact class to be run. Often these will not include any other information, simply being a way for an application to launch various internal activities it has as the user interacts with the application. Implicit Intents have not specified a component; instead, they must include enough information for the system to determine which of the available components is best to run for that intent. When using implicit intents, given such an arbitrary intent we need to know what to do with it. This is handled by the process of Intent resolution, which maps an Intent to an Activity, BroadcastReceiver, or Service (or sometimes two or more activities/receivers) that can handle it.

May be its saying to mention the component explicitly.




回答2:


I faced exactly the same problem and it seems to be that in the Google Play Services Library, they missed to put android:exported="true" in their <service> declaration.

Before Android 5.0, it was allowed to start services with implicit intents, but now it's not possible, and instead of having a warning, you will have an Exception.

They need to fix their stuff.




回答3:


While setting the filters in the service that you are trying to access, you have to make the exported:"false" to exported:"true". Such as below:

<service
        android:name=".MyService"
        android:exported="true" >
        <intent-filter >
            <action android:name="com.pluralsight.intentrelatedstuffs.action.LOG_TIME"></action>
        </intent-filter>
    </service>


来源:https://stackoverflow.com/questions/22050813/is-this-warning-caused-by-my-app-implicit-intents-with-startservice-are-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!