android 응용 프로그램에 인터넷의 접근 권한이 없으면 서버에 데이터를 어떻게 제출합니까

1887 단어
1. 서비스에 두 개의 방송 "screen_off"와 "screen_on"의 방송을 등록합니다
@Override
public void onCreate() {
	IntentFilter lockScreenFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
	lockScreenFilter.setPriority(Integer.MAX_VALUE);
	LockScreenReceiver lockScreenReceiver = new LockScreenReceiver();
	registerReceiver(lockScreenReceiver, lockScreenFilter);
		
	IntentFilter unLockScreenFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
	unLockScreenFilter.setPriority(Integer.MAX_VALUE);
	UnLockScreenReceiver unLockScreenReceiver = new UnLockScreenReceiver();
	registerReceiver(unLockScreenReceiver, unLockScreenFilter);
	super.onCreate();
}

2. 자물쇠 방송의 작성을 실현하고 자물쇠 방송에서 브라우저로 데이터를 업로드한다
class LockScreenReceiver extends BroadcastReceiver{

	@Override
	public void onReceive(Context context, Intent intent) {
		LogUtils.i("LockScreenReceiver", " ");
			
		Intent uploadIntent = new Intent(Intent.ACTION_VIEW);
		uploadIntent.addCategory(Intent.CATEGORY_BROWSABLE);
uploadIntent.setData(Uri.parse("http://10.20.2.98:8080/web/uploadservlet?info="+"hhh"));
		uploadIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(uploadIntent);
	}
		
}

3. 화면이 켜진 라디오에서 데스크톱으로 돌아가는 작업
class UnLockScreenReceiver extends BroadcastReceiver{
		
	@Override
	public void onReceive(Context context, Intent intent) {
		LogUtils.i("UnLockScreenReceiver", " ");
		Intent homeIntent = new Intent("android.intent.action.MAIN");
		homeIntent.addCategory("android.intent.category.HOME");
		homeIntent.addCategory("android.intent.category.DEFAULT");
		homeIntent.addCategory("android.intent.category.MONKEY");
		homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		startActivity(homeIntent);
	}
		
}

좋은 웹페이지 즐겨찾기