我來這裏,因爲我真的不明白爲什麼我沒有得到BroadcastReceiver 我有一個名爲NotifService的服務創建通知。 我創建了一個接收器下面這段代碼:無法獲得BroadcastReceiver
public class MyReceiver extends BroadcastReceiver {
Intent myIntent;
@Override
public void onReceive(Context context, Intent intent) {
Log.d("2erlog","2erlog>>>>>>>>>>>>>>>>>>>>>>>>");
myIntent = new Intent(context, NotifService.class);
context.startService(myIntent);
Log.d("3erlog","3erlog>>>>>>>>>>>>>>>>>>>>>>>>");
}
}
在這裏你可以看到我的清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.notifplugunplug"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<service android:name="NotifService"/>
<activity
android:name="com.example.notifplugunplug.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Declaring broadcast receiver for BOOT_COMPLETED event -->
<receiver android:name=".MyReceiver" android:enabled="true" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
</manifest>
我知道,服務永遠不啓動,因爲我從來沒有看到日誌,我創建,我不看到通知從服務中出現。
謝謝你們!
你有沒有運行該應用程序?即啓動了MainActivity? – NickT
是的主要活動是用來啓動服務來測試,如果問題是我的廣播接收器或其他地方。活動開始良好(但我把評論的活動,以便從broadcastReceiver做到這一點)! – Eydolol
你的應用程序安裝在哪裏?內部存儲器或SD卡?如果是SD卡,則在安裝SD卡之前將發送'BOOT_COMPLETED'action,並且您的應用程序不會處於活動狀態。 – Squonk