How to install Android widget from an Android Activity? - android-widget

I want to install the widget from the Android Activity. After doing this the widget should be available along with the list of other previously installed widgets. For this, i have created a custom widget. But dont know how to install the widget from the Activity.

I got the solution for this. We have to mention the Widget in the manifest file as a receiver. Then it will create the widget. We can use the widget by long press on the home screen and tap widget to place on home screen. I got the answer after lot of search. The usage is ,
<receiver
android:name="MyWidgetProvider"
android:icon="#drawable/widic"
android:label="Example Widget" >
<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>

Related

Flutter app run stuck white screen on device

i've developed a an app on flutter, despite it worked 2 days ago, when i run the app on the device the application it does not start. It remains on the white screen and do not launch the app. I think that something happened when i synchronized the gradle.
My main.dart:
import 'package:my_firstapp/locator.dart';
import 'package:my_firstapp/models/user_model.dart';
import 'package:my_firstapp/screens/wrapper.dart';
import 'package:provider/provider.dart';
import 'package:my_firstapp/services/auth.dart';
import 'package:firebase_core/firebase_core.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
setupServices();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return StreamProvider<UserModel>.value(
value: AuthService().user,
child: MaterialApp(
theme: ThemeData(
primaryColor: Color(0xff5FA55A),
accentColor: Color(0xff5FA55A),
),
home: Wrapper(),
),
);
}
}
My manifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.my_firstapp">
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:label="food_track"
android:icon="#drawable/launch_background">
<activity
android:name="com.example.my_firstapp.MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="#style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.aptreesoftware.barcodescan.BarcodeScannerActivity"/>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
I checked that everything is upgraded and it is. Do you have any ideas?
Open the terminal, cd to android folder of your flutter project and run:
$./gradlew build

Flutter add to app Android shows white screen on startActivity

I have an app where there are some screens that are made in Flutter (add2app). I have a class called CMFlutterActivity that is a subclass of io.flutter.embedding.android.FlutterActivity. I use this class to manage the method channels, but I am not too happy with how the screen is presented, because the first Flutter frame is not available when the Activity is presented. After some research I figured there is a method in the FlutterActivity that I can override to know when the first Flutter frame is available, it is called onFlutterUiDisplayed. The problem I have is: how do I manage to only make the Activity visible after this method has been called? Has anyone solved this problem already?
I am currently starting the activity in the following manner:
startActivity(Intent(context, CMFlutterActivity::class.java))
Here are some of my configurations:
AndroidManifest.xml:
<activity
android:name=".ui.flutter.CMFlutterActivity"
android:theme="#style/AppTheme.NoFullscreen"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
android:screenOrientation="portrait"
android:stateNotNeeded="true"
android:exported="true"
/>
styles.xml:
<style name="AppTheme.NoFullscreen">
<item name="android:windowFullscreen">false</item>
</style>

Alarm Activity gets launched on launching the app

Scenario : I have a simple to-do app where In the main activity I have a fragment that takes a list of to-dos from the user. I set an alarm for a fixed time in the future (in my case every 2 min ONLY for testing. The AlarmReceiver class launches an AlarmActivity which shows the list of to-dos as checkboxes for the user to mark as done.
When the alarm comes up and shows the list, I have a "Submit" button to mark all the checked items as 'done' in the local db.
Problem:
This AlarmActivity disappears on click of submit since I'm calling finish on it. But when I launch the app from the icon, the AlarmActivity is shown instead of the main activity.
AlarmReceiver code :
final Intent intent1 = new Intent(context, CheckListAlarmActivity.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NO_HISTORY);
context.startActivity(intent1);
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:noHistory="true"
android:clearTaskOnLaunch="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AlarmActivity"
android:alwaysRetainTaskState="false"
android:clearTaskOnLaunch="true"
android:showOnLockScreen="true"
android:screenOrientation="sensorPortrait"
android:noHistory="true"/>
<receiver android:name=".AlarmReceiver" />
</application>
I added the android:clearTaskOnLaunch="true" and that seems to do the trick sometimes but not always.
And in the background when I put the loggers, it shows that every time I launch using the app icon it calls the onCreate of the MainActivity and then immediately calls the onCreate of the AlarmActivity.
I have tried looking for all kinds of solutions and tried setting a bunch of flags to the Intent. Nothing seems to do the trick convincingly.
It seems like a simple problem but I am not able to find the solution. Any help/guidance would be appreciated.

How can I change starting activity in Basic4Android?

Is there a way to change starting activity in Basic4Android?
Always Main activity automatic added and set the starting activity.
Program not let to change its name too...
Is it possible?
Go to: "Project" -> "Manifest Editor" and a popup window with Android manifest xml code will show up. Insert this code after AddManifestText(... and change yourActivityName to what you want.
<activity android:name=".yourActivityName" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You can run Activity.Title= "YourTitle" in any activity to display alternative name in the title bar if that is why you are looking to change the startup activity.
There is no way, I think it is not possible.
You can switch names of two activities in the manifest editor which would effectively start your app from activity2 code module:
SetActivityAttribute(Main, android:name, ".activity2")
SetActivityAttribute(Activity2, android:name, ".main")

Every activity shows its own icon

I have a few activities in my app, but for some reason on the menu there are a lot of
Icons of my app- for every activity.
How can I fix it and make an Icon for MainActivity only?
Ty.
In your manifest remove these lines from all Activities except the one you want to open on:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
(I recommend removing them from all the activities exept MainActivity).