具有不同ID的多个待定意图

时间:2016-03-18 02:12:09

标签: java android android-pendingintent

我有一个很大的问题,有多个待定意图,有不同的位置,并且仅针对最后一个触发。我尝试更改每个pendint意图的唯一ID但不起作用。错误在哪里?

MainActivity.java

private void AddpromoAlert(){
    showpDialog();

    userDbHelper=new UserDbHelper(thiscontext);
    sqLiteDatabase=userDbHelper.getReadableDatabase();
    cursor=userDbHelper.getMarker(sqLiteDatabase);

    if (cursor.getCount()!=0){

        if(cursor.moveToFirst())
        {
            do {
                String id,name, addr,  lati, longi;
                id = cursor.getString(0);
                name = cursor.getString(1);
                addr = cursor.getString(2);
                lati = cursor.getString(3);
                longi = cursor.getString(4);

                if(attivo.equalsIgnoreCase("si")){

                    if (promo.length() >= 5) {

                        Intent proximityIntent = new Intent (getContext(), ProximityActivity.class);

                        proximityIntent.putExtra("id", id);
                        proximityIntent.putExtra("desc", name);
                        proximityIntent.putExtra("addr", addr);
                        proximityIntent.putExtra("lati", lati);
                        proximityIntent.putExtra("longi", longi);

                        pendingIntent = PendingIntent.getActivity(getContext(), Integer.parseInt(id), proximityIntent,Intent.FLAG_ACTIVITY_NEW_TASK);
                        locationManager.addProximityAlert(Double.parseDouble(lati), Double.parseDouble(longi), 30, -1, pendingIntent);



                    }
                }


            }while (cursor.moveToNext());

        }

    }

    userDbHelper.close();
    hidepDialog();
}

ProximityActivity.java

public class ProximityActivity extends AppCompatActivity{
String notificationTitle;
String notificationContent;
String tickerMessage;

PendingIntent pendingIntent;
String RicName,RicAddr,RicID;
Double latiRic,longiRic;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    boolean proximity_entering = getIntent().getBooleanExtra(LocationManager.KEY_PROXIMITY_ENTERING, true);

    String RicName=getIntent().getExtras().getString("desc");
    String RicAddr=getIntent().getExtras().getString("addr");
    final double latiRic=getIntent().getExtras().getDouble("lati");
    final double longiRic=getIntent().getExtras().getDouble("longi");
    final String RicID=getIntent().getExtras().getString("id");

    if(proximity_entering)
    {
        notificationTitle="notification";
        notificationContent="Enter pov";
        tickerMessage = "alarm";
        SetNotification();
    }
    else
    {

    notificationTitle="notification'";
    notificationContent="leave pov";
    tickerMessage = "alarm";

    }


    finish();


}
public void SetNotification(){
    Intent notificationIntent = new Intent(getApplicationContext(),ViewMarkerPopup.class);
    notificationIntent.putExtra("content", notificationContent );
    notificationIntent.putExtra("desc", RicName);
    notificationIntent.putExtra("addr", RicAddr);
    notificationIntent.putExtra("lati", latiRic);
    notificationIntent.putExtra("longi", longiRic);



    notificationIntent.setData(Uri.parse("tel:/"+ (int)System.currentTimeMillis()));


    pendingIntent = PendingIntent.getActivity(getApplicationContext(), Integer.parseInt(RicID), notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);


    NotificationManager nManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);


    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext())
            .setWhen(System.currentTimeMillis())
            .setContentText(notificationContent)
            .setContentTitle(notificationTitle)
            .setSmallIcon(R.drawable.centerlogo, 3)
            .setAutoCancel(true)
            .setTicker(tickerMessage)

            .setContentIntent(pendingIntent);


    long[] v = {500, 1000};
    notificationBuilder.setVibrate(v);




    Notification notification = notificationBuilder.build();


    nManager.notify((int) System.currentTimeMillis(), notification);


    finish();
}

}

我正在寻找解决方案几周,tnx回复!

1 个答案:

答案 0 :(得分:0)

在此电话会议中:

pendingIntent = PendingIntent.getActivity(getContext(),
   Integer.parseInt(id), proximityIntent,Intent.FLAG_ACTIVITY_NEW_TASK);

删除Intent.FLAG_ACTIVITY_NEW_TASK并将其替换为0。这是flags参数,您应该只在这里传递PendingIntent个标志,而不是Intent个标志。