广播接收器中的权限拒绝

时间:2019-03-29 05:38:57

标签: android permissions receiver

我正在尝试将广播接收器从应用B转换为应用A,但由于出现错误消息而似乎无法通信(请参见下文)。此外,我正尝试在此论坛中搜索解决特定问题的答案,但由于情况的不同,它们似乎都对我没有帮助。

错误:

$("#session_id, #start_date").on('change', function() {
    var d1 = $( "#session_id" ).val();
    var d2 = $( "#start_date" ).val();

    $("#tbody").empty();


    if(d1 != null || d1 != undefined){
        kl1 = "if (obj1[i][0] !== d1 && row > -1) continue;";
        v(kl1);
    }

    if(d2 != null || d2 != undefined){
        var kl = "if (obj1[i][1] !== d2 && row > -1) continue;"
        v(kl);
    }

    function v(data){
        for (var i = 0; i < obj1.length; i++) {
                data;
            row++;
        var newTr = table.insertRow(-1);
        newTr.insertCell(-1).appendChild(document.createTextNode(obj1[i][1]));
        newTr.insertCell(-1).appendChild(document.createTextNode(obj1[i][2]));
        newTr.insertCell(-1).appendChild(document.createTextNode(obj1[i][3]));
        newTr.insertCell(-1).appendChild(document.createTextNode(obj1[i][4]));
        newTr.insertCell(-1).appendChild(document.createTextNode(obj1[i][5]));
    }
}
});

清单:

应用A中的权限:

2019-03-28 07:24:23.973 1636-1650/? W/BroadcastQueue: Permission Denial: receiving Intent { act=com.example.cataloguemoviefinal.ACTION_UPDATE_WIDGET_DATA flg=0x30 } to com.example.cataloguemoviefinal/receiver.UpdateWidgetDataReceiver requires com.example.cataloguemoviefinal.UPDATE_WIDGET_DATA due to sender com.example.favoritefilmapp (uid 10147)

应用A中的接收器:

<!-- Permission declaration for updating widget content -->
    <permission
        android:name="com.example.cataloguemoviefinal.UPDATE_WIDGET_DATA" />

应用A中的广播接收器:

<!-- Custom Broadcast receiver -->
        <receiver
            android:name=".receiver.UpdateWidgetDataReceiver"
            android:permission="com.example.cataloguemoviefinal.UPDATE_WIDGET_DATA"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="com.example.cataloguemoviefinal.ACTION_UPDATE_WIDGET_DATA"/>
            </intent-filter>
        </receiver>

在应用B中的清单:

public class UpdateWidgetDataReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO: This method is called when the BroadcastReceiver is receiving
        // an Intent broadcast.
        Log.d("Action intent", intent.getAction());

        if(intent.getAction() != null){
            if(intent.getAction().equals("com.example.cataloguemoviefinal.ACTION_UPDATE_WIDGET_DATA")){
                // Log message
                Log.d("Testing receiver", "I got ur updates");

                AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

                int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, FavoriteMovieItemWidget.class));

                appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.favorite_movie_stack_view);
            }

        }
    }
}

应用B中的发件人消息:

 <!-- This code is used for custom BroadcastReceiver -->
    <uses-permission android:name="com.example.cataloguemoviefinal.UPDATE_WIDGET_DATA"/>

我应该怎么做才能使广播接收器从应用B接收消息到应用A(显示Log.message)?

对不起,如果我写了太多代码,但是这些是可能出现错误的必要部分。

谢谢。

1 个答案:

答案 0 :(得分:0)

Android O具有隐式广播限制,您是否在Android o或更高版本上运行? https://developer.android.com/about/versions/oreo/background,搜索“广播限制”