2013-01-15 104 views
0

我有問題在無法註冊的BroadcastReceiver我在清單

我已經建立,如果用戶點擊它帶他到地圖活動的通知,其檢查廣播接收器Android清單文件中註冊我的廣播接收器。問題是,當我點擊我的通知消失時,我認爲這是由於我的broadcasrReceiver未成功註冊。我正在使用Eclipse IDE。

以下是我的Android清單XML

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.fyp_api_8_team" 
android:versionCode="1" 
android:versionName="1.0.0" android:installLocation="auto"> 

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

<uses-sdk android:minSdkVersion="9" /> 

<application 
    android:name="com.example.fyp_api_8_team.MyGobalClass" 
    android:icon="@drawable/shazam" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <uses-library android:name="com.google.android.maps" /> 

    <activity 
     android:name="com.example.fyp_api_8_team.SplashScreen" 
     android:label="@string/app_name" 
     android:theme="@android:style/Theme.NoTitleBar" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name="com.example.fyp_api_8_team.Login_Form" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN.Register_form" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name="com.example.fyp_api_8_team.Register_form" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN.Register_form" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name="com.example.fyp_api_8_team.Forget_form" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN.Forget_form" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name="com.example.fyp_api_8_team.Create_Meeting_Form" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN.Create_Meeting_form" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name="com.example.fyp_api_8_team.Create_Team_Form" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN.Create_Team_Form" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name="com.example.fyp_api_8_team.Map_Location" 
     android:label="@string/app_name" 
     android:theme="@android:style/Theme.NoTitleBar" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN.Map_Location" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name="com.example.fyp_api_8_team.Main" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN.Main" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name="com.example.fyp_api_8_team.Register_Form" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN.Register_Form" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 
    <activity android:name="com.example.fyp_api_8_team.MainPreferenceActivity" > 
    </activity> 
    <activity 
     android:name="com.example.fyp_api_8_team.Team_Members" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN.Create_Team_Form..Team_Members" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name="com.example.fyp_api_8_team.Show_Map" 
     android:label="@string/title_activity_show__map" > 
    </activity> 

    <service android:name="com.example.fyp_api_8_team.Services.ScheduleService" /> 
    <service android:name="com.example.fyp_api_8_team.Services.NotifyService" /> 
    <receiver android:name="com.example.fyp_api_8_team.MyBroadcastReceiver" android:enabled="true"></receiver> 
</application> 

這是MyBroadcastReceiver類

package com.example.fyp_api_8_team; 
import com.example.fyp_api_8_team.R; 
import com.example.fyp_api_8_team_AlertMap.Show_Map; 
import android.app.Notification; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent;  
import android.os.Vibrator; 
import android.util.Log; 


    public class MyBroadcastReceiver extends BroadcastReceiver { 
private NotificationManager mNotificationManager; 
public static int SIMPLE_NOTFICATION_ID; 
public static String title, Message; 
public static int Meetingid, pos; 

@Override 
public void onReceive(Context context, Intent intent) { 

    mNotificationManager = (NotificationManager) context 
      .getSystemService(Context.NOTIFICATION_SERVICE); 
    Notification notifyDetails = new Notification(
      R.drawable.stat_notify_more, "You Alarm is here", 
      System.currentTimeMillis()); 

    // take you to the Map class by notification click 
    Intent notificationIntent = new Intent(context, Show_Map.class); 

    PendingIntent myIntent = PendingIntent.getActivity(context, 0, 
      notificationIntent, 0); 

    // Sets the Map class for the particular notification of event 
    Show_Map.position = pos; 
    notifyDetails.setLatestEventInfo(context, title, 
      "Click on me to view you Meeting Location", myIntent); 

    notifyDetails.flags |= Notification.FLAG_AUTO_CANCEL; 
    notifyDetails.flags |= Notification.DEFAULT_SOUND; 
    mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails); 

    Log.i(getClass().getSimpleName(), "Sucessfully Notification Clicked"); 

    // Vibrate the mobile phone 
    Vibrator vibrator = (Vibrator) context 
      .getSystemService(Context.VIBRATOR_SERVICE); 
    vibrator.vibrate(2000); 
} 

}

+0

您的通知因爲是FLAG_AUTO_CANCEL而消失。你的活動沒有出現,因爲意圖缺乏FLAG_NEW_TASK – njzk2

+0

njzk2我創建了一個示例應用程序,當通知被點擊時,我將用戶帶到人聯繫系統服務。 –

+0

你有沒有日誌或任何可能有幫助的? – njzk2

回答

1

你需要聲明它是這樣的:

<receiver android:name="com.example.fyp_api_8_team.MyBroadcastReceiver"> 
      <intent-filter> 
       <action android:name="**your_action_name**" /> 
      </intent-filter> 
     </receiver> 
+0

你能更具體什麼我應該放在這裏。我想讓通知讓用戶進入顯示地圖活動 –