실례지만 다른 비슷한 게시물이 도움이되지 못했습니다. 저는 Xamarin을 사용하며 각 알림에 ID를 지정합니다. 열린 활동에서 클릭 한 알림 ID를 가져 와서 내 목록에서 검색하고 관련 정보를 표시하고 싶습니다. 감사합니다.각 Android 알림의 ID를 가져 오는 방법은 무엇입니까?
답변
감사합니다. Graham. WebService에서 목록을 얻었고 각 항목에 대해 알림을 만들었습니다. 각 품목에는 ID, 원본, 심상이있다.
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를하지되었다 .when "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);
}
}
덕분에
나는 질문이 분명하다고 생각하지 않습니까? –
두 번째 알림 ID는 첫 번째 알림 ID이고, 세 번째 ID는 두 번째 ID입니다. 알림을 클릭하면 ID가 'Show_Notify' 활동의 이미지에 표시됩니까? 그래서 이드는 잘못 뒀어? –
제 질문은 각 통지가 자신의 ID를 유지하지 않는 이유는 무엇입니까? 내 경우에는 마지막 ID가 이전 ID를 덮어 쓰고 Show_Notify 활동에서 마지막 ID 정보 만 얻는다. –
감사하지만 난이 한 내가 의도 에서 널 수 :
Intent activityIntent = new Intent(context, typeof(Show_Notify));
activityIntent.PutExtra("notify_id", id);
var pendingIntent = PendingIntent.GetActivity(context, id, activityIntent, PendingIntentFlags.CancelCurrent);
및 show_notify 활동
string s1 = Intent.GetStringExtra("notify_id");
을
그러나 반환 S1 널
테스트 프로젝트를 게시하면 테스트 할 수 있습니다. 'id' 유형이'string'이 아닌'int'입니다. –
감사합니다. joe, 테스트 해 보겠습니다. –
테스트 해 보셨습니까? –
이 시도 :
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>
joe, 내 코드는 0에서 10 사이의 루프를 제외하고는 모두 동일하지 않습니다. 주요 포인트는 알림 표시 줄에 추가 된 모든 알림이 자신의 ID를 유지하지 않는 이유입니다. 우리가 그들을 클릭 할 때까지, 그들의 ID를 기반으로, 우리는 정보를 얻습니다. –
내 코드가 작동합니까? 원하는대로 작동하는 경우 먼저 알림을 표시하고 알림창에 추가 된 모든 알림이 자신의 ID를 유지하지 않는 이유에 대해 새 사례 하나를 엽니 다. 감사합니다. –
아무도 도움을? 제발 응급 문제 야. 고맙습니다. –
질문을 확장하십시오. 당신이 묻고있는 것이 명확하지 않습니다. 가능한 경우 사례를 제시하고, 올바른 결과를 제안하고, 코드를 작은 부분으로 축소하여 문제를 표시하십시오. –