I'm working with ionic/cordova for developing cross-platform apps with angular 5. Everything is working great. I just encountered a scenario where I need to show some preference only on the mobile device. They should not be visible on tablet etc. Is there any way through which I can restrict some of my preferences only to mobile devices ? e.g. some kind of key on the preference to tell it should only be rendered is device is a mobile handset.
I've already googled it but found nothing. Just wondering is there any way or is this thing impossible.
(Remember, its not a bug or issue, I just want some additional functionality in my existing app so asking for code is useless ;) )
Any help would be highly appreciated.
You can use the Platform service to check whether a device is a mobile phone or a tablet. Using this info, you can set your app preferences as needed. See this slightly modified example from the docs here and here:
import { Platform } from 'ionic-angular';
import { AppPreferences } from '#ionic-native/app-preferences';
#Component({...})
export MyPage {
constructor(public plt: Platform, public appPreferences: AppPreferences) {
if (this.plt.is('mobile')) {
this.appPreferences.store(ok, fail, 'key', 'value');
}
}
}
ok and fail are the callbacks executed if storing the preferences went well or failed. See the example here.
Related
My App created by Meteor is now doing upgrading by Meteor's HCP(Hot Code Push), which means the user will get a new version as soon as he restarts the App, without any information or confirm dialog.
HCP is great, but there are two reasons some users don't want the App be upgraded quietly:
New version may have degrades or other risks.
Old version is enough for theirs uses.
So I want to know if there is a way, I can show user a new-version-available dialog describing features of the new version, and ask him whether to upgrade or not. When he agreed, use HCP to do the upgrade work or, download the necessary package by writing code if HCP not usable in this occasion.
By the way I have another question related: Why HCP only work on android phone, how to make it work on iOS phone.
Many thanks in advance for answering any one of the two questions, or both.
Thank you.
By the way I have another question related: Why HCP only work on android phone, how to make it work on iOS phone.
HCP should work on all platforms in the same way.
To show prompt dialog you have to intercept HCP in Reload._onMigrate hook:
import { Reload } from 'meteor/reload';
Reload._onMigrate(() => {
const decision = confirm("New version is available, would you like to upgrade now?")
return [decision]; // Return [false] to manually handle HCP
});
This is a very simple example, you can trigger nice UI/UX element to handle it.
For example we always return [false] in _onMigrate hook. Show to the user nice pop-up. And if user choose to update now, we trigger next function (pick options you need):
// Purge and reload cache for AppCache package
window.applicationCache.swapCache();
window.applicationCache.update();
// Drop ServiceWorker cache
window.caches.keys().then((keys) => {
keys.forEach((name) => {
window.caches.delete(name);
});
}).catch((err) => {
console.error('window.caches.delete', err);
});
// Unregister Service Worker
SWRegistration.unregister();
// Reload the page
if (window.location.hash || window.location.href.endsWith("#")) {
window.location.reload();
} else {
window.location.replace(window.location.href);
}
In my logout option, I need to clear all of my app's data reverting it to a fresh installation state. Basically I need to trigger the same effect as manually doing Settings->Installed Apps->AppName->Clear App Data
Any ideas how to do it?
PS: This is specifically for the android platform only, though if there's a cross-platform solution I'd be most grateful.
For android version greater then kitkat you can use
import android.os.Build.*;
if (VERSION_CODES.KITKAT <= VERSION.SDK_INT) {
((ActivityManager)context.getSystemService(ACTIVITY_SERVICE))
.clearApplicationUserData(); // note: it has a return value!
}
please don't make my post like as duplicate why because am totally confused with those post when i google it.
but i need your valuable statements and real time experience on How to get UNIQUE IDENTIFIER for iOS,Android and Windows Mobiles
i have a scenario that when user login with UserName and Password i send details to server at same time i need to send Device UUID. By using device UUID and User Credentials am going to Restrict second user login when first user is already logged in(Active). but am confused with getting iOS Device UUID but wheen i seen in many post iOS is killing apps in App store when app is Accessing any UUID values.
please suggest me better way to complete mytask.
Link-1
Link-2
sorry for my bad english....!!!
You can use the Unique Device ID plugin.
Install it:
cordova plugin add cordova-plugin-uniquedeviceid
And use it:
window.plugins.uniqueDeviceID.get(function(uuid){
console.log("Unique ID": +uuid);
}, function(error){
console.error(error);
});
This will give you a unique ID per device that persists between installs.
Note that on Android 6 it requires telephony run-time permission to access SIM ID. Also you may need to fork it and update it to get the Windows Phone 8 code working on Windows 10 Mobile.
in the case of angular
you gotta install ngx-device-detector via npm then import it on your module and in the import section add DeviceDetectorModule.forRoot().then in the component you're gonna use import it and add private deviceService: DeviceDetectorService this in the constructor it will generate u a method and add it on the constructor this.epicFunction(), if it doesnt paste this
epicFunction() {
console.log('hello `Home` component');
this.deviceId = this.deviceService.getDeviceInfo();
const isMobile = this.deviceService.isMobile();
const isTablet = this.deviceService.isTablet();
const isDesktopDevice = this.deviceService.isDesktop();
console.log(this.deviceId);
console.log(isMobile); // returns if the device is a mobile device (android / iPhone / windows-phone etc)
console.log(isTablet); // returns if the device us a tablet (iPad etc)
console.log(isDesktopDevice); // returns if the app is running on a Desktop browser.
}
note: the "this.deviceId" is a variable i created in the start of the class
in the case of android just import the security and add the permission on the manifest file
I'm going nuts over here! I've got a website I am making in CakePHP that will form the back end of a mobile application. It is not a mobile website, it's designed purely to be used for a smartphone application.
That being said: The application needs the user to login. But I just cannot seem to find the right way to implement this. The BasicAuthenticate AuthComponent seems to hate me and doesn't make debugging easy. There's an OAuth 2.0 Provider plugin for CakePHP 2.0, but I can't figure out how to make it 2 legged, as the app won't be relying on the website to display a login form.
I really need to figure out which of these paths to take and how to make it work but just neither one wants to work. Anybody have any info on what I need to do?
Update The Basic Auth issue turned out to be due to Virtualmin preferring to use FCGId to allow the process to run as the same owner as the content of the website. I have since switched it back to mod_php and it works fine.
So my question is now more about using cakephp-oauth-server in a 2 legged setup.
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('index','view');
$this->set('logged_in', $this->Auth->loggedIn());
$this->set('current_user',$this->Auth->user());
if($this->name == 'Specific') {
// for the specific controller
$this->Auth->authenticate = array('Basic');
} else {
// everything else
}
}
checkout KVZ's rest plugin it may be of interest https://github.com/kvz/cakephp-rest-plugin
I am going to be sending off press-kits to various reviewers in regards to my new Android game and I am wondering how I should go about sending them an APK they can test? The game is paid and licensed.
If I send them the licensed version of the game they won't be able to run it on their phones without buying it. However, if I send them an unlicensed version and someone leaks it then everyone will just be able to get my game for free. What should I do?
Your options are pretty much limited to:
a time limited (demo) version
sending them an unlocked version which displays some personal information about the reviewer, thus making it in the reviewer's interests to keep the APK to themselves
using a licensing server. ie the game checks against a server (on GAE or similar) to see if it is allowed to run
I'm sure there are other options - I'd be interested to hear them.
One thing that is sorely missing from the Android Market is the ability to give the app to people. I think this is possible on the iOS store - at least like this you'd be able to grant real licences to the reviewers.
Following on from the above answers. Here's what I do (plus a message on the splash screen with the name of the reviewer)
private void initNewGame() {
//do a date check and quit if necessary
if ( reviewMode ) {
if ( new GregorianCalendar().after(new GregorianCalendar(2011,3,1,0,0,0))) {
//quit
((Program)parentActivity).finish();
}
}
}
I would also be interested if anyone has other ways of doing this, it's a really good question.
Make a free demo version that expires or something like that?