对不起,但其他类似的帖子对我没有帮助。 我使用Xamarin并且我将每个通知指定为Id。 我想在打开的活动中获得点击的通知ID,并在我的列表中搜索并显示相关信息 感谢。
答案 0 :(得分:0)
谢谢格雷厄姆。我从WebService获得了一个列表,并为其中的每个项目创建了一个通知。每个项目都有id,text,image。
for (int i = 0; i < sobhan.arr_notify.Length; i++)
call_notify(context, sobhan.arr_notify[i].text, sobhan.int_32(sobhan.arr_notify[i].id));
并且call_notify方法:
private static void call_notify(Context context, string message,int id)
{
Intent activityIntent = new Intent(context, typeof(Show_Notify));
sobhan.notify_call_id = id;
var pendingIntent = PendingIntent.GetActivity(context, 0, activityIntent, PendingIntentFlags.UpdateCurrent);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.SetAutoCancel(true)
.SetDefaults((int)NotificationDefaults.All)
.SetSmallIcon(Resource.Drawable.icon_mini)
.SetContentTitle("دنیا طب دام")
.SetContentText(message)
.SetContentIntent(pendingIntent)
.SetContentInfo("info");
NotificationManager manager = (NotificationManager)context.GetSystemService(Context.NotificationService);
manager.Notify(id, builder.Build());
}
此“id”未设置为自己的通知并且所有通知都采用上次通知ID。当“Show_Notify”活动呼叫时,显示最后一个ID的图像。
Show_Notify活动:
var r = sobhan.show_arr_notify.FindAll(x => x.id == sobhan.notify_call_id.ToString());
if(r.Count>0)
{
Bitmap bitmap = BitmapFactory.DecodeByteArray(r[0].image, 0, r[0].image.Length);
using (var os = new FileStream(filename, FileMode.CreateNew))
{
bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, os);
}
}
由于
答案 1 :(得分:0)
试试这个:
MainActivity
:
[Activity(Label = "App26", MainLauncher = true)]
public class MainActivity : Activity
{
Button bt1;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
initVicew();
}
private void initVicew()
{
bt1 = FindViewById<Button>(Resource.Id.bt);
bt1.Click += Bt1_Click;
}
private void Bt1_Click(object sender, EventArgs e)
{
for (int id=0;id<10;id++) {
Intent activityIntent = new Intent(this, typeof(Activity1));
activityIntent.PutExtra("id",""+id);
var pendingIntent = PendingIntent.GetActivity(this, id, activityIntent, PendingIntentFlags.CancelCurrent);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.SetAutoCancel(true)
.SetDefaults((int)NotificationDefaults.All)
.SetSmallIcon(Resource.Drawable.Capture)
.SetContentTitle("دنیا طب دام")
.SetContentText(""+id)
.SetContentIntent(pendingIntent)
.SetContentInfo("info");
NotificationManager manager = (NotificationManager)this.GetSystemService(Context.NotificationService);
manager.Notify(id, builder.Build());
System.Diagnostics.Debug.Write("id="+id);
}
}
}
Main.axml
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="click"
android:id="@+id/bt" />
</LinearLayout>
Activity1
:
[Activity(Label = "Activity1")]
public class Activity1 : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
SetContentView(Resource.Layout.layout2);
string str = this.Intent.GetStringExtra("id");
System.Diagnostics.Debug.Write(str);
}
}
layout2
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>