本文介绍了发送不受保护的广播com.motorola.motocare.INTENT_TRIGGER java.lang.Throwable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在堆栈溢出时搜索了不同的答案.即使禁用服务和广播接收器,它也会显示错误.

I have searched different answers on stack overflow. It shows the error even if I disable the services and broadcast receivers.

这是我的清单文件:-

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.appzoy.croatiaapp">

<!-- to make api calls -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<!-- for qr code scanning -->
<uses-permission android:name="android.permission.CAMERA" />

<application
    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:fullBackupContent="@xml/backup_descriptor">
    <activity
        android:name=".MainActivity" />
    <activity android:name=".LoginActivity" />
    <activity
        android:name=".TicketsListActivity"
        android:theme="@style/AppTheme.NoActionBar"
        android:windowSoftInputMode="stateHidden" />
    <activity android:name=".SplashActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".SettingsActivity"
       android:theme="@style/AppTheme.NoActionBar"></activity>
    <receiver android:name=".receivers.AlarmReceiverSubmit"
        android:exported="false"
        android:enabled="true"/>

    <service android:name=".services.AlarmService"
        android:exported="false"
        android:enabled="true"/>

    <receiver android:name=".receivers.NetworkChangeReceiver"
        android:exported="false"
        android:enabled="true">
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
        </intent-filter>
    </receiver>
</application>

每当我关闭导航抽屉时,SettingsActivity就会出现在前台,这是我使用以下代码设置警报的活动:-

Whenever I close the navigation drawer SettingsActivity appears to foreground and this is the activity where I set the alarm using this code:-

 private void setAlarm(Calendar calSet) {

    Toast.makeText(this, "Alarm is set @ " + calSet.getTime(), Toast.LENGTH_SHORT).show();

    Intent intent = new Intent(getBaseContext(), AlarmService.class);
    PendingIntent pendingIntent = PendingIntent.getService(getBaseContext(), 1, intent, 0);
    AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calSet.getTimeInMillis(),AlarmManager.INTERVAL_DAY, pendingIntent);
}

private void setAlarmSubmitTickets(Calendar calSet) {

    Toast.makeText(this, "Alarm is set @ " + calSet.getTime(), Toast.LENGTH_SHORT).show();

    Intent intent = new Intent(getBaseContext(), AlarmReceiverSubmit.class);
    intent.putExtra("selectedTime", txtSendTicketsTime.getText().toString());
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), 1, intent, 0);
    AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calSet.getTimeInMillis(),AlarmManager.INTERVAL_DAY, pendingIntent);
}

我的 Log 文件如下:-

推荐答案

如果您在 AndroidManifest.xml 中声明了"android:sharedUserId="android.uid.system",则声明受保护的广播.

If you have in your AndroidManifest.xml declared "android:sharedUserId="android.uid.system", then declare the protected broadcast.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourcompany.mypackage"
android:sharedUserId="android.uid.system">

<uses-sdk
    android:minSdkVersion="17"
    android:targetSdkVersion="24" />

<protected-broadcast android:name="com.motorola.motocare.INTENT_TRIGGER" />

您可以使用Android Studio进行构建.

这篇关于发送不受保护的广播com.motorola.motocare.INTENT_TRIGGER java.lang.Throwable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 09:49