-2

ハイテク以下のコードアンドロイド放送受信機&通知

レシーバクラスである
import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.util.Log; 


public class AlarmReceiver extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     Log.e("the time is right","yay!"); 
     Intent i = new Intent(context.getApplicationContext() , AlarmServie.class); 
     context.startService(i); 
    } 
} 

以下のコード私のサービスクラス

import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.app.Service; 
import android.content.Intent; 
import android.os.IBinder; 
import android.support.annotation.Nullable; 
import android.support.v4.app.NotificationCompat; 
import android.support.v4.app.TaskStackBuilder; 
import android.util.Log; 

public class AlarmServie extends Service { 
    @Nullable 
    @Override 
    public IBinder onBind(Intent intent) { 
     Log.e("hello","hi"); 
     return null; 
    } 

    @Override 
    public int onStartCommand(Intent intent, int flags, int startId) { 
    super.onStartCommand(intent, flags, startId); 
     Log.e("onCreate:","came"); 
    /* NotificationManager notifyman = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
     Intent main_activity = new Intent(this.getApplicationContext(), MainActivity.class); 
     PendingIntent o = PendingIntent.getActivity(this, 0, main_activity, 0); 

     /*Notification noti = new Notification.Builder(this) 
       .setContentTitle("Reminder to Pill") 
       .setContentText("Click for info") 
       .setAutoCancel(true) 
       .setContentIntent(o)v 
       .build();*/ 
     NotificationManager nm = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE); 
     Intent in = new Intent(this.getApplicationContext(), MainActivity.class); 
     PendingIntent pending = PendingIntent.getActivity(this, 0, in, 0); 
     NotificationCompat.Builder mBuilder =new NotificationCompat.Builder(AlarmServie.this); 
     mBuilder.setContentTitle("Pill Reminder"); 
     mBuilder.setContentText("CLick here to View"); 
     //mBuilder.setSound(sound); 

     TaskStackBuilder ts=TaskStackBuilder.create(this); 
     ts.addParentStack(MainActivity.class); 
     nm.notify(9999,mBuilder.build()); 
     return START_STICKY; 
    }} 

次のコードは、私のマニフェスト

<uses-permission android:name="android.permission.VIBRATE"/> 
    <uses-permission android:name="android.permission.WAKE_LOCK"/> 
    <uses-permission android:name="com.android.alarm.permission.SET_ALARM"/> 
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> 


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

       <category android:name="android.intent.category.LAUNCHER" /> 



      </intent-filter> 
     </activity> 


     <receiver 
        android:name=".AlarmReceiver" 
        android:enabled="true"> 
      <intent-filter> 
       <action android:name="android.intent.action.BOOT_COMPLETED"/> 
      </intent-filter> 

     </receiver> 

     <activity android:name=".Set"> 

     </activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for 
    App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. --> 
     <meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 


      <service 
       android:name=".AlarmServie" 
       android:enabled="true"/> 




    </application> 

</manifest> 

ですテキストボックスとタイマーボタンを使ってテキストと時間を取得し、データベースに保存しました。システム時刻は、通知が来なければならないと一致するが、これはhappens.clearlyコード

して詳細に説明することによって、この問題が発生したYを説明し、なぜ誰もが、これはlogcat

である、これは私の主な活動

import android.app.AlarmManager; 
import android.app.PendingIntent; 
import android.content.Context; 
import android.content.Intent; 
import android.database.Cursor; 
import android.os.Bundle; 
import android.support.design.widget.FloatingActionButton; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.Button; 
import android.widget.ListView; 
import android.widget.TextView; 

import com.google.android.gms.common.api.GoogleApiClient; 

import java.util.ArrayList; 
import java.util.Calendar; 
import java.util.Date; 
import java.util.List; 


public class MainActivity extends AppCompatActivity { 
    Sqlitedb dbobj1; 
    int gh; 
    AlarmManager am; 


    Calendar c; 
    /** 
    * ATTENTION: This was auto-generated to implement the App Indexing API. 
    * See https://g.co/AppIndexing/AndroidStudio for more information. 
    */ 
    private GoogleApiClient client; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     dbobj1 = new Sqlitedb(MainActivity.this); 
     gh = (int) dbobj1.number(); 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

     Calendar c = Calendar.getInstance(); 

     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
     fab.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Intent intent = new Intent(MainActivity.this, Set.class); 
       startActivity(intent); 
      } 
     }); 
     Intent my_intent = new Intent(MainActivity.this, AlarmServie.class); 


     am = (AlarmManager) getSystemService(ALARM_SERVICE); 
     Date dt = new Date(); 
     int hour=dt.getHours(); 
     int min=dt.getMinutes(); 
     PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 0, my_intent, PendingIntent.FLAG_UPDATE_CURRENT); 
     Cursor t = dbobj1.recenttime(hour,min); 
     t.moveToFirst(); 
     c.set(Calendar.HOUR_OF_DAY, t.getInt(0)); 
     c.set(Calendar.MINUTE, t.getInt(1)); 
     am.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pi); 


     populate(); 

    } 
     // ATTENTION: This was auto-generated to implement the App Indexing API. 
     // See https://g.co/AppIndexing/AndroidStudio for more information. 
     //client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); 
    //oncreate ends here 


    class customAdabter extends ArrayAdapter<setget> { 
     Context _context; 
     List<setget> _li; 

     public customAdabter(Context con, int layout, List<setget> li) { 
      super(con, layout, li); 
      _context = con; 
      _li = li; 
     } 

     @Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
      gh++; 
      LayoutInflater layu = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

      View v = layu.inflate(R.layout.item, null); 


      TextView txt = (TextView) v.findViewById(R.id.item_textview1); 
      TextView txt1 = (TextView) v.findViewById(R.id.item_textview2); 
      Button btt = (Button) v.findViewById(R.id.item_button1); 
      btt.setId(gh); 

      btt.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 

        int r = v.getId(); 
        dbobj1.deleteRow(r); 

        populate(); 

       } 
      }); 

      setget dataobj = _li.get(position); 

      txt.setText(dataobj.getPn()); 
      txt1.setText(dataobj.getPt()); 

      return v; 
     } 
    } 


    public void populate() { 
     List<setget> li = new ArrayList<setget>(); 

     for (int i = 1; i <= dbobj1.number(); i++) { 
      setget obj = new setget(); 
      Cursor c = dbobj1.getRow(i); 
      String name = c.getString(c.getColumnIndex("pillname")); 
      String time = c.getString(c.getColumnIndex("pilltime")); 
      obj.setPn(name); 
      obj.setPt(time); 
      c.close(); 
      li.add(obj); 
     } 
     ListView lv = (ListView) findViewById(R.id.listview); 
     customAdabter customobj = new customAdabter(MainActivity.this, R.layout.item, li); 
     lv.setAdapter(customobj); 

    } 
} 

であると言うことができます来ていません

09-19 11:30:32.267 19426-19426/com.example.ashwin.pillreminder11 D/ActivityThread: BDC-Calling onReceive: intent=Intent { flg=0x114 cmp=com.example.ashwin.pillreminder11/.AlarmReceiver (has extras) }, [email protected] 

09-19 11:30:32.267 19426-19426/com.example.ashwin.pillreminder11 E/the time is right: yay! 

09-19 11:30:32.268 19426-19426/com.example.ashwin.pillreminder11 D/ActivityThread: BDC-RECEIVER handled : 0/ReceiverData{intent=Intent { flg=0x114 cmp=com.example.ashwin.pillreminder11/.AlarmReceiver (has extras) } packageName=com.example.ashwin.pillreminder11 resultCode=0 resultData=null resultExtras=null} 
+0

@Mike M.お知らせとアラームの両方が来ていません。どうしてこのようなことが起きるのでしょうか。 –

+0

@Mike M.はい私は今出力する必要があります。コード –

+0

@Mike M.私は自分のコードを更新しました –

答えて

0
<receiver 
     android:name=".AlarmReceiver" 
     android:enabled="true"> 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED"/> 
     </intent-filter> 
</receiver> 

<receiver 
     android:name=".AlarmReceiver" 
     android:enabled="true"> 
</receiver> 
への変更を

を使用し、別のブロードキャスト受信機を使用してBOOT_COMPLETEDブロードキャストを受信し、すべてのアラームをリセットします。

+0

問題は、受信者クラスがサービスクラスに移動していないことです –

+0

logcat出力を提供 –

+0

E/MultiWindowProxy:getServiceInstance failed! –

関連する問題