2017-07-11 17 views
1

最近私はアプリを開発しましたが、AndroidスタジオではsetLatestEventInfoメソッドがサポートされなくなりましたので、このメソッドをNotification.Builderメソッドに変更しようとしました。しかし、私は苦労しているので、誰かが私にこのメソッドをNotification.Builderメソッドに変更することをサポートして欲しいです。setLatestEventInfoメソッドを解決できません

String ns = Context.NOTIFICATION_SERVICE; 
     mNotificationManager = (NotificationManager) getSystemService(ns); 

     int icon = R.drawable.ic_launcher; 
     CharSequence tickerText = "Fall Detector"; 
     long when = System.currentTimeMillis(); 
     notification = new Notification(icon, tickerText, when); 


     mContext = getApplicationContext(); 
     CharSequence contentTitle = "Fall Detector"; 
     CharSequence contentText = "Running"; 
     Intent notificationIntent = new Intent(this,StartActivity.class); 
     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
       notificationIntent, 0); 
     notification.setLatestEventInfo(mContext, contentTitle, contentText, 
       contentIntent); 


     mNotificationManager.notify(1, notification); 

私は以下を試しましたが、シンボルの内容が解決できないと言います。

String ns = Context.NOTIFICATION_SERVICE; 
     int icon = R.drawable.ic_launcher; 
     CharSequence tickerText = "Fall Detector"; 
     long when = System.currentTimeMillis(); 
     notification = new Notification(icon, tickerText, when); 
     mNotificationManager = (NotificationManager) getSystemService(ns); 

     Notification.Builder builder = new Notification.Builder(mContext) 

       .setContentTitle("Fall Detector") 
       .setContentText("Running") 
       .setContentIntent(contentIntent); 
     builder.build(); 
     Notification notification = builder.getNotification(); 

     mNotificationManager.notify(1, notification); 
+0

"私は苦労しています" - あなたの質問を編集して、あなたが試したこととあなたが遭遇した特定の問題を示してください。 [この1つ](https://stackoverflow.com/q/32345768/115145)のような、このトピックに関する文字通り何十という既存の質問があります。あなたの質問を重複としてマークしたくない人は、**あなたの質問を既存のものとは異なるものにするために**詳細に**説明する必要があります。 – CommonsWare

+0

質問が更新されました –

+0

私はコードを修正しましたが、symbol contentintentを解決できないという同じメッセージが表示されています。 –

答えて

0

私は、しかし、それはそれはシンボルcontentintentを解決できないと言う、以下試してみました。あなたの改訂コードにあなたの元のコードからいくつかの行をコピーするために失敗したので

Intent notificationIntent = new Intent(this,StartActivity.class); 
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
      notificationIntent, 0); 

あなたがNotification.Builderの設定を開始する前に、改訂されたコードでそれらを持っています。

+0

私は以下を試しましたが、シンボルの内容を解決できないと言います。 –

+0

@ElderlyWatch:私が書いたように、あなたは 'Notification.Builder' **の設定を開始する前に、あなたの改訂コード**にそれらを載せてください。 'Notification.Builder'の設定を開始した後に**あなたはそれらを持っています。たとえば、コードスニペットの最初の行に置くことができます。 – CommonsWare

+0

私はこれを行っていますが、原因は次のようなエラーメッセージです。java.lang.NullPointerException:仮想メソッド 'void android.app.NotificationManager.notify(int、android.app.Notification)'を呼び出そうとしています –

関連する問題