Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 通知:我的更新接收器未呼叫_Android - Fatal编程技术网

Android 通知:我的更新接收器未呼叫

Android 通知:我的更新接收器未呼叫,android,Android,我是新的通知。我找不到任何帮助,请帮助我。提前谢谢。我必须在android应用程序中显示通知,但它不会接到我的广播接收器的呼叫,尽管我在清单中添加了权限 <Service android:name="com.example.tajgroup.newsapplication.service.NotificationService" android:enabled="true"/> <receiver android:name=".reci

我是新的通知。我找不到任何帮助,请帮助我。提前谢谢。我必须在android应用程序中显示通知,但它不会接到我的广播接收器的呼叫,尽管我在清单中添加了权限

<Service android:name="com.example.tajgroup.newsapplication.service.NotificationService"
            android:enabled="true"/>

        <receiver android:name=".reciever.UpdateReciever">
            <intent-filter>
                <action android:name="android.net.com.CONNECTIVITY_CHANGE" />
            </intent-filter>
            /></receiver>




and my NotificationService and UpdateReciever are



public class UpdateReciever extends BroadcastReceiver {
        ConnectivityManager connectivityManager;
        NetworkInfo networkInfo;
        String dateString;

        public static NotificationManager mNotificationManager;
        public static int SIMPLE_NOTFICATION_ID;

        static Intent serviceintent;

        @Override
        public void onReceive(Context context, Intent intent) {

                if (!isNetworkAvailable(context)) {
                        // Notification(context, "Wifi Connection Off");

                } else {

                        serviceintent = new Intent(context, NotificationService.class);
                        context.startService(serviceintent);
                        context.stopService(serviceintent);

                }
        }

        // Check for network availability
        private boolean isNetworkAvailable(Context context) {
                ConnectivityManager connectivityManager = (ConnectivityManager) context
                        .getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo activeNetworkInfo = connectivityManager
                        .getActiveNetworkInfo();
                return activeNetworkInfo != null;
        }

}






public class NotificationService extends Service {
    ConnectivityManager connectivityManager;
    NetworkInfo networkInfo;
    NotificationService notification;
    String dateString,Name;
    Categories categories;

    ArrayList<String> a = new ArrayList<String>();
    public static int SIMPLE_NOTFICATION_ID;
    private Context _context;
    long count, cnt, date1;
    int flag = 0;
    public static NotificationManager mNotificationManager;

    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onCreate() {
        /*Toast.makeText(this, "Congrats! MyService Created", Toast.LENGTH_LONG)
                .show();*/

    }

    @Override
    public void onStart(Intent intent, int startId) {

        //Toast.makeText(getApplicationContext(), "Service Stared", Toast.LENGTH_SHORT).show();
        date1 = System.currentTimeMillis();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        dateString = sdf.format(date1);
        System.out.println("Ntification item1 = " + dateString);
        //dateString="07/11/2014";
        notification();
    }

    @Override
    public void onDestroy() {
        //Toast.makeText(this, "MyService Stopped", Toast.LENGTH_LONG).show();

    }

    private void notification(){

        final RestAdapter adapter = new RestAdapter.Builder()
                .setEndpoint(Config.url)
                .build();

        MainActivityInterface api = adapter.create(MainActivityInterface.class);

        api.Test(
                new Callback<Response>() {
                    @Override
                    public void success(Response result, Response response) {
                        BufferedReader reader = null;
                        String message = "";
                        String output = "";

                        try {
                            reader = new BufferedReader(new InputStreamReader(result.getBody().in()));
                            output = reader.readLine();
                            JSONTokener tokener = new JSONTokener(output);

                            JSONObject json = new JSONObject(tokener);
                            JSONArray jsonArray = json.getJSONArray("story");

                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject jsonObj = jsonArray.getJSONObject(i);
                                int id = jsonObj.getInt("id");
                                String title = jsonObj.getString("title");
                                String content = jsonObj.getString("content");
                                String picture = jsonObj.getString("picture");
                                String saved_file_name = jsonObj.getString("saved_file_name");
                                String status = jsonObj.getString("status");
                                String start_date = jsonObj.getString("start_date");
                                String end_date = jsonObj.getString("end_date");
                                String created_at = jsonObj.getString("created_at");
                                String updated_at = jsonObj.getString("updated_at");

                                categories = new Categories(id,title,content,picture,saved_file_name,status,start_date,end_date,created_at,updated_at);

                                   String[] items = categories.getUpdated_at().split(" ");
                                   String date1, time;
                                   date1 = items[0];
                                   time = items[1];
                                   System.out.println("item = " + updated_at);
                                System.out.println("noti item1 = " + date1);

                                if(date1.equals(dateString)) {
                                   notification = new NotificationService();
                                   Name = categories.getTitle();
                                   a.add("\n" + Name);
                               }
                            }

                            notification.Notification(NotificationService.this," \n" + a);

                        } catch (IOException e) {
                            e.printStackTrace();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }

                    @Override
                    public void failure(RetrofitError error) {

                        Toast.makeText(NotificationService.this, error.toString(), Toast.LENGTH_LONG).show();

                    }
                }
        );
    }

    void Notification(Context context, String message) {
        // TODO Auto-generated method stub
        // Set Notification Title
        String strtitle = context.getString(R.string.app_name);
        // Open NotificationView Class on Notification Click
        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        // Create Notification using NotificationCompat.Builder
        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                context)
                // Set Icon
                .setSmallIcon(R.drawable.pen_50px)
                // Set Ticker Message
                .setTicker(message)
                // LED
                .setLights(Color.RED, 3000, 3000)

                // Set Title
                .setContentTitle(context.getString(R.string.app_name))
                // Set Text
                .setContentText(message)
                // Add an Action Button below Notification
                .addAction(android.R.drawable.ic_menu_more, "Click to Check", pIntent)
                // Set PendingIntent into Notification
                .setContentIntent(pIntent)
                // Dismiss Notification
                .setAutoCancel(true);

        // Create Notification Manager
        NotificationManager notificationmanager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        // Build Notification with Notification Manager
        notificationmanager.notify(0, builder.build());

    }
}

/>
我的NotificationService和UpdateReciever是
公共类UpdateReceiver扩展BroadcastReceiver{
ConnectivityManager ConnectivityManager;
网络信息网络信息;
字符串日期字符串;
公共静态通知经理通知经理;
公共静态int简单通知ID;
静态意图服务意图;
@凌驾
公共void onReceive(上下文、意图){
如果(!isNetworkAvailable(上下文)){
//通知(上下文,“Wifi连接关闭”);
}否则{
serviceintent=新的意图(上下文,NotificationService.class);
上下文。startService(serviceintent);
停止服务(serviceintent);
}
}
//检查网络可用性
专用布尔值isNetworkAvailable(上下文){
ConnectivityManager ConnectivityManager=(ConnectivityManager)上下文
.getSystemService(Context.CONNECTIVITY\u服务);
NetworkInfo activeNetworkInfo=connectivityManager
.getActiveNetworkInfo();
返回activeNetworkInfo!=null;
}
}
公共类NotificationService扩展了服务{
ConnectivityManager ConnectivityManager;
网络信息网络信息;
通知服务通知;
字符串日期字符串,名称;
类别;
ArrayList a=新的ArrayList();
公共静态int简单通知ID;
私人语境(private Context)(私人语境);;
长计数,cnt,date1;
int标志=0;
公共静态通知经理通知经理;
@凌驾
公共IBinder onBind(意向){
//TODO自动生成的方法存根
返回null;
}
@凌驾
public void onCreate(){
/*Toast.makeText(这是“恭喜!我的服务已创建”,Toast.LENGTH\u LONG)
.show()*/
}
@凌驾
公共无效启动(Intent Intent,int startId){
//Toast.makeText(getApplicationContext(),“服务启动”,Toast.LENGTH_SHORT.show();
date1=System.currentTimeMillis();
SimpleDataFormat sdf=新SimpleDataFormat(“yyyy-MM-dd”);
dateString=sdf.format(date1);
System.out.println(“标识项1=“+dateString”);
//dateString=“07/11/2014”;
通知();
}
@凌驾
公共空间{
//Toast.makeText(这是“MyService已停止”,Toast.LENGTH_LONG.show();
}
私人无效通知(){
最终RestAdapter adapter=new RestAdapter.Builder()
.setEndpoint(Config.url)
.build();
MainActivityInterface api=adapter.create(MainActivityInterface.class);
api.测试(
新回调函数(){
@凌驾
public void成功(响应结果、响应){
BufferedReader reader=null;
字符串消息=”;
字符串输出=”;
试一试{
reader=new BufferedReader(new InputStreamReader(result.getBody().in());
输出=reader.readLine();
JSONTokener令牌=新的JSONTokener(输出);
JSONObject json=新的JSONObject(标记器);
JSONArray JSONArray=json.getJSONArray(“故事”);
for(int i=0;i