如何使用android.support.v4.app.ActivityCompat.requestPermissions或android.app.Activity.requestPermissions? 因爲它總是不確定的NativeScript RequestPermission
我想這樣做
var context = android.content.Context;
var wifi_service = application.android.context.getSystemService(context.WIFI_SERVICE);
wifi_service.setWifiEnabled(true);
var rs = wifi_service.startScan();
console.log(android.support.v4.app.ActivityCompat.requestPermissions); // undefined
console.log(android.support.v4.content.ContextCompat.requestPermissions); // undefined
application.android.registerBroadcastReceiver(
android.net.wifi.WifiManager.SCAN_RESULTS_AVAILABLE_ACTION,
function onReceiveCallback(context, intent) {
var tp = wifi_service.getScanResults();
console.log(tp); // empty []
console.log(tp.size()); // 0
});
但陣列TP始終是空的,我的事情,因爲我需要合適的權限,而在Android上6,我們需要問它
我還加上manifest資源配置文件:
<uses-feature android:name="android.hardware.wifi" />
<uses-feature android:name="android.hardware.location" android:required="false" />
<uses-feature android:name="android.hardware.location.network" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION" />
還加上C:\程序\ App_Resources \ Android的\ app.gradle:
dependencies {
compile "com.android.support:support-v4:+"
, compile "com.android.support:appcompat-v7:+"
}
感謝