現在、ステータスバーに通知を起動するクラスを起動するメインアクティビティにアラームがあります。通知をクリックすると、メインのアクティビティが開きます。そのアクティビティ内の特定のビューを開くようにします。
これは私の通知コードです。
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
int icon = android.R.drawable.stat_notify_chat; // icon from resources
CharSequence tickerText = "TickerText"; // ticker-text
long when = System.currentTimeMillis(); // notification time
CharSequence contentTitle = "My notification"; // message title
CharSequence contentText = "Hello World!"; // message text
//This is the intent to open my main activity when the notification is clicked
final Intent notificationIntent = new Intent(context, mainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
// the next two lines initialize the Notification, using the configurations above
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(notifID, notification);
これは、メイン アクティビティで使用されるレイアウトのボタンで、通知を開きたいビュー (グラフ ビュー) を開きます。
<Button
android:id="@+id/graphsButton"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="@id/reviewButton"
android:layout_toRightOf="@id/medicineButton"
android:onClick="openGraphs"
android:text="Graphs" />
ボタンをクリックすると。メインクラスで次のメソッドを実行します。
public void openGraphs(View v) {
canExit = false;
setContentView(R.layout.graphs);
}
基本的には、アプリを開いてメインのアクティビティを起動するようにという通知を受け取りましたが、グラフ ビューを直接起動する必要があります。
誰でも私を助けることができますか?