我在 android 清单文件中注册我的广播接收器时遇到问题
我创建了一个 BroadcastReceiver,它检查用户是否单击通知将他带到地图活动。问题是当我点击我的通知消失时,我认为这是由于我的广播接收器没有成功注册。我正在使用 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);
}
}