/*
|
Licensed to the Apache Software Foundation (ASF) under one
|
or more contributor license agreements. See the NOTICE file
|
distributed with this work for additional information
|
regarding copyright ownership. The ASF licenses this file
|
to you under the Apache License, Version 2.0 (the
|
"License"); you may not use this file except in compliance
|
with the License. You may obtain a copy of the License at
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
Unless required by applicable law or agreed to in writing,
|
software distributed under the License is distributed on an
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
KIND, either express or implied. See the License for the
|
specific language governing permissions and limitations
|
under the License.
|
*/
|
|
package io.cordova.hellocordova;
|
|
import android.content.Intent;
|
import android.content.pm.PackageManager;
|
import android.os.Build;
|
import android.os.Bundle;
|
import android.support.annotation.Nullable;
|
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.content.ContextCompat;
|
import android.util.Log;
|
import android.view.View;
|
import android.webkit.JavascriptInterface;
|
import android.webkit.WebView;
|
import android.widget.Toast;
|
|
import com.github.lzyzsd.jsbridge.BridgeWebView;
|
import com.google.zxing.integration.android.IntentIntegrator;
|
import com.google.zxing.integration.android.IntentResult;
|
|
import org.apache.cordova.*;
|
|
import io.hybird.jsbridge.JsInterface;
|
|
public class MainActivity extends CordovaActivity
|
{
|
public WebView webview;
|
|
@Override
|
public void onCreate(Bundle savedInstanceState)
|
{
|
super.onCreate(savedInstanceState);
|
|
// enable Cordova apps to be started in the background
|
Bundle extras = getIntent().getExtras();
|
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
|
moveTaskToBack(true);
|
}
|
|
//webview = (BridgeWebView) findViewById();
|
|
|
// Set by <content src="index.html" /> in config.xml
|
loadUrl(launchUrl);
|
|
Log.d("#****", "123");
|
Log.d( "#######################","456"+appView.getView().getId());
|
webview = findViewById(appView.getView().getId());
|
// 添加事件
|
webview.addJavascriptInterface(new JsInterface(this, webview,MainActivity.this), JsInterface.JS_INTERFACE_NAME);
|
|
|
Intent intent=new Intent(this,CheckExitService.class);
|
getApplicationContext().startService(intent);
|
}
|
|
private void requsetPermission(){
|
if (Build.VERSION.SDK_INT>22){
|
if (ContextCompat.checkSelfPermission(MainActivity.this,
|
android.Manifest.permission.CAMERA)!= PackageManager.PERMISSION_GRANTED){
|
//先判断有没有权限 ,没有就在这里进行权限的申请
|
ActivityCompat.requestPermissions(MainActivity.this,
|
new String[]{android.Manifest.permission.CAMERA},1);
|
|
}else {
|
|
}
|
}else {
|
|
}
|
}
|
|
@Override
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
switch (requestCode){
|
case 1:
|
if (grantResults.length>0&&grantResults[0]==PackageManager.PERMISSION_GRANTED){
|
//这里已经获取到了摄像头的权限,想干嘛干嘛了可以
|
|
}else {
|
//这里是拒绝给APP摄像头权限,给个提示什么的说明一下都可以。
|
Toast.makeText(MainActivity.this,"请手动打开相机权限",Toast.LENGTH_SHORT).show();
|
}
|
break;
|
default:
|
break;
|
}
|
}
|
|
@Override
|
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
if(result != null) {
|
if(result.getContents() == null) {
|
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
|
} else {
|
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
|
//testResult.setText(result.getContents());
|
}
|
} else {
|
super.onActivityResult(requestCode, resultCode, data);
|
}
|
}
|
}
|