[英]Need Help in Android Notifications
I'm developing an app where I had to show notification , I am showing it sucessfully but however I want when user click on notification it should dial a mobile number ... 我正在开发一个必须显示通知的应用程序,但显示成功,但是我希望当用户单击通知时它应该拨打手机号码...
MyNotify.java MyNotify.java
package com.premiumtechhelp.net;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Mynotify extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView txt = new TextView(this);
txt.setText("Some text here");
setContentView(txt);
}
}
MainActivity.java MainActivity.java
private static final int NOTIFY_ME_ID = 1337;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final NotificationManager mgr = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification note = new Notification(R.drawable.ic_launcher,
"Hello Notifi", System.currentTimeMillis());
PendingIntent i = PendingIntent.getActivity(this, 0, new Intent(this,
Mynotify.class), 0);
note.setLatestEventInfo(this, "Hello text",
"mobile number 9906012345", i);
mgr.notify(NOTIFY_ME_ID, note);
You need to put the number as extra to the intent where you create the notification: 您需要在创建通知的意图中添加额外的数字:
final String number = "1234567890";
final NotificationManager mgr = (NotificationManager)this.getSystemService(
Context.NOTIFICATION_SERVICE);
Notification note = new Notification(R.drawable.ic_launcher, "Hello Notifi",
System.currentTimeMillis());
Intent intent = new Intent(this, Mynotify.class);
intent.putExtra("number", number);
PendingIntent i = PendingIntent.getActivity(this, 0, intent, 0);
nte.setLatestEventInfo(this, "Hello text", "mobile number " + number, i);
mgr.notify(NOTIFY_ME_ID, note);
Than you can grep it in your activity with: 比起以下方法,您可以在活动中使用它:
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView txt = new TextView(this);
String number = getIntent().getStringExtra("number");
txt.setText("Some text here " + number);
setContentView(txt);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.