2013-04-27 36 views
1

我想在我的應用程序中使用凹凸API。我將Bump庫項目導入到我的項目中。有人知道爲什麼會發生這種情況嗎?權限拒絕:廣播意圖未導出

04-26 21:00:15.828: W/ActivityManager(528): Permission denied: checkComponentPermission() owningUid=10072 

04-26 21:00:15.828: W/BroadcastQueue(528): Permission Denial: broadcasting Intent { act=com.bump.core.util.LocationDetector.PASSIVE_LOCATION_UPDATE flg=0x10 (has extras) } from com.helloworld.utility (pid=-1, uid=10071) is not exported from uid 10072 due to receiver com.bumptech.bumpga/com.bump.core.service.PassiveLocationReceiver 

這裏是我的AndroidManifest.xml中的相關部分:

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.VIBRATE" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 

<service android:name="com.bump.api.BumpAPI"> 
    <intent-filter> 
     <action android:name="com.bump.api.IBumpAPI" /> 
    </intent-filter> 
</service> 

我想看看Android的源裏面,它是從這裏起源於ActivtiyManagerService.java:

// If the target is not exported, then nobody else can get to it. 
if (!exported) { 
    Slog.w(TAG, "Permission denied: checkComponentPermission() owningUid=" + owningUid); 
    return PackageManager.PERMISSION_DENIED; 
} 

我不確定在這種情況下「目標」是什麼以及需要「導出」什麼。有沒有其他人看過這個?

謝謝你們!

回答

2

在服務標籤中使用exported屬性。例如清單中的<service android:exported="true" android:name="com.bump.api.BumpAPI">。導出的屬性意味着其他應用程序可以訪問它(活動/服務/廣播等)。在您的代碼中,exported布爾值爲false,因此條件if(!exported)始終爲真,因此它從那裏返回。讓我提到的變化,讓我們知道如果問題仍然存在。

對於文檔去here

2

您是否按照here所述註冊了BroadcastReceiver?

private final BroadcastReceiver receiver = new BroadcastReceiver() { 
@Override 
public void onReceive(Context context, Intent intent) { 
    final String action = intent.getAction(); 
    try { 
     if (action.equals(BumpAPIIntents.DATA_RECEIVED)) { 
      Log.i("Bump Test", "Received data from: " + api.userIDForChannelID(intent.getLongExtra("channelID", 0))); 
      Log.i("Bump Test", "Data: " + new String(intent.getByteArrayExtra("data"))); 
     } else if (action.equals(BumpAPIIntents.MATCHED)) { 
      api.confirm(intent.getLongExtra("proposedChannelID", 0), true); 
     } else if (action.equals(BumpAPIIntents.CHANNEL_CONFIRMED)) { 
      api.send(intent.getLongExtra("channelID", 0), "Hello, world!".getBytes()); 
     } else if (action.equals(BumpAPIIntents.CONNECTED)) { 
      api.enableBumping(); 
     } 
    } catch (RemoteException e) {} 
} 
}; 

IntentFilter filter = new IntentFilter(); 
filter.addAction(BumpAPIIntents.CHANNEL_CONFIRMED); 
filter.addAction(BumpAPIIntents.DATA_RECEIVED); 
filter.addAction(BumpAPIIntents.NOT_MATCHED); 
filter.addAction(BumpAPIIntents.MATCHED); 
filter.addAction(BumpAPIIntents.CONNECTED); 
registerReceiver(receiver, filter); 

同時檢查文檔android:exported

默認值取決於該活動是否包含意圖過濾器。沒有任何過濾器意味着該活動只能通過指定其確切的類名稱來調用。這意味着該活動僅用於應用程序內部使用(因爲其他人不知道類名)。所以在這種情況下,默認值是「false」。另一方面,至少存在一個過濾器意味着該活動是爲外部使用的,所以默認值爲「true」。

相關問題