Is it possible to run a timer task when the application is closed? - runtime

I have just completed learning Java, now I am working on creating Android apps. But I am not so expert in this field. I have just created an Android app which has some advertisements like banner ad, interstitial ad. I want to give an opportunity to the user to stop those Ads for 24 hours if they watch a video AD. But I'm not familiar with timer task any suggestion will be very appreciating. here is the code that I imagine :
// load from shared preference
SharedPreference spref = getSharedPreference("directory_name", 0);
if(spref.getBoolean("ad_key", false)==true){
// all ads should stop showing
}else{
// ads are showing
}
// help me here in timer task
As ad reward
--> start countadown
--> if(countDown>0){
doneWatchindAd(true);
}else{
doneWatchindAd(false);
}
// store to shared preference
public void doneWatchindAd(bollean cond){
SharedPreference spref = getSharedPreference("directory_name", 0);
SharedPreference.Editor editor = spref.edit();
editor.putBoolean("ad_key", cond);
editor.commit();
}

Related

Android Facebook Native ads error: 1001 no fill on user device

Our application use Facebook Native Ad via mediation platform Mopub, and it works good, but we should move to another platform.
I've replaced SDK platform, using the same placementId and app_id and tested my application as Developer.
Everything works good in test mode with real ads also, but I cannot get ads on real devices.
I tried to implement Facebook Native without any mediation platforms(code in the bottom), but still have the same result.
So the issue is not in partner platform,but I cannot get ads on real devices. Facebook Native throws error: 1001 no fill
It looks very strange, because I have:
Application has real users and shows ads in the previous version.
Application in PlayMarket(but with the previous implementation) with same package Id, placementId and app_id.
Facebook has checked my app.
I can see requests from new and previous version.
Code and logs:
AndroidManifest:
//...
//...
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/app_id" />
Application build.gradle:
//...
ext {
supportLibraryVersion = '25.3.1'
playServicesVersion = '11.0.1'
FBVersion = "4.25.0"
}
dependencies {
compile project(':library')
compile fileTree(include: ['*.jar'], dir: 'libs')
//...
compile "com.facebook.android:audience-network-sdk:$FBVersion"
//...
}
FacebookNativeLoader.java:
//...
/**
* Initiate ad container for native ad
*/
Override
public View createContentView(Context context) {
log(" createContentView");
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
return inflater.inflate(R.layout.facebook_ad_native_view, null);
}
#Override
public void loadAd(final MyViewManager myViewManager, final ResultListener resultListener) {
log(" loadAd");
adNativeLayout = myViewManager.getContentView();
// Create ad request with Facebook ad PlacementId
adNative = new NativeAd(myViewManager.getContext(), adPlacementId);
//
adNative.setAdListener(new AdListener() {
#Override
public void onError(Ad ad, AdError adError) {
log("FacebookNative Ad Loading Failed." +
"Error:" + NATIVE_LOAD_ERROR +
" ErrorCode:" + adError.getErrorCode() +
" ErrorMessage" + adError.getErrorMessage());
//Call Error to hide ad layout
resultListener.onError(NATIVE_LOAD_ERROR);
}
#Override
public void onAdLoaded(Ad ad) {
log("FacebookNative Ad Loading Completed");
//...
// Download icon for native ad
if (adNative.getAdIcon() != null) {
String iconUrl = adNative.getAdIcon().getUrl();
if (iconUrl != null && iconUrl.length() > 0)
NativeAd.downloadAndDisplayImage(adNative.getAdIcon(), icon);
}
// Download cover for native ad
if (adNative.getAdCoverImage() != null) {
String coverUrl = adNative.getAdCoverImage().getUrl();
if (coverUrl != null && coverUrl.length() > 0)
NativeAd.downloadAndDisplayImage(adNative.getAdCoverImage(), contentImage);
}
//Show debug info
log("adNative.getCalltoAction() - " + adNative.getAdCallToAction());
log("adNative.getBody() - " + adNative.getAdBody());
log("adNative.getClickUrl() - " + adNative.getAdCallToAction());
BaseLockScreenManager.url = adNative.getAdCallToAction();
title.setText(adNative.getAdTitle());
text.setText(adNative.getAdSubtitle());
downloadButton.setText(adNative.getAdCallToAction());
// Add the AdChoices icon
LinearLayout adChoicesContainer = (LinearLayout) adNativeLayout.findViewById(R.id.ad_choices_container);
AdChoicesView adChoicesView = new AdChoicesView(myViewManager.getContext(), adNative, true);
adChoicesContainer.addView(adChoicesView);
//Call Success to show ads
resultListener.onSuccess(true);
}
#Override
public void onAdClicked(Ad ad) {
//Do something
}
#Override
public void onLoggingImpression(Ad ad) {
//Do something
}
});
//Register Ad container to catch user Interactions
adNative.registerViewForInteraction(adNativeLayout);
// Initiate a request to load an ad.
// Loading Ad started here...
adNative.loadAd();
}
In Facebook documentation "error: 1001 no fill" means:
This is a common error seen while testing, and relates to a "No Fill"
response; the most common reason for this is the user is not logged in
to the Facebook App when testing your mobile app or not logged in to
the Facebook mobile website when testing your mobile website.
Error 1001 - No Fill. May be due to one or more of the following:
- User not logged into Native Facebook App on Mobile Device(But real device logged into Native Facebook App)
Limit Ad Tracking turned on (iOS)(but this is not relevant for Android app)
Opt out of interest-based ads turned on (Android) (but I've turned value off)
No Ad Inventory for current user (What does it mean?)
Your testing device must have the native Facebook application installed.(but I tested on real device with real Facebook account)
Your application should attempt to make another request after 30 seconds.(but I'have the same result everytime)
LogCat messages:
Developer device:
FacebookLoader:
I/----FacebookLoader: loadAd
I/----FacebookLoader: createContentView
I/----FacebookLoader: Facebooknative Ad Loading Completed
I/----FacebookLoader: adNative.getCalltoAction() - Learn More
I/----FacebookLoader: adNative.getBody() - LAToken aims to tokenize assets worth $1.2 trillion by 2025.
I/----FacebookLoader: adNative.getClickUrl() - Learn More
User Device:
FacebookLoader:
I/----FacebookLoader: loadAd
I/----FacebookLoader: createContentView
I/----FacebookLoader: FacebookNative Ad Loading Failed.Error:669 ErrorCode:1001 ErrorMessage: No fill
What can be issue of it? Has somebody the same issue?
I'm afraid to make release without ability to be sure that user can see ads, because the main idea of our application is Advertisement.
step 1: goto play store download native Facebook app install and login
step 2: Then test your app "testing add loading success"
Other errors like : " FacebookAdapter: No fillI/TAG: No fill.I/Ads: Ad failed to load : 3"
then : goto Manifest file and add on application level : android:usesCleartextTraffic="true"
<application
.........
android:usesCleartextTraffic="true"
.......
/>

How to start the app that is associated to the IBackgroundTask I've created in UWP Windows 10

I implemented an IBackgroundTask on Universal Windows 10 and it works like a charm but the problem is that i want to start the app that is associated to that background task if some action occurs. The code is simple:
public sealed class AdvertisementWatcherTask : IBackgroundTask
{
private IBackgroundTaskInstance backgroundTaskInstance;
public void Run(IBackgroundTaskInstance taskInstance)
{
backgroundTaskInstance = taskInstance;
var details = taskInstance.TriggerDetails as BluetoothLEAdvertisementWatcherTriggerDetails;
if (details != null)
{
//Do things
}
}
}
I've seen that you can create a ToastNotification like that:
Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
Windows.Data.Xml.Dom.XmlNodeList elements = toastXml.GetElementsByTagName("text");
foreach (IXmlNode node in elements)
{
node.InnerText = taskInstance.Task.Name+ " remember to uninstall task if not debugging";
}
ToastNotification notification = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(notification);
The notification toast works good. It creates and prompts a notification and if you click it, the app that created this background task starts. This is the behaviour that I want but I want to start the app without having to click any notification. Is there any way to achieve this? Thank you.
TL;DR: I want to start the app that created the background task at some point of the code.
You can not programmatically launch URI or open app from background task. You can however display a reminder or toast notification to let user open your app.

Schedule push notification Parse unity

Can i use Parse.com Unity plugin to schedule push notification to the user once an action is done.
i.e) Notify the user in 1 hour that his building has been built.(as in coc an example)
I don't think Push Notifications is what you are looking for here, instead I think you want Local Notifications. With Local Notifications, you schedule a notification to appear at a specified time (you usually schedule the notification when the player leaves the app, as you wouldn't normally want the notification to appear as they are playing it).
For example, you would do the following (not tested):
public void OnApplicationPause(bool isPaused)
{
// If paused, then in background
if (isPaused)
{
LocalNotification notification = new LocalNotification();
notification.alertAction = "App Name";
notification.alertBody = "The building is complete";
notification.hasAction = true;
notification.applicationIconBadgeNumber = 1; // Set's the badge count
notification.fireDate = dateBuildingWillBeFinished;
NotificationServices.ScheduleLocalNotification(notification);
}
else // Entered the app
{
// Clear notifications
NotificationServices.CancelAllLocalNotifications();
NotificationServices.ClearLocalNotifications();
}
}
Push Notifications are generally used to send messages to all players, or a group of players (such as players in the UK) to notify them of something, like a sale that is going on for in app purchases. Local Notifications are user specific, and can act more as reminders, such as your building has been completed or you haven't visited your town in a week etc.

Launching a background agent from within the app

As far as I have understood, if you register a periodic task to deal with your WP7 live tiles, it will not update more than once every half hour. However, I would like to update the data the background agent works on every time the user exits the app.
My scenario is that I have a live tile displaying the first entry in a planner - and depending on what the user does within the app, that planner might get its entries deleted or have a new one up front. To have the live tile present outdated info is not very appealing.
Is this possible - and if so, how to?
I dont know if this is what you are looking for.
My app updates livetiles when the user exits the app. But then I have had problems such as, if the user does not open the app for few days then it does not get updated.
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
ShellTile PrimaryTile = ShellTile.ActiveTiles.First();
StandardTileData tile = new StandardTileData();
if (PrimaryTile != null)
{
tile.BackTitle = resMan.GetString("liveTileTitle");
tile.BackBackgroundImage = new Uri("/Background.png", UriKind.Relative);
if (pCycMan.GetStartDate() == pCycMan.GetDefaultDate())
{
tile.Title = resMan.GetString("liveTileNotTrackingStatus");
}
else
{
tile.Title = App.m_liveTileText;
}
PrimaryTile.Update(tile);
}
}

WIN7 Keyboard hook stops working in another user account?

I created my own parental control app using C# to monitor my kids activity. It logs all the keyboard input and screens in the background silently, with the only gui of taskbar icon. So far, I just let it run in my admin account and everybody share the same account and it works fine. The problem is that as kids grow up, they found a way to kill it from the task manager. So, I need to use a more sophisticated way to protect my app. I thought I could solve this problem easily by creating a separate standard account for each kid and I can setup my app to run as an admin to monitor all their activities. However, I faced a lot of issues.
The keyboard hooks seem to stop working once I switched to a different user account. Is it true? I thought it's global hook - is it just global within the user account?
The screen capturing doesn't work on another user account either. This is my code and
it failed at g.CopyFromScreen with error "the handle is invalid":
RECT rc = Win32.GetWindowRect();
using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(rc.Width, rc.Height))
{
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
{
g.CopyFromScreen(rc.Location, System.Drawing.Point.Empty, new System.Drawing.Size(rc.Width, rc.Height));
string fileName = Settings.Instance.GetImageFileName();
bitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
}
}
Your help is much appreciated.
As long as the kids aren't administrators, you can run the program under their accounts and deny access to the process.
For example (tested):
static void SetAcl() {
var sd = new RawSecurityDescriptor(ControlFlags.None,
new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null),
null, null, new RawAcl(2, 0));
sd.SetFlags(ControlFlags.DiscretionaryAclPresent | ControlFlags.DiscretionaryAclDefaulted);
var rawSd = new byte[sd.BinaryLength];
sd.GetBinaryForm(rawSd, 0);
if (!NativeMethods.SetKernelObjectSecurity(Process.GetCurrentProcess().Handle, SecurityInfos.DiscretionaryAcl, rawSd))
throw new Win32Exception();
}
static class NativeMethods {
[DllImport("Advapi32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetKernelObjectSecurity(IntPtr target, SecurityInfos info, byte[] descriptor);
}

Resources