0

谷歌地图显示在这里,我也想发出通知,当我点击它时,通知应该把我带到主要活动,即谷歌地图,但没有发出通知。这是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>
4

0 回答 0