ここにGoogleマップが表示され、通知も発行したいのですが、クリックすると、通知によってメインのアクティビティ、つまりGoogleマップに移動しますが、通知は発行されません。ここに 2 つのクラスとマニフェスト ファイルがあります。
public class MainActivity extends FragmentActivity{
protected GoogleMap gMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
if (gMap == null) {
Toast.makeText(this, "Google Maps not available",
Toast.LENGTH_LONG).show();
gMap.setMyLocationEnabled(true);
}
}
通知クラス、
public class Notify extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.jollyr)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setContentTitle("Flood Warning")
.setContentText("You are in Danger Zone");
// Sets an ID for the notification
int notId = 001;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(notId, mBuilder.build());
Intent i=new Intent(this,MainActivity.class);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
i,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
}
}
マニフェストファイル、
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.map.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>
<activity
android:name="com.example.map.Notify"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.map.Notify" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<meta-data
android:name="Package+.v2.API_KEY"
android:value="Key here" />
</application>
</manifest>