Hinzufügen-Taste Aktion in benutzerdefinierte Benachrichtigung
Habe ich gemacht custom notification
und es gibt eine Schaltfläche, die, ich möchte zwei verschiedene functionalities on notification and button click
. Ich sehe auf vielen links, aber nicht finden konnten, die Möglichkeit zum hinzufügen von button-listener.
Kann jemand helfen. Hier ist mein code. Vielen Dank.
private void startNotification() {
Intent intent;
PendingIntent pIntent;
RemoteViews remoteViews = new RemoteViews(getPackageName(),
R.layout.mynotification);
Context context = getApplicationContext();
NotificationCompat.Builder builder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.ic_launcher).setContent(
remoteViews);
if (hasFlash) {
intent = new Intent(context, FlashLight.class);
pIntent = PendingIntent.getActivity(context, 1, intent, 0);
} else {
intent = new Intent(context, BlankWhiteActivity.class);
pIntent = PendingIntent.getActivity(context, 1, intent, 0);
}
builder.setContentIntent(pIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notif = builder.setContentTitle("Flashlight")
.setContentText("Lighten your world!!!").build();
mNotificationManager.notify(1, notif);
remoteViews.setOnClickPendingIntent(R.id.closeOnFlash, pIntent);
}
Ich habe bestanden die Taste id (closeOnFlash
) in setOnClickPendingIntent
weiß nicht, warum es nicht funktioniert.
Und hier ist mein xml
:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="100" >
<ImageView
android:id="@+id/notifiation_image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="30"
android:contentDescription="@string/appImage"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/appName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="50"
android:gravity="center"
android:text="@string/flashLightOn"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/closeOnFlash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="20"
android:text="@string/close" />
Kann dieser thread hilft? stackoverflow.com/questions/5479165/...
Dieser thread sollte beantworten, was Sie zu tun versuchen: stackoverflow.com/questions/12438209/...
Ok, danke ich werde geben ihm einen Blick.
Tatsächlich ist die zweite wirklich arbeitete für mich auf meinem HTC sensation, nicht geprüft die Kompatibilitätsprobleme.
Dieser thread sollte beantworten, was Sie zu tun versuchen: stackoverflow.com/questions/12438209/...
Ok, danke ich werde geben ihm einen Blick.
Tatsächlich ist die zweite wirklich arbeitete für mich auf meinem HTC sensation, nicht geprüft die Kompatibilitätsprobleme.
InformationsquelleAutor Syed Raza Mehdi | 2014-02-21
Du musst angemeldet sein, um einen Kommentar abzugeben.
Start die Meldung als:
xml verwendet:
In manifest unter Anwendung tag:
Wie funktioniert die Deklaration in der Manifest-Arbeit ? Ist die Taschenlampe Ihrer Klasse mit der swiftButtonListener ? Ist es der name der Anwendung ?
seine Tätigkeit name
Das ist wirklich eine tolle Idee! Vielen Dank für den Austausch!
haben Sie registrieren Sie die Empfänger im manifest?
InformationsquelleAutor Syed Raza Mehdi