Permissions Plugin in Flutter - plugins

I am trying to develop an android permissions plugin in Flutter but I am stack at ContextCompat error
if(ContextCompat.checkSelfPermission(this , Manifest.permission.READ_PHONE_STATE)!= PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(this , new String[]{Manifest.permission.READ_PHONE_STATE} , 1);
}
if(ContextCompat.checkSelfPermission(this , Manifest.permission.READ_CALL_LOG)!= PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(this , new String[]{Manifest.permission.READ_CALL_LOG} , 1);
}

Related

Unable to get token using huawei_push

I have followed the steps in documentation to configure the huawei_push package in plugin.
I want to integrate push notification. I am getting error when i use this code
void _onTokenEvent(String event) {
token = event;
if (token != null) {
print("TokenEvent: " + token!);
}
}
void _onTokenError(PlatformException error) {
print("TokenErrorEvent: " + error.toString());
}
static Future<void> getToken() async {
try {
Push.enableLogger();
await Push.getToken("");
print('Huawei push token :: ${HosNotificationHelper.token} ');
Push.disableLogger();
} catch (e) {
print(e.toString());
print('THISIS EXCEPTION');
}
}
and error is below
I/HMSSDK_c(31657): The local secret is already in separate file mode.
E/HMSSDK_HMSPackageManager(31657): Failed to find HMS apk
I/HMSSDK_HMSBIInitializer(31657): Builder->biInitFlag :false
2
E/HMSSDK_HMSPackageManager(31657): Failed to find HMS apk
I/HMSSDK_HuaweiApi(31657): inner hms is empty,hms pkg name is com.huawei.hwid
I/HMSSDK_HuaweiApiManager(31657): sendRequest
I/HMSSDK_BaseHmsClient(31657): ====== HMSSDK version: 50300304 ======
I/HMSSDK_BaseHmsClient(31657): Enter connect, Connection Status: 1
I/HMSSDK_BaseHmsClient(31657): connect minVersion:30000000 packageName:com.huawei.hwid
I/HMSSDK_Util(31657): available exist: true
E/HMSSDK_HMSPackageManager(31657): Failed to find HMS apk
I/HMSSDK_AvailableAdapter(31657): HMS is not installed
I/HMSSDK_BaseHmsClient(31657): check available result: 1
I/HMSSDK_BaseHmsClient(31657): bindCoreService3.0 fail, start resolution now.
Please help
E/HMSSDK_HMSPackageManager(31657): Failed to find HMS apk
I/HMSSDK_AvailableAdapter(31657): HMS is not installed
This error indicates that the HMS Core is not installed on this device.
Therefore, you are advised to search for the HMS Core in the AppStore of the phone, install it, and try again.

Smartface 4.5 Location info

Following code gives compile error in order to get location info from gps for smartface 4.5 for android and ios.
How to get loctaion with SMF 4.5?
// Get location
* #this SMF.Net.Eventsfunction Global_Events_OnLocationChanged(e){
alert(e.lat);
alert(e.lng);
}
You should set GPS status as true before Global_Events_OnLocationChanged event.
Device.setGPSStatus(true);
* #this SMF.Net.Events
*/
function Global_Events_OnLocationChanged(e){
alert("myLat : " + e.lat);
alert("myLng :" + e.lng);
}

iphone-not receive push notification on running app developed with corona(server: pushwoosh)

excellent developers:
I have developed corona sdk project to implement push notification for android and iPhone.
In my corona sdk project, I used GCM server for android version, and pushwoosh server for iPhone version.
Android version works well now. But iPhone version can receive push notification on only not running application. iPhone version can not receive push notification from pushwoosh on running application.
I am searching solution of this issue for over 2 days, but I can not find any solutions in corona sdk project.
I shared registering/receiving push notification code from main.lua.
-------------------- main.lua --------------------
if ( system.getInfo("platformName") == "iPhone OS" ) then
notifications.registerForPushNotifications()
end
local function notificationListener( event )
if ( event.type == "remoteRegistration" ) then
local deviceToken = myData.tokenID
local deviceType = 1 --default to iOS
if ( system.getInfo("platformName") == "Android" ) then
deviceType = 3
end
if(deviceType == 1) then
local PW_APPLICATION = "XXXXX-XXXXX" --use your app ID in PushWoosh
local PW_URL = "https://cp.pushwoosh.com/json/1.3/registerDevice"
local function networkListener( event )
if ( event.isError ) then
--error occurred
native.showAlert( "Notification Registration Failed", "An Error Contacting the Server has Occurred.", { "OK" } )
else
--registration successful!
print( "-----------------------------PushWoosh registration successful", system.getInfo("deviceID") )
end
end
local commands_json =
{
["request"] = {
["application"] = PW_APPLICATION,
["push_token"] = deviceToken,
["language"] = "en", --OR: system.getPreference( "ui", "language" ),
["hwid"] = system.getInfo("deviceID"),
["timezone"] = 3600, --offset in seconds
["device_type"] = deviceType
}
}
local post_body = json.encode( commands_json )
local headers = {}
headers["Content-Type"] = "application/json"
headers["Accept-Language"] = "en-US"
local params = {}
params.headers = headers
params.body = post_body
network.request ( PW_URL, "POST", networkListener, params )
end
elseif ( event.type == "remote" ) then
if ( system.getInfo("platformName") == "Android" ) then
native.showAlert(event.alert.."on android")
else
native.showAlert(event.alert.."on iphone")
end
print("////////////////////////////////////// I got push notification("..event.alert.."). ////////////////////////////")
end
end
local launchArgs = ...
if ( launchArgs and launchArgs.notification ) then
notificationListener( launchArgs.notification )
end
Runtime:addEventListener( "notification", notificationListener )
Look forward to hearing good solutions to receive push notifications on running application in iPhone.
How can I implement corona sdk code or project settings?
Regards.
Lion

phonegap 3.1 BarcodeScanner uncaught module cordova/plugin/BarcodeScanner not found

I'm new on Phonegap and JS... and I tried it with a barcode scanner... I installed the phonegap and everything with this tutorial http://teusink.blogspot.com/2013/07/guide-phonegap-3-android-windows.html
I installed the BarcodeScanner from CMD and exported the project as android platform...
Add it to Eclipse ... followed all the tutorials how to do it, added all permissions and stuff..
when i try the app on ma samsung tab2 ... the app comes up but when i click the "scan" link i get the error uncaught module cordova/plugin/BarcodeScanner not found in the logcat.
this is the call <a href="#" class="btn large" onclick="scaning();">Scan</a
i have this in the index html head
<script src="phonegap.js"></script>
<script src="barcodescanner.js"></script>
this is the scaning function
function scaning(){
var scanner = cordova.require("cordova/plugin/BarcodeScanner");
scanner.scan(
function (result) {
alert("We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled);
},
function (error) {
alert("Scanning failed: " + error);
}
);};
and this is in the config.xml
<feature name="BarcodeScanner">
<param name="android-package" value="com.phonegap.plugins.barcodescanner.BarcodeScanner" />
</feature>
I think I checked the whole Google for the answer ... but till now nothing worked... and still for the phonegap 3.0+ version there is almost none documentation for the barcode scanner ... at least for a beginner ...
if you can help me guys .... couse I'm totally lost :S
Although I've never used older versions as I'm quite new into Phonegap/Cordova, Version 3.1 seems to use a slightly different approach for accessing plugins. Following worked for me with Cordova 3.1 and BarcodeScanner.
Install plugin with
plugman install --platform android --project=DIR-TO-CORDOVA-PROJECT --plugin=https://github.com/wildabeast/BarcodeScanner
You don't have to reference barcodescanner.js by your own, cordova takes care of the includes - the example code from https://github.com/wildabeast/BarcodeDemo worked except I had to change the plugin path from
var scanner = cordova.require("cordova/plugin/BarcodeScanner");
to
var scanner = cordova.require("com.phonegap.plugins.barcodescanner.BarcodeScanner");
edit the file: js/index.js
find the code: var scanner = cordova.require("cordova/plugin/BarcodeScanner");
replace "cordova/plugin/BarcodeScanner"
to "com.phonegap.plugins.barcodescanner.BarcodeScanner"
This one worked for me:
var scanner = cordova.plugins.barcodeScanner;
Had the same problem , got fixed by installing it via plugman like this
plugman install --platform android --project=DIR-TO-CORDOVA-PROJECT --plugin=https://github.com/wildabeast/BarcodeScanner
where DIR-TO-CORDOVA-PROJECT is E:/ProjectName/platform/android
If I didn't add the /platform/android it gave an error
and then put this in the scanning() function
cordova.plugins.barcodeScanner.scan(
function (result) {
alert("We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled);
},
function (error) {
alert("Scanning failed: " + error);
}
);

How to read an installed feature (eclipse PDE)?

Is it possible to read a feature like its possible to read a plugin use the eclipse PDE API? Currently I read plugins using:
Bundle[] bundles = Platform.getBundles(name, version);
if (bundles == null) {
throw new NullPointerException("No bundle found with ID: " + name
+ " and version: " + version);
} else {
for (Bundle bundle : bundles) {
System.out.println(bundle.getSymbolicName());
}
}
But if I specify the name of an installed feature I just get null. Is there some other way that features should be read?
And when I have read the feature I would like to iterate all the plugins that it reference.
You can try to use p2 API to query the installed feature. P2 is the manager of eclipse installation.
// IProvisioningAgent is a OSGi service
IProvisioningAgent agent = ...;
IProfileRegistry profileRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
IProfile profile = profileRegistry.getProfile(IProfileRegistry.SELF);
IQueryResult rt = profile.query(QueryUtil.createIUPropertyQuery("org.eclipse.equinox.p2.eclipse.type", "feature"), null);