BroadcastReceiver does not work - java

I'm trying to create some simple BroadcastReceiver according to manuals but I can't to make it work.
I'm calling procedure setAlarm in onCreate function in MainActivity that looks like this:
private void setAlarm() {
Intent intent = new Intent(MainActivity.this, AlarmReceiver.class);
AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, 0);
manager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+1000, pendingIntent);
}
It should activate AlarmReceiver that should do some action but doesn't do anything. It looks like this:
public class AlarmReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "I'm running", Toast.LENGTH_LONG).show();
notifikace(context);
}
public void notifikace(Context context) {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
mBuilder.setSmallIcon(R.drawable.notifikace);
mBuilder.setContentTitle("Notification Alert, Click Me!");
mBuilder.setContentText("aaa");
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
mNotificationManager.notify(2, mBuilder.build());
}
}
I suspect that I'm missing something in AndroidManifest but I don't know what. AndroidManifest looks like this:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Nastaveni"
android:label="#string/title_activity_nastaveni"
android:theme="#style/AppTheme.NoActionBar" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".Tyden"
android:label="#string/title_activity_tyden"
android:theme="#style/AppTheme.NoActionBar"></activity>
<receiver android:name=".AlarmReceiver" >
</receiver>
</application>
Ultimately appliacation should be able to send notification every day at certain time even if application isn't running at the moment. (I will have to then replace
manager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+1000, pendingIntent);
line with setRepeating function but so far for testing purposes I need first to get it running.)
But so far AlarmReceiver class doesn't do anything. I'm getting some error when I try to run it (but application doesn't crash):
04-14 11:52:54.592 1300-1354/? I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.xxx.myapplication3/com.example.xxx.myapplication.MainActivity (has extras)} from uid 10014 on display 0
04-14 11:52:54.673 1300-1635/? I/ActivityManager: START u0 {act=android.content.pm.action.REQUEST_PERMISSIONS pkg=com.android.packageinstaller cmp=com.android.packageinstaller/.permission.ui.GrantPermissionsActivity (has extras)} from uid 10057 on display 0
I'm not sure whether the error log is related to this or something else in the project. What am I doing wrong? Thanks in advance for any answer.

Sorry I saw later your receiver in manifest, your error is that you ar getting a pending intent with getService instead of getBroadcast.
Just change it to:
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
I tried it just now :)
-- edited I will leave this as a reference --
You have to register the receiver somehow, either by code or by xml.
The alarm is an Intent broadcast that goes to a broadcast receiver that you registered with registerReceiver(BroadcastReceiver, IntentFilter) or through the tag in an AndroidManifest.xml file.
Refer to:
-Pending intent - getBroadcast
-AlarmManager
-Triggering alarm and issues

Related

Android notification does not work when restarting after creating notification

As long as I don't turn the phone off (even if the application is closed), the forward notification that I have created with the alarm manager in my android-java mobile application does not have a problem. But when I restart the phone before the notification time comes, it doesn't work even if it's time for my notification. Can you please help? Thanks.
MY ALARM SERVICE CLASS
package com.gokhankopuz.kopuzfilo.services;
public class AlarmService {
private Context context = null;
private long timeInMillis = 0L;
private String notificationTitle, notificationDesc = "";
public AlarmService(Context context, long timeInMillis, String notificationTitle, String notificationDesc) {
this.context = context;
this.timeInMillis = timeInMillis;
this.notificationTitle = notificationTitle;
this.notificationDesc = notificationDesc;
}
public void setAlarm() {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, timeInMillis, getPendingIntent());
}
private PendingIntent getPendingIntent() {
#SuppressLint("UnspecifiedImmutableFlag")
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, (int) timeInMillis, getIntent(), PendingIntent.FLAG_UPDATE_CURRENT);
return pendingIntent;
}
private Intent getIntent() {
Intent intent = new Intent(context, AlarmReceiver.class);
intent.putExtra("notificationTitle", notificationTitle);
intent.putExtra("notificationDesc", notificationDesc);
return intent;
}
}
MY ALARM RECEIVER CLASS
package com.gokhankopuz.kopuzfilo.receivers;
public class AlarmReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
buildNotification(context, intent);
}
private void buildNotification(Context context, Intent intent) {
String notificationTitle = intent.getStringExtra("notificationTitle");
String notificationDesc = intent.getStringExtra("notificationDesc");
Notify.build(context)
.setImportance(Notify.NotifyImportance.HIGH)
.setTitle(notificationTitle)
.setContent(notificationDesc)
.setColor(R.color.app_background)
.setSmallIcon(R.mipmap.ic_launcher)
.setAutoCancel(false)
.show();
}
}
MY MANIFEST
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.gokhankopuz.kopuzfilo">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
tools:ignore="CoarseFineLocation" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:requestLegacyExternalStorage="true"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.KopuzFilo"
tools:ignore="AllowBackup">
<activity
android:name=".activities.NavigationActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:exported="true" />
<activity
android:name=".activities.MainActivity"
android:exported="true"
android:configChanges="orientation|screenSize|keyboardHidden"
android:windowSoftInputMode="stateVisible|adjustPan" />
<activity
android:name=".activities.SplashActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".receivers.AlarmReceiver" />
</application>
</manifest>
I added the following permissions to my manifest file but it didn't work
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
This is the expected behavior. If you turn off your device, all alarms are deleted. So, to workaround this issue, you must register for boot complete broadcast and re-schedule your alarm.
You can find more details on how to do it in the following question/answer:
does Alarm Manager persist even after reboot?
I think you can try use work manager, which will be executed by system.
WorkManager is the recommended solution for persistent work. Work is persistent when it remains scheduled through app restarts and system reboots. Because most background processing is best accomplished through persistent work, WorkManager is the primary recommended API for background processing.

Android FCM working partly while app is killed

I have 2 kinds of notification builders in my MyFirebaseMessagingService.java, one passes string called 'lecture_date' and opens Lectures_graph.class while the other one passes string called 'web_url' and opens webview_base.class when clicked.
What i want to achieve : fully working FCM notifications even when app is killed, notifications must open activity (with extras) once they are clicked.
How far i am : I can receive notifications to open Lectures_graph.class with intent extras, everything loads and works just fine. Even if i receive notifications for webview_base.class activity, nothing happens when i click on notification.
There might be one thing that points to problem - Logcat often tells me this :
E/FirebaseMessaging: Notification pending intent canceled
Im using PHP to send out notifications (that code is 100% correct and working), code below shows represents the idea of JSON sent out for webview_base.class activity. To send out notifications for Lectures_graph.class activity, i just have to swap click_action from "OPEN_ACTIVITY_WEBVIEW" to "OPEN_ACTIVITY_LECTURES" and change the data payload. PHP for webview_base.class activity sends away such data :
$msg = array
(
'body' => 'test body',
'title' => "test title",
'click_action' => 'OPEN_ACTIVITY_WEBVIEW',
'channelId' => "newsfeed",
'vibrate' => 1,
'sound' => 1
);
//sends notifications via topics
$fields = array
(
"data" => [
'web_url' => $_POST['notification_url']
],
'notification' => $msg,
'to' => '/topics/test'
);
This is my whole manifest file from Android studio :
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="secret">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true" />
<application
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:theme="#style/AppTheme.CustomTheme"
android:usesCleartextTraffic="true"
tools:targetApi="m">
<activity
android:name=".systems.webview_activity.webview_base"
android:configChanges="orientation|screenSize">
<intent-filter>
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="file" />
<data android:mimeType="\*/\*" />
<data android:pathPattern=".*\\.kdb" />
<data android:host="*" />
//even if this method worked with Lectures_graph activity
//it doesnt work with this one
<action android:name="OPEN_ACTIVITY_WEBVIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".systems.lectures.Lectures_graph"
android:configChanges="keyboardHidden|screenSize"
android:label="#string/title_lectures_graph"
>
<intent-filter>
//this intent filter provides correct response
//to click_action which is provided in my PHP file
<action android:name="OPEN_ACTIVITY_LECTURES" />
<action android:name = "android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".SplashScreen"
android:configChanges="keyboardHidden|orientation|screenSize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".NoInternetConnection"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name="secret.systems.about.about_app"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="#style/FullscreenTheme" />
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden|screenSize">
</activity>
<service
android:name="secret.services.MyFirebaseMessagingService"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>
MyFirebaseMessagingService.java:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
//get key/value from notification
String lectureDate = remoteMessage.getData().get("lecture_date");
String web_url = remoteMessage.getData().get("web_url");
if(lectureDate != null)sendLecturesNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody(), lectureDate);
else if(web_url != null) sendNotificationWithURL(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody(), web_url);
else Log.e(TAG, "Message.notification is empty!");
}
}
#Override
public void onNewToken(#NonNull String token) {
Log.d(TAG, "Refreshed token: " + token);
}
private void sendLecturesNotification(String title,String messageBody, String date) {
Intent intent;
intent = new Intent(this, Lectures_graph.class).putExtra("lecture_date", date).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, ((int) System.currentTimeMillis()) /* Request code */, intent,
0);
String channelId = getString(R.string.lectures_channel_id);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.secret)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.notify(((int) System.currentTimeMillis()), notificationBuilder.build());
}
Log.d(TAG, "Lectures notification built with date:"+date);
}
private void sendNotificationWithURL(String title, String messageBody, String web_url) {
Intent intent;
intent = new Intent(this, webview_base.class).putExtra("web_url", web_url).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, ((int) System.currentTimeMillis()) /* Request code */, intent,
0);
String channelId = getString(R.string.newsfeed_channel_id);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.secret)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.notify(((int) System.currentTimeMillis()), notificationBuilder.build());
}
Log.d(TAG, "Webview notification built with URL:"+web_url);
}
}
a while ago i was getting an error in logcat that said something like "default FCM channel is not defined", but im not quite sure thats the problem.
Even if i searched across the whole web, i would like to see better solutions/suggestions for notification (with its payload) handling when app is killed.
So i fixed my nightmare and here is how :
Since i cant open more than one specific activity from notifications, why could i just open my apps main class and handle extra variable from there ?
Instead of having for each wanted activity
<intent-filter>
<action android:name="OPEN_ACTIVITY_???????" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
i made this :
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden|screenSize">
<intent-filter>
<action android:name="OPEN_APP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
I added extra variable to notifications payload (examle : 'activity' => 'webview') and renamed click_action in my PHP code. I handled all payloads in MainActivity.class and called wanted android activity from there. MainActivity code :
Bundle extras = getIntent().getExtras();
if(extras == null) {
Log.e("MainActivity", "No Activities passed in notification extras");
} else {
//get opening activity from notification payload
String activity = extras.getString("activity");
if( activity != null){
switch (activity){
//webview activity
case "webview":
//gets url for webview
String web_url = extras.getString("web_url");
if(web_url != null){
finish();
startActivity(new Intent(this, webview_base.class).putExtra("web_url", web_url));
}
break;
//lectures activity
case "lectures":
//gets lecture date
String lecture_date = extras.getString("lecture_date");
if(lecture_date != null){
finish();
startActivity(new Intent(this, Lectures_graph.class).putExtra("lecture_date", lecture_date));
}
break;
}
}
}
Hope this helps someone, someday..
Cheers.

Can't create notification even though notification manager is initialized correctly

I am trying to send a notification using the NotificationManager API in Android. Below is my code:
AndroidManifest.xml:
<uses-sdk
android:minSdkVersion="23"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
...
<activity
android:name="com.tabs.activity.Comments"
android:configChanges="orientation|keyboardHidden"
android:label="View Post"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" >
</activity>
<service
android:name="com.tabs.activity.NotificationService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
...
Comments.java:
public void createComment(){
...
NotificationService notificationService = new NotificationService();
notificationService.showNotification(getApplicationContext(), R.id.commenter_profile_photo, "User commented: Hi!", "User");
...
}
NotificationService.java:
public void showNotification(Context context, int commenterId, String messageBody, String commenter){
NotificationCompat.Builder notifiationBuilder = new NotificationCompat.Builder(this)
.setContentTitle("Title")
.setContentText(messageBody)
.setTicker("New comment from " + commenter)
.setSmallIcon(commenterId);
Intent moreInfoIntent = new Intent(context, news_feed.class);
//When the user clicks back, it doesn't look sloppy!
TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
taskStackBuilder.addNextIntent(moreInfoIntent);
//If the intent already exists, just update it and not create a new one
PendingIntent pendingIntent = taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
//When the notification is actually clicked on
notifiationBuilder.setContentIntent(pendingIntent);
//Notification manager to notify of background event
notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(1, notifiationBuilder.build());
}
Error that is shown (Stack Trace):
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:160)
at android.app.Notification$Builder.<init>(Notification.java:2287)
at android.support.v4.app.NotificationCompatApi21$Builder.<init>(NotificationCompatApi21.java:68)
at android.support.v4.app.NotificationCompat$NotificationCompatImplApi21.build(NotificationCompat.java:759)
at android.support.v4.app.NotificationCompat$Builder.build(NotificationCompat.java:1559)
at com.tabs.activity.NotificationService.showNotification(NotificationService.java:113)
at com.tabs.activity.Comments.createComment(Comments.java:146)
The problem with this code is that for whatever reason, the notificationManager.notify(1, notifiationBuilder.build()); line always produces a NullPointerException. I know what they are but I can't seem to solve this one because I don't understand why my context would need getApplicationInfo(). My context should already have that when I pass it in from Comments.java which is confusing me. I just don't see how I could have built the notification manager incorrectly. Below is the stack trace that is given. Any help would be appreciated. Thanks!
Change
NotificationCompat.Builder notifiationBuilder = new NotificationCompat.Builder(this)
to
NotificationCompat.Builder notifiationBuilder = new NotificationCompat.Builder(context)

Android - start AlarmManager after reboot

AlarmManeger doesn't start after reboot but it should.
How can I do it?
AndroidManifest:
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name=".AlarmEngine.AlarmManagerHelper" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
BroadcastReceiver:
#Override
public void onReceive(Context context, Intent intent)
{
setAlarms(context);
}
public static void setAlarms(Context context)
{
cancelAlarms(context);
AlarmDBHelper dbHelper = new AlarmDBHelper(context);
List<AlarmModel> alarms = dbHelper.getAlarms();
for (AlarmModel alarm : alarms)
{
PendingIntent pIntent = createPendingIntent(context, alarm);
...
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pIntent);
I fixed it moved app to the phone's memory.
I replace this:
android:installLocation="preferExternal" >
On this:
android:installLocation="internalOnly" >

Why my widget doesn't get installed?

I want to install my widget to my home page after i drag and drop it, but when i do it, it says app can't get installed here is my code:
public class WidgetProvider extends AppWidgetProvider {
#Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
Intent receiver = new Intent(context, WidgetReceiver.class);
receiver.setAction("COM_FLASHLIGHT");
receiver.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, receiver, 0);
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
views.setOnClickPendingIntent(R.id.Button, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, views);
}
}
And my provider info:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="40dp"
android:minHeight="40dp"
android:updatePeriodMillis="86400000"
android:previewImage="#drawable/more"
android:initialLayout="#layout/widget_layout"
android:configure="com.flashlight.standroid.WidgetProvider"
android:resizeMode="horizontal|vertical"
android:label="Monitor Widget">
</appwidget-provider>
My Manifest:
<receiver
android:name=".WidgetProvider"
android:icon="#drawable/more"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="com.example.flash.ACTION_WIDGET_RECEIVER" />
<action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/provider_info" />
</receiver>
<receiver
android:name="WidgetReceiver">
<intent-filter>
<action android:name="com.flashlight"></action>
</intent-filter>
</receiver>
Here i have gathered almost all the parts of code that i use to run/install.. my widget.Thanks in advance
Remove android:configure from your app widget metadata, or have it point to an activity to be used for configuring the app widget.
You can read more about configuration activities in the documentation.
change
android:configure="com.flashlight.standroid.FlashlightWidgetProvider"
with
android:configure="com.flashlight.standroid.WidgetProvider"
And make sure the Activity name is exactly wrote down on the android manifest.

Categories