同时单击推送通知,不会在Android中使用待处理的意图进行相应的活动



我正在使用挂起的意图在通过火力基地获得推送通知后移动到另一个活动。我尝试了几乎所有的解决方案,但是每次单击通知时,它都会重定向到登录屏幕。

Intent intent = new Intent(this, PendingTicketFragment.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.logo_river)
.setContentTitle("CEMPIA Message")
.setContentText("CEMPIA Ticket Escalated to you for"+" "+lp.getUsername())
.setAutoCancel(true)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logo_river))
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
assert notificationManager != null;
notificationManager.notify(1 /* ID of notification */, notificationBuilder.build());

@Shane PendingTicketFragment 是一个片段

令牌 API.java

public class TOKEN_API extends AsyncTask<Void, Void, String> {
SingletonePage1Data page1Data = SingletonePage1Data.getSingletonePage1Data();
SingleToneLoginProperties lp = SingleToneLoginProperties.getSingleToneLoginProperties();
String targetURL;
String token;
private Activity act;
ProgressDialog mProgressDialog;
private final static int NOTIFICATION_ID = 412434;
public TOKEN_API(String token){
this.token=token;
}
public TOKEN_API(String token, Activity act){
this.token=token;
this.act=act;
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
//        mProgressDialog = new ProgressDialog(act);
//        mProgressDialog.setMessage("Prepareing .....");
//        mProgressDialog.setIndeterminate(true);
//        mProgressDialog.setProgress(0);
//        //mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
//        mProgressDialog.setCancelable(false);
//mProgressDialog.show();
}
//-----------------------------------------------------------------
protected String doInBackground(Void... params) {
String ret_str = "";
try {
Log.e("ERROR","1");
targetURL = CaLoginActivity.server_ip+"/json/updateToken?userID="+lp.getUserid()+"&tokenID="+token;
HttpPost post = new HttpPost(targetURL);
final HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 50000);
HttpClient fbClient = new DefaultHttpClient(httpParams);
//            post.setEntity(new UrlEncodedFormEntity(pairs));
HttpResponse response = fbClient.execute(post);
InputStream is = response.getEntity().getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is,"iso-8859-1"));
Log.e("ERROR","3");
String line = "";
while ((line = br.readLine()) != null) {
ret_str=ret_str+ line;
}
br.close();
is.close();
fbClient.getConnectionManager().shutdown();
Log.e("ERROR","2      "+targetURL);
// ============================================================================
} catch (Exception e) {
mProgressDialog.dismiss();
Log.e("ERROR", e.toString());
//            hand.sendEmptyMessage(0);
}
return ret_str;
}
@Override
protected void onPostExecute(String results) {
try{
Log.e("TOKEN_API RETURN DATA", results.toString());
// creating JSONObject
JSONObject jo = new JSONObject(results);
String returnMsg = jo.getString("returnMsg");
String returnCode = jo.getString("returnCode");
String tokenID = jo.getString("tokenID");
String userID = jo.getString("userID");
Log.e("TOKEN_RES_FROM_SERVER", ""+returnMsg);
Log.e("TOKENID_RES_FROM_SERVER", ""+tokenID);
Log.e("TOKEN_UID_FROM_SERVER", ""+userID);
if(returnMsg.equalsIgnoreCase("success")||
returnCode.equalsIgnoreCase("200")){
Log.e("TOKEN_RESONSE_ERROR", "success");
Intent intent = new Intent(act, PendingTicketFragment.class);
//                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
//                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
//                Random randomGenerator = new Random();
//                int randomInt = randomGenerator.nextInt(100);
PendingIntent pendingIntent = PendingIntent.getActivity(act, 1 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(act)
.setSmallIcon(R.drawable.logo_river)
.setContentTitle("CEMPIA Message")
.setContentText("CEMPIA Ticket Escalated to you for"+" "+lp.getUsername())
.setAutoCancel(true)
.setLargeIcon(BitmapFactory.decodeResource(act.getResources(), R.drawable.logo_river))
.setSound(defaultSoundUri)
.setOngoing(true)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager)act.getSystemService(Context.NOTIFICATION_SERVICE);
assert notificationManager != null;
notificationManager.notify(1 /* ID of notification */, notificationBuilder.build());
}
if(returnMsg.equalsIgnoreCase("Updation failed")||
returnCode.equalsIgnoreCase("400")){
Log.e("TOKEN_RESONSE_ERROR", "Updation failed");
}
if(returnMsg.equalsIgnoreCase("exception")||
returnCode.equalsIgnoreCase("401")){
Log.e("TOKEN_RESONSE_ERROR", "exception");
}
if(returnMsg.equalsIgnoreCase("Token empty")||
returnCode.equalsIgnoreCase("402")){
Log.e("TOKEN_RESONSE_ERROR", "Token empty");
}
if(returnMsg.equalsIgnoreCase("userID empty")||
returnCode.equalsIgnoreCase("403")){
Log.e("TOKEN_RESONSE_ERROR", "userID empty");
}
}catch(Exception e){
Log.e("TOKEN_API ERROR", e.toString());
}
}
//------------------------------------------------------------------------------------------------
}

相关内容

  • 没有找到相关文章

最新更新