- Forum-Beiträge: 27
29.08.2014, 15:16:35 via Website
29.08.2014 15:16:35 via Website
Hallo,
ich kenne mich nicht wirklich gut mit Anroid-programmierung aus, hab es jedoch mit einpaar Tutorials geschaft eine kleine App zu machen. Es ist ganz simpel. Man drückt auch einen Knopf und eine Benachrichtigen ploppt auf. Das funktionierte ja noch soweit, aber nun wollte ich einen zweiten Knopf machen, der nur ein anderes Bild, Text und Namen hat. Hierbei scheiterte ich total. Kann mir irgendjemand sagen wie man nun mehrere Buttons mach bei denen nur die Eigenschaften leicht abgeändert werden? Der Notification-Code von wir ist unten gegeben.
Danke schon mal im Vorraus!
MFG Phillip
package de.dude.test1;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener{
private Button b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=(Button)findViewById(R.id.button1);
b.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View v) {
Intent intent = new Intent();
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
@SuppressWarnings("deprecation"
Notification noti = new Notification.Builder(this)
.setTicker("Ticker Title"
.setContentTitle("Content Title"
.setContentText("Notification content."
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent).getNotification();
noti.flags=Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);
}
}