2016-09-06 15 views
0

私はAndroidアプリを開発中で、現在、ユーザーが設定した日時に通知を受けています。アプリを終了した後に通知が機能しない

私の問題は、時間と日付を設定した後、私は電話からアプリを閉じることです。しかし、通知を私は、アプリケーションを閉じると動作しません。これは私のブロードキャストレシーバーはこれが私のマニフェストファイル

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.jacobabraham13.homeworkapplication"> 
    <!--<receiver android:process=":remote" android:name=".AlarmReceiver" 
     android:permission="com.google.android.c2dm.permission.SEND" 
    />--> <!--android:process=":remote" android:enabled="true"--> 

    <receiver 
     android:name=".AlarmReceiver" 
     android:permission="com.google.android.c2dm.permission.SEND" > 
     <intent-filter> 
      <!-- Receives the actual messages. --> 
      <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
      <action android:name="android.intent.action.USER_PRESENT" /> 
      <category android:name="com.google.android.gcm.demo.app" /> 
     </intent-filter> 
    </receiver> 
    <service android:name=".GcmIntentService" /> 
    <uses-permission android:name="android.permission.VIBRATE" /> 
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 
    <uses-permission android:name="com.android.alarm.persmission.SET_ALARM" /> 

<!-- <service android:name=".AlarmReceiver" android:enabled="true" android:exported="false"> 
     <intent-filter> <action android:name="NOTIFICATION_SERVICE" /></intent-filter> 
    </service>--> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcherplannerlogo" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity android:name=".ApplicationFunc.MainActivityLogIn"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".ApplicationFunc.HomeScreen" 
      android:label="@string/title_activity_home_screen" 
      android:theme="@style/AppTheme.NoActionBar" /> 
     <activity android:name=".ApplicationFunc.AddHomework" /> 
<!--  <service android:name=".ApplicationFunc.AlarmReceiver" 
       android:exported="false" /> 

     <activity android:name=".ApplicationFunc.ChooseTime"></activity>--> 

    </application> 


</manifest> 

ある

@Override 
public void onReceive(Context context, Intent intent) { 
    String text=intent.getStringExtra("param"); 
    List<String> content = Arrays.asList(text.split("\\s*,\\s*")); 
    Uri soundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
    Intent intent1=new Intent(context.getApplicationContext(),HomeScreen.class); 
    PendingIntent pIntent = PendingIntent.getActivity(context.getApplicationContext(), 0, intent, 0); 

    Notification notif=new Notification.Builder(context.getApplicationContext()).setContentTitle(content.get(0)) 
      .setContentText(content.get(1)) 
      .setSound(soundUri) 
      .setContentIntent(pIntent) 
      .setSmallIcon(R.mipmap.ic_launcherplannerlogo) 
      .build(); 

    notif.flags |= Notification.FLAG_AUTO_CANCEL; 

    // Play default notification sound 
    notif.defaults |= Notification.DEFAULT_SOUND; 

    // Vibrate if vibrate is enabled 
    notif.defaults |= Notification.DEFAULT_VIBRATE; 

    NotificationManager notifMan=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); 
    notifMan.notify(0,notif); 



} 

をclass`私はここで何が問題を

やっているのですか?

助けてください!

`

+0

存在しない場合は、試してみましたことを示しているので、

PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_NO_CREATE); 

をプッシュ通知やサービスを使用していますか? http://stackoverflow.com/questions/13741875/how-to-get-android-notifications-when-app-was-closed – Aaron

+0

私はこれを実装する方法についてちょっと混乱しています –

+0

サービスクラスは私の活動であるはずですか?ユーザーは時間と日付を設定しますか? –

答えて

0

次とPendingIntentライン置き換える必要があります。PendingIntent.FLAG_NO_CREATEフラグ説明PendingIntentはすでに

+0

これを試してみましたが、うまくいきませんでした:/ –

+0

どういう意味ですか? 通知バーに表示されない、または開いた後にクラッシュする –

+0

設定した時刻に通知が表示されません。私は上記のように、私はアプリを終了して、それがバックグラウンドで実行して残していない場合それは動作します –

0
First Check When app is close OnReceive() method is Call or Not 
if OnReceive() Method is calling, when app is close. try below Code. 


PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); 
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
    NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(getApplicationContext()) 
      .setSmallIcon(R.mipmap.ic_launcherplannerlogo) 
      .setContentText(content.get(1)) 
      .setContentIntent(pIntent) 
      .setAutoCancel(true) 
      .notificationManager.notify(0, mBuilder.build()); 
+0

どのように私はチェックするか?私は、アプリケーションを閉じるとすぐに、Android Studioで何が起こっているのかわからない。 –

+0

このリンクを参照してくださいhttp://stackoverflow.com/questions/39480931/error-broadcast-intent-callback-result-cancelled-forintent-act-com-google-and/39492561#39492561 –

関連する問題