当点击推送通知时,不会使用android中的挂起意图进入相应的活动
在通过fire base获得推送通知后,我正在使用pending Intent移动到另一个活动。我尝试了几乎所有的解决方案,但每次单击通知时,它都会重定向到登录屏幕当点击推送通知时,不会使用android中的挂起意图进入相应的活动,android,android-intent,push-notification,firebase-cloud-messaging,android-pendingintent,Android,Android Intent,Push Notification,Firebase Cloud Messaging,Android Pendingintent,在通过fire base获得推送通知后,我正在使用pending Intent移动到另一个活动。我尝试了几乎所有的解决方案,但每次单击通知时,它都会重定向到登录屏幕 Intent intent = new Intent(this, PendingTicketFragment.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); PendingIntent pendingI
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());
}
}
//------------------------------------------------------------------------------------------------
}
公共类令牌\u API扩展了异步任务{
SingletonePage1Data page1Data=SingletonePage1Data.getSingletonePage1Data();
SingleToneLoginProperties lp=SingleToneLoginProperties.getSingleToneLoginProperties();
字符串targetURL;
字符串标记;
私人活动法;
进程对话框;
私有最终静态int通知_ID=412434;
公共令牌API(字符串令牌){
this.token=token;
}
公共令牌API(字符串令牌、活动法案){
this.token=token;
这个动作=动作;
}
@凌驾
受保护的void onPreExecute(){
//TODO自动生成的方法存根
super.onPreExecute();
//mProgressDialog=新建进度对话框(act);
//设置消息(“准备…”);
//mProgressDialog.setUndeterminate(true);
//mProgressDialog.setProgress(0);
////mProgressDialog.setProgressStyle(ProgressDialog.STYLE\u水平);
//mProgressDialog.setCancelable(假);
//mProgressDialog.show();
}
//-----------------------------------------------------------------
受保护字符串doInBackground(无效…参数){
字符串ret_str=“”;
试一试{
Log.e(“错误”,“1”);
targetURL=CaLoginActivity.server_ip+“/json/updateToken?userID=“+lp.getUserid()+”&tokenID=“+token;
HttpPost=新的HttpPost(targetURL);
最终HttpParams HttpParams=新的基本HttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams,50000);
HttpClient fbClient=新的默认HttpClient(httpParams);
//setEntity(新的UrlEncodedFormEntity(对));
HttpResponse response=fbClient.execute(post);
InputStream is=response.getEntity().getContent();
BufferedReader br=新的BufferedReader(新的InputStreamReader(is,“iso-8859-1”);
Log.e(“错误”,“3”);
字符串行=”;
而((line=br.readLine())!=null){
ret_str=ret_str+线路;
}
br.close();
is.close();
fbClient.getConnectionManager().shutdown();
Log.e(“错误”,“2”+目标URL);
// ============================================================================
}捕获(例外e){
mProgressDialog.disclose();
Log.e(“ERROR”,e.toString());
//hand.sendEmptyMessage(0);
}
返回ret_str;
}
@凌驾
受保护的void onPostExecute(字符串结果){
试一试{
Log.e(“TOKEN_API返回数据”,results.toString());
//创建JSONObject
JSONObject jo=新的JSONObject(结果);
字符串returnMsg=jo.getString(“returnMsg”);
字符串returnCode=jo.getString(“returnCode”);
String tokenID=jo.getString(“tokenID”);
字符串userID=jo.getString(“userID”);
Log.e(“来自服务器的令牌”,“返回消息”);
Log.e(“TOKENID\u RES\u FROM\u SERVER”,“”+TOKENID);
Log.e(“来自服务器的令牌”、“+userID”);
if(returnMsg.equalsIgnoreCase(“成功”)||
returnCode.equalsIgnoreCase(“200”)){
Log.e(“令牌响应错误”、“成功”);
Intent Intent=新意图(act,PendingTicketFragment.class);
//intent.addFlags(intent.FLAG\u ACTIVITY\u CLEAR\u TOP);
//intent.addFlags(intent.FLAG\u活动\u清除\u任务);
//intent.addFlags(intent.FLAG\u活动\u新任务);
intent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK | intent.FLAG_ACTIVITY_CLEAR_TASK);
//Random randomGenerator=新的Random();
//int randomInt=randomGenerator.nextInt(100);
PendingEvent PendingEvent=PendingEvent.getActivity(act,1/*请求代码*/,意图,
悬挂式帐篷(一杆旗帜);
Uri defaultSoundUri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_通知);
NotificationCompat.Builder notificationBuilder=新建NotificationCompat.Builder(act)
.setSmallIcon(右拉深,徽标_河)
.setContentTitle(“CEMPIA消息”)
.setContentText(“针对“+”+lp.getUsername()向您上报的CEMPIA票证”)
.setAutoCancel(真)
.setLargeIcon(BitmapFactory.decodeResource(act.getResources(),R.drawable.logo_河))
.setSound(defaultSoundUri)
.正在进行(正确)
.setContentIntent(挂起内容);
通知经理通知经理=
(NotificationManager)act.getSystemService(上下文通知服务);
assert notificationManager!=null;
notificationManager.notify(通知的1/*ID*/,notificationBuilder.build());
}
if(returnMsg.equalsIgnoreCase(“更新失败”)||
returnCode.equalsIgnoreCase(“400”)){
Log.e(“令牌响应错误”,“更新失败”);
}
if(returnMsg.equalsIgnoreCase(“异常”)||
returnCode.equalsIgnoreCase(“401”)){
Log.e(“令牌响应错误”、“异常”);
}
if(returnMsg.equalsIgnoreCase(“令牌为空”)||
returnCode.equalsIgnoreCase(“402”)){
Log.e(“令牌响应错误”、“令牌为空”);