问题描述
当设备在 android 上启动时,我一直在尝试测试服务,但我无法让它工作.我正在尝试使用 CMD 中的此命令启动它:
(在 ..AppDataLocalAndroidsdkplatform-tools 中)
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED
或
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n net.fstab.checkit_android/.MyReceiver
AndroidManifest.
<uses-permission android:name="android.permission.INTERNET"/><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/><uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/><uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/><uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/><申请android:name="com.example.tacache.sciopero.MyApplication"机器人:allowBackup =真"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:supportsRtl="true"android:theme="@style/AppTheme"><!-- 为 BOOT_COMPLETED 事件声明广播接收器.PER FARE UN SERVIZIO AVVIATO ALL'INIZIO --><receiver android:name="com.example.tacache.sciopero.MyReceiver" android:exported="true"><意图过滤器><action android:name="android.intent.action.BOOT_COMPLETED"/></意图过滤器></接收器><activity android:name=".MainActivity" android:exported="true"><意图过滤器><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></意图过滤器></activity><!-- 注意:这是自动生成的,用于将 Google Play 服务添加到您的项目中应用索引.有关更多信息,请参阅 https://g.co/AppIndexing/AndroidStudio.--><元数据android:name="com.google.android.gms.version"android:value="@integer/google_play_services_version"/></应用程序></清单>
我的接收器类是这样的:
public class MyReceiver extends BroadcastReceiver {@覆盖public void onReceive(上下文上下文,意图意图){System.out.println("MyReceiver !!!!");Intent startServiceIntent = new Intent(context, MioServizio.class);context.startService(startServiceIntent);}}
我的 dos 命令的答案是这样的:
广播:意图 { act=android.intent.action.BOOT_COMPLETED cat=[android.intent.category.HOME] cmp=net.fstab.checkit_android/.MyReceiver }java.lang.SecurityException:权限拒绝:不允许从 pid=3715, uid=2000 发送广播 android.intent.action.BOOT_COMPLETED在 android.os.Parcel.readException(Parcel.java:1683)在 android.os.Parcel.readException(Parcel.java:1636)在 android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:3507)在 com.android.commands.am.Am.sendBroadcast(Am.java:772)在 com.android.commands.am.Am.onRun(Am.java:404)在 com.android.internal.os.BaseCommand.run(BaseCommand.java:51)在 com.android.commands.am.Am.main(Am.java:121)在 com.android.internal.os.RuntimeInit.nativeFinishInit(NativeMethod)在 com.android.internal.os.RuntimeInit.main(RuntimeInit.java:262)
为什么我有这个错误java.lang.SecurityException: Permission Denial"?
我遇到了同样的问题并通过这个解决:
尝试以 root 模式重新启动 ADB: adb root然后像这样广播 BOOT_COMPLETED
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED-p yourpackage.app
I've been trying to test a service when a device boots up on android, but I cannot get it to work.I'm trying to start it with this command from CMD:
(in ..AppDataLocalAndroidsdkplatform-tools)
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED
or
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n net.fstab.checkit_android/.MyReceiver
AndroidManifest.
<?
my receiver class is this:
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
System.out.println("MyReceiver !!!!");
Intent startServiceIntent = new Intent(context, MioServizio.class);
context.startService(startServiceIntent);
}
}
the answer to my dos command is this:
Broadcasting: Intent { act=android.intent.action.BOOT_COMPLETED cat=[android.intent.category.HOME] cmp=net.fstab.checkit_android/.MyReceiver }
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.BOOT_COMPLETED from pid=3715, uid=2000
at android.os.Parcel.readException(Parcel.java:1683)
at android.os.Parcel.readException(Parcel.java:1636)
at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:3507)
at com.android.commands.am.Am.sendBroadcast(Am.java:772)
at com.android.commands.am.Am.onRun(Am.java:404)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:51)
at com.android.commands.am.Am.main(Am.java:121)
at com.android.internal.os.RuntimeInit.nativeFinishInit(NativeMethod)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:262)
Why I have this error "java.lang.SecurityException: Permission Denial"?
I had same problem and solve by this:
Try restarting ADB in root mode: adb root
and then broadcast BOOT_COMPLETED like this
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED
-p yourpackage.app
这篇关于Android - 尝试在启动时测试服务(java.lang.SecurityException:权限拒绝)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!