Ich habe eine Benachrichtigung mit AsyncTask implementiert und was ich tun möchte, ist für die Benachrichtigung, um Daten zu übergeben, wenn geklickt wird. Immer wenn ich auf die Benachrichtigung klicke, sollte ich mit einem Fragment fortfahren, das die Daten erhalten wird. Ich verwende Bundle
für die Daten, die an meine Fragmentklasse übergeben werden sollen. WieonClick Benachrichtigung übergeben Daten zu fragmentieren mit Bundle
ich nur die Absicht versucht mit und das Bundle zu entfernen, aber es tut nichts
new notifyThis(this, "2", "Title", "Description", "http://imgur.com/gallery/WBTdB").execute();
Mitteilung AsyncTask
public class notifyThis extends AsyncTask<String, Void, Bitmap> {
private Context mContext;
private String itemId, title, description, imageLink;
Notification notification;
NotificationManager notificationManager;
DetailsFragment detailsFragment;
FragmentManager fragmentManager;
FragmentTransaction fragmentTransaction;
Bundle bundle;
PendingIntent pendingIntent;
Intent intent;
Resources res;
public notifyThis(Context context, String itemId, String title, String description, String imageLink) {
super();
this.mContext = context;
this.itemId = itemId;
this.title = title;
this.description = description;
this.imageLink = imageLink;
}
@Override
protected Bitmap doInBackground(String... params) {
InputStream in;
try {
URL url = new URL(this.imageLink);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
in = connection.getInputStream();
return BitmapFactory.decodeStream(in);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Bitmap imageResult) {
super.onPostExecute(imageResult);
fragmentManager = getFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
final int idItem= Integer.valueOf(itemId);
intent = new Intent(mContext, DetailsFragment.class);
bundle = new Bundle();
bundle.putInt("id", idItem);
detailsFragment= new DetailsFragment();
detailsFragment.setTitle(title);
detailsFragment.setArguments(bundle);
transaction.replace(R.id.frame_container, detailsFragment);
transaction.addToBackStack("details");
transaction.commit();
intent.putExtras(bundle);
pendingIntent = PendingIntent.getActivity(mContext, 100, intent, PendingIntent.FLAG_ONE_SHOT);
res = mContext.getResources();
int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height);
int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width);
imageResult = Bitmap.createScaledBitmap(result, width, height, false);
notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notification = new NotificationCompat.Builder(mContext)
.setContentIntent(pendingIntent)
.setContentTitle(title)
.setSmallIcon(R.drawable.icon)
.setLargeIcon(imageResult)
.setSubText(description)
.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(1, notification);
}
}
Dies ist, wie I die Daten erhalten werden - DetailsFragment.class
if (save != null) {
setTitle(save.getString("title"));
}
if (itemId != this.getArguments().getInt("id")) {
itemId = this.getArguments().getInt("id");
/do something here
}
Was genau bedeutet „Es scheint nicht so zu arbeiten.“ bedeuten? Außerdem habe ich bemerkt, dass Sie einen PendingIntent für eine Aktivität erhalten, aber Sie übergeben und Intent, dass dies keine Aktivität ist. –