I'm trying to access a development server API using nativescript-vue. I have added all the possible permissions in the android manifest, but it's giving the error: JS: Error: java.io.IOException: Cleartext HTTP traffic to url not permitted
Here is my manifest:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:usesCleartextTraffic="true"
android:name="com.tns.NativeScriptApplication"
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:cleartextTrafficPermitted="true"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="#xml/network_security_config"
android:theme="#style/AppTheme">
Here is the network_security_config.xml file:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">192.168.xxx.xxx</domain>
</domain-config>
</network-security-config>
And here is the Nativescipt-vue code:
httpModule.request({
url: "http://192.168.XXX.XXX:XXXX/func",
method: "POST",
headers: { "Content-Type": "application/json" },
content: data
}).then((response) => {
const result = response.content.toJSON();
}, (e) => {
console.error(e);
});
For those who face the same issue, tns platform remove android and tns platform add android worked for me. It started reading the updated manifest after this.
Go in to App_Resources -> Android -> src\main -> AndroidManifest.xml add android:usesCleartextTraffic="true" go to the application xml section then do a tns update resources cmd.
Related
In my nativescript appllication, I use nativescript-local-notifications NPM to push the local notification and I have followed the instructions same as the readme file in the github.
I face the error
LocalNotifications.schedule: TypeError: builder.setChannelId is not a function
I referred the GitHub issue which is already resolved by someone. But still, I face the issue.
ItemComponent.ts:
import * as LocalNotifications from "nativescript-local-notifications";
scheduleTesting() {
console.log("I am inside schedule noti");
LocalNotifications.hasPermission().then(
function (granted) {
console.log("Permission granted -->" + granted);
}
)
LocalNotifications.schedule([{
id: 0,
title: 'Sound & Badge',
body: 'Who needs a push service anyway?',
badge: 1,
at: new Date(new Date().getTime() + (5 * 1000)) // 5 seconds from now
}])
LocalNotifications.addOnMessageReceivedCallback(data => {
alert({
title: "Local Notification received",
message: `id: '${data.id}', title: '${data.title}'.`,
okButtonText: "Roger that"
});
});
}
manifestoXML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="__PACKAGE__"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="__APILEVEL__"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name="com.tns.NativeScriptApplication"
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name="com.tns.NativeScriptActivity"
android:label="#string/title_activity_kimera"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="#style/LaunchScreenTheme"
android:launchMode="singleTop"
>
<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="#style/AppTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.shortcuts"
android:resource="#xml/shortcuts" />
</activity>
<activity
android:name="com.tns.ErrorReportActivity"/>
</application>
</manifest>
API level = 27
"nativescript-local-notifications": "^2.0.3",
GITHub issue url : https://github.com/EddyVerbruggen/nativescript-local-notifications/pull/68
I have created an app that calls boot completed class every time the phone restart. But my issue
is that I get a message that says 'Unfortunately, the app has stopped' every time I restart the phone, especially on older phones like OS 4.4.2. What could cause this issue?
My code :
Manifes.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="mypackagename" android:versionCode="1" android:versionName="1.0" android:installLocation="preferExternal">
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application android:allowBackup="true" android:label="#string/app_name" android:icon="#drawable/shortcut_icon">
<service android:enabled="true" android:name=".AppService" />
<receiver android:name=".RebootListener" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
Boot completed class
[BroadcastReceiver(Enabled = true)]
[IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted })]
public class RebootListener : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Intent serviceIntent = new Intent(context, typeof(AppService));
context.StartService(serviceIntent);
}
}
The issue persists even if I comment out the code in the OnReceive method. I presume the problem might be in the manifest file. If I remove the boot completed code in the manifest file I stop receiving this error message.
Remove the receiver from your manifest:
<receiver android:name=".RebootListener" android:enabled="true" android:exported="true">
<intent-filter>
~~~~
</intent-filter>
You have applied the BroadcastReceiver attribute to your BroadcastReceiver subclass and thus the Xamarin.Android build process will create this in your manifest automatically using a MD5-based Java class name (which will not be just .RebootListener)
MainActivity.java
Button sendTestSMSButton = (Button)findViewById(R.id.sendTestSMSButton);
sendTestSMSButton.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
System.out.println("Send SMS");
try
{
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("+972526855556", null, "shenkin", null, null);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.smssong.admin.smstosong">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.SEND_SMS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
I get error "Sending SMS message: uid 10063 does not have android.permission.SEND_SMS."
Even that in the AndroidManifest.xml there is code to enable the permission.
What I am missing ?
There was permission error using illegal SDK
I am trying to get the current location of user(tried in genymotion and actual android device) but always getting an error of {"nativeException":{}}. I am testing it with gps enabled and my view model code is below to access the location
var observable = require("data/observable");
var locationModule = require("location");
var LocationManager = new locationModule.LocationManager();
var enums = require('ui/enums');
var MainViewModel = (function (_super) {
__extends(MainViewModel, _super);
function MainViewModel() {
_super.call(this);
}
MainViewModel.prototype.signIn = function () {
//alert("Me");
alert(JSON.stringify(LocationManager));
alert(JSON.stringify(enums.Accuracy));
var locationOptions = {
desiredAccuracy: enums.Accuracy.high,
updateDistance: 0,
minimumUpdateTime: 5000,
maximumAge: 20000
};
LocationManager.startLocationMonitoring(function (location) {
console.log("Location received: " + location);
alert(JSON.stringify(location));
}, function (error) {
alert("Location error received");
alert(JSON.stringify(error));
}, locationOptions);
};
return MainViewModel;
})(observable.Observable);
exports.MainViewModel = MainViewModel;
exports.mainViewModel = new MainViewModel();
This is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.nativescript.myapp"
android:versionCode="1"
android:versionName="1.0" >
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="22"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:name="com.tns.NativeScriptApplication"
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.tns.NativeScriptActivity"
android:label="#string/title_activity_kimera"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.tns.ErrorReportActivity"/>
</application>
</manifest>
My bet would be that you haven't set the permissions in your AndroidManifest.xml (in NativeScript 1.3.0: platforms/android/src/main).
You want to have a line looking like this:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
I have a barebones index.html, Anddroid Phonegap project in Eclipse that will not execute jQuery Mobile ajax calls. LogCat displays the following messages and the app crashes
CordovaWebView: TIMEOUT ERROR!
CordovaWebViewClient.onReceivedError: Error code=-6 Description=The connection to the server was unsuccessful.
Interesting facts:
1.) Eclipse installs and runs the app fine if I comment out the ajax call. 2.) I use the same ajax pattern in an .apk that I get by processing an html-css-javascript app through PhoneGap Build, and it works fine.
Details:
In Eclipse Juno, I have an Android PhoneGap project (it uses the ADT and cordova-1.9.0.jar) with an index.html file which incorporates the following .js files in the following order:
<script type="text/javascript" src="Scripts/cordova-1.9.0.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.6.2.min.js"></script>
<script src="Scripts/temp.js" type="text/javascript"></script>
the temp.js file has this in it
$(document).ready(function(){
var theUrl = 'http://www.myDomain.biz/WebServices/gg.svc/';
console.log("theUrl + GetHelpFile = " + theUrl + "GetHelpFile");
$('div#divTarget').html("theUrl + GetHelpFile = " + theUrl + "GetHelpFile");
$.ajax({
type: "GET",
cache: false,
dataType: 'jsonp',
url: theUrl + "GetHelpFile",
contentType: "text/plain",
success: function (theJson) {
var help_file = $(theJson);
$('div#divHelpFile').html(help_file);
},
error: function ($theData) {
var tt = $theData;
alert(tt);
}
});
});
The project has
cordova-1.9.0.jar in its build path
an AndroidManifest.xml file that
has <application><activity>s for my .java file
android:name=".java_activity" and for
android:name="org.apache.cordova.DroidGap"
and all the <uses-permissions>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
the Run configuration I am using in Eclipse targets a 4.0 AVD and that all works fine.
When I comment out the ajax call, Eclipse creates the .apk file, opens the AVD, installs the app, and it runs fine. Also, I made a website in IIS for the same index.html file, in the same directory, and the page loads in the browser and the ajax runs fine.
I increased the timeout period and that did not help
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
What do you think I need to do to get the ajax call to execute in my Eclipse-Android-PhoneGap project?
Thanks
You should use different type of ajax call:
$.get('http://yourdomain.com/index.php', function (data) {
alert(data);
});
phonegap android ajax call doesnt work
here is my solution.