i have set it to update each 12 hours :
android:updatePeriodMillis="43200000"
then in the manifest I have this:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<!--
*************************************************************************************************
* Provider Configure Activity
*************************************************************************************************
-->
<activity android:name=".ConfiguratorActivity"
android:label="Configure Widget"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<!--
*************************************************************************************************
* Widget Provider Receiver
*************************************************************************************************
-->
<receiver android:name=".WidgetProvider">
<meta-data android:name="android.appwidget.provider"
android:resource="#xml/widget_provider" />
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<service android:name=".AppWidget$UpdateService" />
</receiver>
</application>
however the application keep updating each time I create the widget itself when i start the configuration activity but it does not update when i click the ok button wich its the metod that have the forcing widget instructions =/
Widgets always get updated when you create them so that you can prepare the proper look. This is a good thing; otherwise your initial layout (as defined in the xml) would be displayed until it finally refreshes after 12 hours. If you don't need that you have to detect that it's the first refresh (write a flag to shared prefs) and then ignore this one.
Button: how did you connect the button to force a refresh?
Since Donut (Android 1.6) the minimum & maximum time to update the widget is 30 min, mainly to avoid your battery will be consumed shortly.
Android guys have to change their documentation:
https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html#updatePeriodMillis
Related
When I rotate the phone the activity calls again onCreate and reset everything.
Is it possible to keep data and services like the location manager or I have to save and restore it?
By data I mean something like a list of objects.
How can I prevent code from keep running onCreate every time I rotate the phone?
Add this to your Activity in your AndroidManifest.xml:
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
Example snippet:
<activity
android:name="your.package.activity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" <!-- Keep data on rotation -->
android:windowSoftInputMode="adjustPan"> <!-- Keep keyboard from "pushing" layout -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Note: This is not the "preferred" way but I use it most of my Android applications(Read here: http://developer.android.com/training/basics/activity-lifecycle/recreating.html)
I'm working on an Android app written by someone no longer with the company, and not understanding what the purpose is of creating a receiver for AppWidget updates. The manifest has the main activity which runs when the app is launched. As far as I can tell, the appwidget is never used and its code is separate from the rest of the app. I can't tell if this is a left-over and can be removed or if it is still in use. All of the tutorials and examples I find explain how to implement this, but not really why one would, especially in this case.
Code from the manifest file:
<application
android:debuggable="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/ConnectTheme" >
<activity
android:name="com.globalcrossing.connect.ConferenceListView"
android:label="#string/listTitle" >
<intent-filter android:label="#string/app_name" >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.globalcrossing.connect.Preferences"
android:label="#string/set_preferences" >
</activity>
<!-- Broadcast Receiver that will process AppWidget updates -->
<receiver
android:name="com.globalcrossing.connect.ConferenceWidget"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget_provider" />
</receiver>
... more activities I understand, deleted for brevity
</application>
as in Doc:
ACTION_APPWIDGET_UPDATE :
Sent when it is time to update your AppWidget.
means ACTION_APPWIDGET_UPDATE Action faire when:
1. an new instance of Your AppWidget added to Home Screen from AppWidget Chooser( from AppWidget provider),
2. when requested update interval having lapsed which you have provided in AppWidget meta-data file using android:updatePeriodMillis attribute , and
3. when device reboot
If the application has a corresponding home screen widget, which can be found under the widgets section in the all programs list, then you will need APPWIDGET_UPDATE. Otherwise it will be unnecessary noise to your application with no purpose.
I'm writing a (legal) spy program. I want to make this program hidden on the launcher (so that no icon is shown). I tried to remove <category android:name="android.intent.category.LAUNCHER" /> line from AndroidManifest.xml, but then the user can't launch the application in first start mode (configuration). Who have any ideas ?
How can I do it?
You need to make your app into a service. Here is Androids take on creating services components:
http://developer.android.com/guide/components/services.html
Found this as well on MobiWare:
When you want to track the usage of the mobile or gather some data without user knowledge,this might help you.
Step1: Create an application with No icon.
Normally,an activity is declared as follows in manifest.
<activity
android:label="#string/app_name"
android:name="org.security.tracker.Tracker-activity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Remove the Category TAG ,you wont get app icon anymore.
Now,you don't need activity anymore. so remove this segment.
BUt you might think,how the app will run without any trigger or what is the starting point of the application.
This is the solution.
<!-- Start the Service if applicable on boot -->
<receiver android:name="org.security.tracker.ServiceStarter" >
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
This triggers your code that written in Receiver there by you can run service to implement your thoughts.
<service android:name="org.security.tracker.serviceCode" />
You need to add this permission,
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Your code runs when the phone reboots only.
Step 2. Write your code
On Reboot,the recevier will fire ,there you can start your service.
class ServiceStarter extends BroadcastReceiver {
#Override
public void onReceive(Context _context, Intent _intent) {
Intent i = new Intent("com.prac.test.MyPersistingService");
i.setClass(_context, ServiceCode.class);
_context.startService(i);
}
}
You can remove the <category android:name="android.intent.category.LAUNCHER"/> from the AndroidManifest.xml file.
But remember to add <category android:name="android.intent.category.LEANBACK_LAUNCHER"/> so that Android studio will be able to compile your app (yet hidden from launcher) :) :D
remove
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
from the manifest file
The app can be hidden programmatically, Below is the code which will hide the app from the Launcher menu. this works fine android 10 as well
// App will be hidden when this method will be called from menu
private fun hideApp() {
val packageManager =packageManager
val name =ComponentName(this,MainActivity::class.java)
packageManager.setComponentEnabledSetting(name,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP)
Log.d("TAG", "hideApp: success")
}
For more information, you can check this link https://developer.android.com/reference/android/content/pm/PackageManager#setComponentEnabledSetting(android.content.ComponentName,%20int,%20int)
I have an Android Widget that uses web services to retrieve and display the data on the widget. The widget has a configuration activity that extends PreferenceActivity. The configuration activity starts up as soon as the widget is installed, which is the desired behavior for this widget.
The problem is, whenever a widget is added to the home screen, the widget attempts to update iteself before the configuration activity is started/completed which may potentially lead to a long delay (several seconds). The configuration activity should occur before the widget attempts to update itself anytime a new widget is added.
Here is the sequence of events that I'm seeing in LogCat when a widget is added:
Widget.onRecive: action = APPWIDGET_ENABLED
Widget.onEnabled
Widget.onReceive: action = APPWIDGET_UPDATE
Widget.onUpdate: Widget Service is started.
WidgetService.onStartCommand: Potentially long running work which will delay the configuration activity from being immediately shown.
WidgetConfiguration.onCreate
Widget.onReceive: action = APPWIDGET_UPDATE
Widget.onUpdate: Widget Service is started again
WidgetService.onStartCommand: Potentially long running work is performed again.
What's happening is that when a widget is added, the service will start up before the configuration view has been shown.
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xxx.xxx.xxxwidget"
android:versionCode="1"
android:versionName="#string/app_version" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:debuggable="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<receiver android:name="xxxWidget" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget_info" />
</receiver>
<activity android:name="xxxWidgetConfigure" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="xxxWidgetService" />
</application>
</manifest>
Question
Is there a way to force the configuration activity to be shown before the system attempts to add the widget to the home screen?
From android documentation:
http://developer.android.com/guide/topics/appwidgets/index.html#Configuring
The onUpdate() method will not be called when the App Widget is created (the system will not send the ACTION_APPWIDGET_UPDATE broadcast when a configuration Activity is launched). It is the responsibility of the configuration Activity to request an update from the AppWidgetManager when the App Widget is first created. However, onUpdate() will be called for subsequent updates—it is only skipped the first time.
HOWEVER, this does not seem to be correct!
What I did was adding a boolean to SharedPreferences which tells me if this widgetId has been through configuration. If not skip this update. Implement this in your AppWidgetProvider class' onUpdate method.
Declare ActivityConfig in manifest:
<activity
android:name="com.zoostudio.moneylover.widget.ActivityWidgetConfig"
android:label="Hello Widget Config">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
With update widget class:
public abstract class SampleWiget extends AppWidgetProvider {
}
follow android developer widget support to understand it.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="muazam.multiplication.one"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="3" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:label="#string/app_name" android:name=".multiplication">
<intent-filter android:priority="1">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/app_name" android:name=".splash">
<intent-filter android:priority="3">
<action android:name="android.intent.action.CLEARSCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:label="#string/app_name" android:name=".Menu">
<intent-filter android:priority="2">
<action android:name="muazam.multiplication.one.Play" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
I want it to start with the .splash class first, and then .Menu class.
As you see I have put android:priority on them, but it seem to do nothing.
Anyone know how to solve this problem? Thanks.
I want it to start with the .splash class first
That has no meaning in Android.
If you meant to say "I want the .splash class to be what launches when the icon in the home screen launcher is clicked", then you need to get rid of the .splash class' current <intent-filter> (which is simply wrong) and move your MAIN/LAUNCHER <intent-filter> from the .multiplication class to the .splash class.
While you are at it, please get rid of the android:priority attributes (which are not used here) and your Play/DEFAULT <intent-filter> (which you really should not need, unless you plan on third-party apps starting up that activity directly).
and then .Menu class
You do this in Java code with startActivity().
As you see I have put android:priority on them, but it seem to do nothing.
Of course. There is no android:priority attribute for the <activity> element, as you can see in the documentation.
Activities aren't run automatically like a 'slide show' (although you could write your own code that way if you really wanted to).
The android:priority attribute is used for an entirely different purpose (from the docs for <intent-filter>...
It provides information about how able
an activity is to respond to an intent
that matches the filter, relative to
other activities that could also
respond to the intent. When an intent
could be handled by multiple
activities with different priorities,
Android will consider only those with
higher priority values as potential
targets for the intent.
In other word, if you have two activities each having an intent filter with the same action and category, then any Intent sent (from a 3rd party app) with those action/category details, will be passed first to the Activity whose intent filter has the highest priority.
This has nothing to do with how an app (and its activities) behave internally at runtime.