Android BroadcastReciever BOOT_COMPLETED SecurityException
Android BroadcastReciever BOOT_COMPLETED SecurityException
我在互联网上搜索了 2 天,但一无所获,这是我的
adb 命令
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED
和``
这是我的错误代码
Broadcasting: Intent { act=android.intent.action.BOOT_COMPLETED flg=0x400000 }
Security exception: Permission Denial: not allowed to send broadcast android.intent.action.BOOT_COMPLETED from pid=20913, uid=2000
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.BOOT_COMPLETED from pid=20913, uid=2000
at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:20474)
at com.android.server.am.HwActivityManagerService.broadcastIntentLocked(HwActivityManagerService.java:4226)
at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:21189)
at com.android.server.am.ActivityManagerShellCommand.runSendBroadcast(ActivityManagerShellCommand.java:614)
at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:154)
at android.os.ShellCommand.exec(ShellCommand.java:96)
at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:16149)
at android.os.Binder.shellCommand(Binder.java:574)
at android.os.Binder.onTransact(Binder.java:474)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:4285)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3286)
at com.android.server.am.HwActivityManagerService.onTransact(HwActivityManagerService.java:837)
at android.os.Binder.execTransact(Binder.java:675)
和
这是我的 MANİFEST FİLE
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mir.kitapkurdu"
>
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="com.huawei.permission.external_app_settings.USE_COMPONENT"/>`
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<permission android:name="android.permission.NET_ADMIN"
android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
android:protectionLevel="signature">
</permission>
<application
android:installLocation="internalOnly"
android:name=".App"
android:persistent="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name=".Gonderici" />
<activity android:name=".Register" />
<activity android:name=".BookComplate" />
<activity android:name=".SpeechGame" />
<activity android:name=".BooksActvty" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Categories" />
<activity android:name=".PageComplete" />
<activity android:name=".Membership" />
<receiver
android:name=".SensorRestarterBroadcastReceiver"
android:enabled="true"
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.REBOOT" />
<action android:name="android.permission.BOOT_COMPLETED" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED"/>
<action android:name="android.intent.action.ACTION_USER_PRESENT" />
<action android:name="com.mir.kitapkurdu.AN_INTENT" />
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<service android:name=".services.BootUpService"
android:permission="android.permission.BIND_JOB_SERVICE"/>
</application>
</manifest>
Mainactvity.class
package com.mir.kitapkurdu;
import android.Manifest;
import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Bundle;
import android.speech.SpeechRecognizer;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;
import com.mir.kitapkurdu.objects.User;
import com.mir.kitapkurdu.services.BootUpService;
import com.mir.kitapkurdu.services.Database;
import com.mir.kitapkurdu.services.NotificaionService;
public class MainActivity extends AppCompatActivity {
private SpeechRecognizer mSpeechRecognizer;
private Intent mSpeechRecognizerIntent;
private String space = " ";
private Button ileri;
private TextView ekranayazdir;
private TextView startVoiceInput;
private Database db;
public BroadcastReceiver br = new SensorRestarterBroadcastReceiver();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db= new Database(MainActivity.this);
User user=new User();
user = db.getLastAddedUser();
if (user.user_name==null)
{
serviceControl();
/* BootUpService mBootUpService = new BootUpService();
Intent mServiceIntent = new Intent(getApplicationContext(), mBootUpService.getClass());
startService(mServiceIntent);*/
broadcastIntent();
Intent intent = new Intent(this, Membership.class);
// intent.putExtra("category_id", 59);
startActivity(intent);
finish();
}else{
serviceControl();
/* BootUpService mBootUpService = new BootUpService();
Intent mServiceIntent = new Intent(getApplicationContext(), mBootUpService.getClass());
startService(mServiceIntent);*/
broadcastIntent();
Intent intent = new Intent(this, Gonderici.class);
intent.putExtra("user_id", user.user_id);
startActivity(intent);
finish();
}
}
private void serviceControl(){
NotificaionService mSensorService = new NotificaionService(getApplicationContext());
Intent mServiceIntent = new Intent(getApplicationContext(), mSensorService.getClass());
if (!isMyServiceRunning(mSensorService.getClass())) {
startService(mServiceIntent);
}
}
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
Log.i ("isMyServiceRunning?", true+"");
return true;
}
}
Log.i ("isMyServiceRunning?", false+"");
return false;
}
@Override
protected void onResume() {
super.onResume();
}
public void broadcastIntent() {
ComponentName receiver = new ComponentName(getPackageName(), "com.mir.kitapkurdu.SensorRestarterBroadcastReceiver");
PackageManager pm = MainActivity.this.getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
Intent intent = new Intent();
intent.setComponent(receiver);
sendBroadcast(intent);
}
@Override
protected void onStop() {
super.onStop();
}
}
请帮助我,我在互联网上尝试了一切,但没有结果我认为这个关于许可的问题我可以在清单文件中做什么帮助我我希望这个广播接收在启动时工作:(
文档说:
This is a protected intent that can only be sent by the system.
https://developer.android.com/reference/android/content/Intent#ACTION_BOOT_COMPLETED
这意味着你不能发送这个意图。
您目前已将 <action android:name="android.permission.BOOT_COMPLETED" />
设置为 intent 过滤器,这将不起作用。
将 <action android:name="android.intent.action.BOOT_COMPLETED" />
添加到 SensorRestarterBroadcastReceiver
的 intent 过滤器,然后重新启动您的设备。
我在互联网上搜索了 2 天,但一无所获,这是我的 adb 命令
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED
和``
这是我的错误代码
Broadcasting: Intent { act=android.intent.action.BOOT_COMPLETED flg=0x400000 }
Security exception: Permission Denial: not allowed to send broadcast android.intent.action.BOOT_COMPLETED from pid=20913, uid=2000
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.BOOT_COMPLETED from pid=20913, uid=2000
at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:20474)
at com.android.server.am.HwActivityManagerService.broadcastIntentLocked(HwActivityManagerService.java:4226)
at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:21189)
at com.android.server.am.ActivityManagerShellCommand.runSendBroadcast(ActivityManagerShellCommand.java:614)
at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:154)
at android.os.ShellCommand.exec(ShellCommand.java:96)
at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:16149)
at android.os.Binder.shellCommand(Binder.java:574)
at android.os.Binder.onTransact(Binder.java:474)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:4285)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3286)
at com.android.server.am.HwActivityManagerService.onTransact(HwActivityManagerService.java:837)
at android.os.Binder.execTransact(Binder.java:675)
和 这是我的 MANİFEST FİLE
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mir.kitapkurdu"
>
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="com.huawei.permission.external_app_settings.USE_COMPONENT"/>`
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<permission android:name="android.permission.NET_ADMIN"
android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
android:protectionLevel="signature">
</permission>
<application
android:installLocation="internalOnly"
android:name=".App"
android:persistent="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name=".Gonderici" />
<activity android:name=".Register" />
<activity android:name=".BookComplate" />
<activity android:name=".SpeechGame" />
<activity android:name=".BooksActvty" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Categories" />
<activity android:name=".PageComplete" />
<activity android:name=".Membership" />
<receiver
android:name=".SensorRestarterBroadcastReceiver"
android:enabled="true"
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.REBOOT" />
<action android:name="android.permission.BOOT_COMPLETED" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED"/>
<action android:name="android.intent.action.ACTION_USER_PRESENT" />
<action android:name="com.mir.kitapkurdu.AN_INTENT" />
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<service android:name=".services.BootUpService"
android:permission="android.permission.BIND_JOB_SERVICE"/>
</application>
</manifest>
Mainactvity.class
package com.mir.kitapkurdu;
import android.Manifest;
import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Bundle;
import android.speech.SpeechRecognizer;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;
import com.mir.kitapkurdu.objects.User;
import com.mir.kitapkurdu.services.BootUpService;
import com.mir.kitapkurdu.services.Database;
import com.mir.kitapkurdu.services.NotificaionService;
public class MainActivity extends AppCompatActivity {
private SpeechRecognizer mSpeechRecognizer;
private Intent mSpeechRecognizerIntent;
private String space = " ";
private Button ileri;
private TextView ekranayazdir;
private TextView startVoiceInput;
private Database db;
public BroadcastReceiver br = new SensorRestarterBroadcastReceiver();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db= new Database(MainActivity.this);
User user=new User();
user = db.getLastAddedUser();
if (user.user_name==null)
{
serviceControl();
/* BootUpService mBootUpService = new BootUpService();
Intent mServiceIntent = new Intent(getApplicationContext(), mBootUpService.getClass());
startService(mServiceIntent);*/
broadcastIntent();
Intent intent = new Intent(this, Membership.class);
// intent.putExtra("category_id", 59);
startActivity(intent);
finish();
}else{
serviceControl();
/* BootUpService mBootUpService = new BootUpService();
Intent mServiceIntent = new Intent(getApplicationContext(), mBootUpService.getClass());
startService(mServiceIntent);*/
broadcastIntent();
Intent intent = new Intent(this, Gonderici.class);
intent.putExtra("user_id", user.user_id);
startActivity(intent);
finish();
}
}
private void serviceControl(){
NotificaionService mSensorService = new NotificaionService(getApplicationContext());
Intent mServiceIntent = new Intent(getApplicationContext(), mSensorService.getClass());
if (!isMyServiceRunning(mSensorService.getClass())) {
startService(mServiceIntent);
}
}
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
Log.i ("isMyServiceRunning?", true+"");
return true;
}
}
Log.i ("isMyServiceRunning?", false+"");
return false;
}
@Override
protected void onResume() {
super.onResume();
}
public void broadcastIntent() {
ComponentName receiver = new ComponentName(getPackageName(), "com.mir.kitapkurdu.SensorRestarterBroadcastReceiver");
PackageManager pm = MainActivity.this.getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
Intent intent = new Intent();
intent.setComponent(receiver);
sendBroadcast(intent);
}
@Override
protected void onStop() {
super.onStop();
}
}
请帮助我,我在互联网上尝试了一切,但没有结果我认为这个关于许可的问题我可以在清单文件中做什么帮助我我希望这个广播接收在启动时工作:(
文档说:
This is a protected intent that can only be sent by the system.
https://developer.android.com/reference/android/content/Intent#ACTION_BOOT_COMPLETED
这意味着你不能发送这个意图。
您目前已将 <action android:name="android.permission.BOOT_COMPLETED" />
设置为 intent 过滤器,这将不起作用。
将 <action android:name="android.intent.action.BOOT_COMPLETED" />
添加到 SensorRestarterBroadcastReceiver
的 intent 过滤器,然后重新启动您的设备。