Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.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_Broadcastreceiver_Intentservice - Fatal编程技术网

Android 我的意图服务不是从广播接收器被呼叫

Android 我的意图服务不是从广播接收器被呼叫,android,broadcastreceiver,intentservice,Android,Broadcastreceiver,Intentservice,这是我的广播接收器 public class InternetConnectivityReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { ConnectivityManager connMgr = (ConnectivityManager) context .getSystem

这是我的广播接收器

public class InternetConnectivityReceiver extends BroadcastReceiver {

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

        ConnectivityManager connMgr = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        android.net.NetworkInfo wifi = connMgr
                .getNetworkInfo(ConnectivityManager.TYPE_WIFI);

        android.net.NetworkInfo mobile = connMgr
                .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

        if (wifi.isAvailable() || mobile.isAvailable()) {
            // Do something
            Toast.makeText(
                    context,
                    "wifi" + wifi.isAvailable() + "mobile"
                            + mobile.isAvailable(), Toast.LENGTH_LONG).show();

                context.startService(new Intent(context,
                        DataDownloadService.class));
            }

    }

}
这是我的服务

public class DataDownloadService extends IntentService {
    private static ORM orm = new ORM();

    public DataDownloadService() {
        super("hello");

    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Toast.makeText(this, "Service inside", Toast.LENGTH_LONG).show();

        Bitmap AdsDrawable = null;
        InputStream inputStream = null;
        try {
            HttpClient httpclient = new DefaultHttpClient();
            URI uri = URI
                    .create(myurlstring);
            HttpGet get = new HttpGet(uri);
            HttpResponse httpResponse = httpclient.execute(get);
            inputStream = httpResponse.getEntity().getContent();

            BufferedReader br = new BufferedReader(new InputStreamReader(
                    inputStream));

            String datarow = "", data = "";
            while ((datarow = br.readLine()) != null) {

                data = datarow + "\n";
            }
            Log.w("Chaitanya", data);


        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

   //work with data and show notification


NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

                // old implementation API level <=10
                Notification notification = new Notification(
                        R.drawable.testing_visaul, "My Notification",
                        System.currentTimeMillis());

                Intent intent1 = new Intent(getApplicationContext(),
                        MainActivity.class);

                PendingIntent pendingIntent = PendingIntent.getActivity(
                        getApplicationContext(), 0, intent1, 0);

                notification.setLatestEventInfo(getBaseContext(),
                        "My Notification Title", "New Event", pendingIntent);

            }
        }
    }
}
公共类DataDownloadService扩展了IntentService{
私有静态ORM=新ORM();
公共数据下载服务(){
超级(“你好”);
}
@凌驾
受保护的手部内容无效(意图){
Toast.makeText(这是“内部服务”,Toast.LENGTH_LONG.show();
位图AdsDrawable=null;
InputStream InputStream=null;
试一试{
HttpClient HttpClient=新的DefaultHttpClient();
URI=URI
.create(myurlstring);
HttpGet=新的HttpGet(uri);
HttpResponse HttpResponse=httpclient.execute(get);
inputStream=httpResponse.getEntity().getContent();
BufferedReader br=新的BufferedReader(新的InputStreamReader(
输入流);
字符串datarow=“”,data=“”;
而((datarow=br.readLine())!=null){
数据=数据行+“\n”;
}
Log.w(“Chaitanya”,数据);
}捕获(未知后异常e){
e、 printStackTrace();
}捕获(例外e){
e、 printStackTrace();
}
//处理数据并显示通知
NotificationManager NotificationManager=(NotificationManager)getSystemService(通知服务);

//旧的实现API级别尝试添加此操作android.net.conn.CONNECTIVITY\u更改“android.net.wifi.wifi\u STATE\u在主包或其他地方更改数据下载服务。如果在其他地方,只需在清单中写入完全限定的名称。有时这就是原因。它在主包中only@mohammed但是我的广播接收器被呼叫了看看
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>


    <receiver
        android:name="InternetConnectivityReceiver"
        android:enabled="true" >
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
        </intent-filter>
    </receiver>


    <service android:name="DataDownloadService"></service>