简体   繁体   English

Android BroadcastReciever BOOT_COMPLETED SecurityException

[英]Android BroadcastReciever BOOT_COMPLETED SecurityException

I search on internet 2 days but find nothing this is my adb command我在互联网上搜索了 2 天,但什么也没找到,这是我的 adb 命令

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED

and``和``

this is my error code这是我的错误代码

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)

AND THİS İS MY 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主要活动.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();

    }



}

please help me I try everything on internet but There are no results I think this problem about permission what can I do in manifest file help me I want it this broadcast recieve to work at startup:(请帮助我,我在互联网上尝试了一切,但没有结果我认为这个关于权限的问题我可以在清单文件中做什么帮助我我希望这个广播接收在启动时工作:(

The docs say:文档说:

This is a protected intent that can only be sent by the system.这是一个只能由系统发送的受保护意图。

https://developer.android.com/reference/android/content/Intent#ACTION_BOOT_COMPLETED https://developer.android.com/reference/android/content/Intent#ACTION_BOOT_COMPLETED

Which means that you cant send this intent.这意味着您无法发送此意图。

You currently have <action android:name="android.permission.BOOT_COMPLETED" /> set as an intent filter, which won't work.您目前已将<action android:name="android.permission.BOOT_COMPLETED" />设置为意图过滤器,但它不起作用。

Add <action android:name="android.intent.action.BOOT_COMPLETED" /> to the intent filter of your SensorRestarterBroadcastReceiver , then reboot your device.<action android:name="android.intent.action.BOOT_COMPLETED" />添加到SensorRestarterBroadcastReceiver的意图过滤器中,然后重新启动设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM