The following code was written to snooze the currently ringing alarm. It is working fine in android emulator and behaving differently in different mobiles. Mobiles with API 23 are throwing an intent not found exception. Mobiles with API >23 are not throwing an exception, but failing to snooze.Please help me in resolving this issue.
public class AlarmReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent a = new Intent();
a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
a.setAction(AlarmClock.ACTION_SNOOZE_ALARM);
context.startActivity(a);
}
}
Here is the manifest file,
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.sriyanksiddhartha.fragmentdemo"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<uses-permission android:name="com.android.alarm.permission.SNOOZE_ALARM"/>
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:name=".AlarmReceiver">
<intent-filter>
<action android:name="com.android.deskclock.ALARM_ALERT"/>
<action android:name="com.android.alarmclock.ALARM_ALERT"/>
</intent-filter>
</receiver>
</application>
</manifest>
exception in mobiles
Related
The error I am receiving is
2022-01-28 11:10:42.186 1651-3045/? W/ActivityManager: Unable to start service Intent { act=nveeaidle pkg=com.rchan.nveeapplication } U=0: not found
I have ensured the following code in both my applications (client and server). In my server manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rchan.nveeapplication">
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<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/Theme.NveeApplication">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="com.rchan.nvee_sdk.detectedactivity.DetectedActivityService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="nveeaidle" />
</intent-filter>
</service>
<receiver android:name="com.rchan.nvee_sdk.detectedactivity.DetectedActivityReceiver"/>
<!-- <receiver-->
<!-- android:name="com.rchan.nvee_sdk.detectedactivity.DetectedActivityReceiver"-->
<!-- android:exported="false"-->
<!-- android:process=":remote"-->
<!-- android:permission="com.google.android.gms.permission.ACTIVITY_RECOGNITION">-->
<!-- <intent-filter>-->
<!-- <action android:name="action.TRANSITIONS_DATA" />-->
<!-- </intent-filter>-->
<!-- </receiver>-->
</application>
</manifest>
In my client, I have this in my fragment:
private fun connectToRemoteService() {
val intent = Intent("nveeaidle")
val pack = "com.rchan.nveeapplication"
pack?.let {
intent.setPackage(pack)
activity?.applicationContext?.bindService(
intent, this, Context.BIND_AUTO_CREATE
)
}
}
I am not sure what is causing this warning, and I have tried out different solutions after searching on stackoverflow and google.
How do I test is:
Launch my server application
Launch my client application
I see the warning
Thank you for taking the time to read my question.
After recent changes, You can use <queries> <package android:name ="your package name" /> </queries>
https://developer.android.com/training/package-visibility/declaring
I did more searching and finally found the answer... All credits go to the SO answer here:
https://stackoverflow.com/a/55712326/3718584
TLDR:
Had to change the intent from implicit to explicit due to API 21
intent.setClassName("com.rchan.nveeapplication","com.rchan.nvee_sdk.detectedactivity.DetectedActivityService")
I'm not able to subscribe to push notifications. I did:
1) I created a firebase application, with the same package name as my MainActivity package name;
2) I downloaded the google-service.json file and stored it in my /app/ next to the gradle file;
3) I added the C2D and WAKE-LOCK permissions as the google guide showed;
4) I added the API-KEY in the pushnotification's setting tab in quickblox admin panel;
5) I modified the manifest as showed by the quickblox guide;
6) I added a push-notification listener and a local broadcast receiver as shown by the same guide as above.
That's how my manifest looks like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.unical.sistemidistribuiti.ddf.appraia">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<permission android:name="it.unical.sistemidistribuiti.ddf.appraia.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="it.unical.sistemidistribuiti.ddf.appraia.permission.C2D_MESSAGE"/>
<meta-data android:name="com.quickblox.messages.TYPE" android:value="FCM" />
<meta-data android:name="com.quickblox.messages.SENDER_ID" android:value="#string/sender_id" />
<meta-data android:name="com.quickblox.messages.QB_ENVIRONMENT" android:value="DEVELOPMENT" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:largeHeap="true"
android:theme="#style/AppTheme"
android:name="it.unical.sistemidistribuiti.ddf.appraia.AppraiaApplication">
<activity
android:name="it.unical.sistemidistribuiti.ddf.appraia.StartActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="it.unical.sistemidistribuiti.ddf.appraia.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
<activity
android:name="it.unical.sistemidistribuiti.ddf.appraia.NewsDetailActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
<activity
android:name="it.unical.sistemidistribuiti.ddf.appraia.CreatePostActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
<activity
android:name="it.unical.sistemidistribuiti.ddf.appraia.UserProfileActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.gcm" />
</intent-filter>
</receiver>
<service
android:name="com.quickblox.messages.services.fcm.QBFcmPushListenerService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
Since I'm using 3.2 sdk version, the app should automatically subscribe the user to push-notifications, but this not happen. Actually the listener code prints nothing:
//This is in AppraiaApplication extends Application
#Override
public void onCreate() {
super.onCreate();
QBSettings.getInstance().init(getApplicationContext(), APP_ID, AUTH_KEY, AUTH_SECRET);
QBSettings.getInstance().setAccountKey(ACCOUNT_KEY);
QBPushManager.getInstance().addListener(new QBPushManager.QBSubscribeListener() {
#Override
public void onSubscriptionCreated() {
System.out.println("onSubscriptionCreated");
}
#Override
public void onSubscriptionError(final Exception e, int resultCode) {
System.out.println("onSubscriptionError" + e);
if (resultCode >= 0) {
System.out.println("Google play service exception");
}
System.out.println("onSubscriptionError " + e.getMessage());
}
});
QBSettings.getInstance().setEnablePushNotification(true);
LocalBroadcastManager.getInstance(this).registerReceiver(pushBroadcastReceiver,
new IntentFilter("new-push-event"));
System.out.println("Application creation ended");
}
What am I doing wrong?
Looks like you don't make signIn with user, and subscription is not performed. Also have a look in logs, there is can be info something like D/QBASDK: SubscribeService: SubscribeService created. So, you can figure out whether the subscription is executed at all.
I try to show a simple toast message on phone startup.
I wasted almost a day trying to figure out why my code did not work.
Here is the full error:
Unable to instantiate receiver com.debug.receivebootcomplete.debug.BroadcastReceiverClass: java.lang.ClassNotFoundException: com.debug.receivebootcomplete.debug.BroadcastReceiverClass
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.debug.receivebootcomplete.debug">
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:allowBackup="true" android:icon="#mipmap/icon" android:label="#string/app_name">
<receiver android:name=".BroadcastReceiverClass" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
And my class:
namespace Debug
{
class BroadcastReceiverClass:BroadcastReceiver
{
public override void OnReceive (Context context, Intent intent)
{
Toast.MakeText (context,"Work",ToastLength.Short).Show ();
}
}
}
In emulator debug the application throw the java.lang.ClassNotFoundException and on phone when reboot the application crash.
Thank you in advance!
Thanks #Talha!
My error was generated by the intent-filter tag. I have no idea why because in every topic that I saw everybody used that tag in Manifest file.
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
So I remove it and add
[BroadcastReceiver]
[IntentFilter(new[] {Intent.ActionBootCompleted})]
to the BroadcastReceiver class.
I have BroadcastReceiver which listens for ACTION_SHUTDOWN and some other actions.
My problem is, when I shutdown my android device(2.3.6) BroadcastReceiver is catching ACTION_SHUTDOWN two times. Problem is only with ACTION_SHUTDOWN and not with other actions.
When I run same code on emulator, it works fine.
Guys please help me. Here is my code:
my BootReceiver.java
public class BootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if(Intent.ACTION_SHUTDOWN.equalsIgnoreCase(intent.getAction())) {
Log.i("Boot Receiver - Shutdown event");
// database operation
}
if(Intent.ACTION_BOOT_COMPLETED.equalsIgnoreCase(intent.getAction())) {
// some operation
}
if(Intent.ACTION_AIRPLANE_MODE_CHANGED
.equalsIgnoreCase(intent.getAction().intern())) {
// some operation
}
if(ConnectivityManager.CONNECTIVITY_ACTION
.equalsIgnoreCase(intent.getAction())) {
// some operation
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xyz.ui"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/spota"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name="com.xyz.UserActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.xyz.BootReceiver">
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.intent.action.BATTERY_CHANGED" />
<action android:name="android.intent.action.AIRPLANE_MODE"/>
</intent-filter>
</receiver>
</application>
And here is the Logcat entries
05-03 16:37:23.826: I/xyz(2337): Boot Receiver - Shutdown event
05-03 16:37:23.881: I/xyz(2337): Inserting Data
05-03 16:37:28.514: I/xyz(2337): Boot Receiver - Shutdown event
05-03 16:37:28.529: I/xyz(2337): Inserting Data
Thanks!
you can add a flag to avoid this.
once you received this intent, set the flag.
if(flag)
{
do sth.
flag =0 ;
}
else
{
ignore.
}
I really do not know what is wrong, but my if widget is update by system by "APPWIDGET_UPDATE" it throws following exception. I tried several things, exporting receiver (true/false), I tried it on emulators and real phones, but it is same. I added several intent-filters, but it did not work.
11-06 20:10:10.279: W/ActivityManager(61): Permission denied: checkComponentPermission() reqUid=1000
11-06 20:10:10.279: W/ActivityManager(61): Permission Denial: broadcasting Intent { act=android.appwidget.action.APPWIDGET_UPDATE (has extras) } from com.ency.easychange (pid=1196, uid=10034) requires null due to receiver com.android.settings/com.android.settings.widget.SettingsAppWidgetProvider
My AppWidgetProvider is only declared, because I tried to eliminate possibilities, but the exception is throw before ExchangeRateWidgetProvider.onReceive() is called.
public class ExchangeRateWidgetProvider extends AppWidgetProvider {
public static final String tag = "ExchangeRateWidgetProvider";
#Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
}
}
My Manifest:
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<!-- TODO: Remove, only for traces -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="#drawable/ic_launcher_main"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".EasyChange"
android:label="#string/title_activity_easy_change" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".ExchangeRateWidgetService"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
</intent-filter>
</service>
<receiver
android:name=".ExchangeRateWidgetProvider"
android:label="#string/exchange_rate_widget_name"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/exchange_rate_widget_providerinfo" />
</receiver>
<activity
android:name=".WidgetConfigSmall"
android:label="#string/title_activity_widget_config_small"
android:theme="#android:style/Theme.Holo.Dialog"
android:excludeFromRecents="true"
android:exported="true" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
</activity>
</application>
I appreciate if you can take a look ...
Your problem lies somewhere in your Java code, where you are attempting to send the android.appwidget.action.APPWIDGET_UPDATE broadcast. That is to be broadcast by the OS, not by apps, and that is what the Permission Denial is about.