i created an app that always start a service once the device has completed booting.
This is the Manifest code..
<receiver>
android:name="StartMyServiceAtBootReceiver"
android:directBootAware ="true"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
<action android:name="android.intent.action.REBOOT"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
The service always start in some devices once boot is completed but in my own device which is running android 7.0, the boot completed service doesn't start unless i convert the app to system app using root access. Can someone tell me how to make the app to start the service on boot completed without converting it to a system app?
First of All
receiver android:name="StartMyServiceAtBootReceiver"
Your path to Receiver should written over here for example:
<receiver android:name=".receiver.BootReceiver">
first dot suggest your path till root of the package.
Create a BroadcastReceiver and register it to receive ACTION_BOOT_COMPLETED. You also need RECEIVE_BOOT_COMPLETED permission.
Read: Listening For and Broadcasting Global Messages , and Setting Alarms
Try into manifest
<receiver
android:name=".AutoStart"
android:enabled="true"
android:exported="true" >
<intent-filter android:priority="500" >
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Make sure also to include the completed boot permission.
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Also read this answer carefully
Related
When using App Links, the receiver app (EX. Whatsapp) is paused, and your application's activity is opened on top of the receiver app.
For example, if you open your link from a WhatsApp's chat page, the new activity isn't opened from your app (The WhatsApp's task in recent apps includes your app), while your app isn't in the recent task.
But what if I want to open my application in a new task? Separate from the receiver app?
This is my Manifest file of the activity opened from the App Link:
<activity
android:name=".Activitys.MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter
android:autoVerify="true"
android:label="#string/app_name">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="eventtk.uae-dc.com"
android:pathPrefix="/product/"
android:scheme="https" />
</intent-filter>
</activity>
Is there a thing I should add to the IntentFilter?
Not sure if I understood correctly what you would like to achieve, but you can try
to add
android:launchMode="singleTask"
to your activity definition.
More information here:
https://inthecheesefactory.com/blog/understand-android-activity-launchmode/en
I am trying to stop the app I am working on from asking for USB permissions each time the USB device is disconnected. I have followed: USB device access pop-up suppression? without much luck.
The app does remember the USB device until the device is unplugged.
If it matters I am trying to connect the app to an Arduino Teensy.
This is what my manifest activity looks like
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter> <!-- For receiving data from another application -->
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="#xml/usb_device_filter" />
</activity>
</application>
And here is my usb_device_filter file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="--hidden--" product-id="--hidden--" />
</resources>
Any help is welcome.
EDIT: I also look over at the Android Developer page and they say when using an intent filter for USB connections: If users accept, your application automatically has permission to access the device until the device is disconnected.
I would also like to point out that the suggested duplicate does not have the same issue as I am trying to solve. Their problem is having two activities while my problem deals with just one.
https://developer.android.com/guide/topics/connectivity/usb/host
We ended up opening the app automatically when the USB is inserted into the phone, because our project deals with the app being open all day.
The app only asks for permission to use the USB once for the phone and remembers it now, as long as the user connects the USB before opening the app and the phone is unlocked. The phone even remembers the permission after the phone is restarted.
This is kind of a work around, but it works for our needs. Hopefully this will help some others with the same problem.
As the asker here says, For your perpose (if I understood correctly) the following should be enough. That's right that he had a different problem but he started hes question saying that for your case it's working.
<activity android:name=".FirstActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="#xml/usb_device_filter" />
</activity>
I am not able to receive push notifications at all. onPushReceieved method in my receiver class is never called.
Here's what my manifest looks like:
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:protectionLevel="signature"
android:name="com.compName.appName.permission.C2D_MESSAGE" />
<uses-permission android:name="com.compName.appName.permission.C2D_MESSAGE" />
<application>
.
.
<service android:name="com.parse.PushService" />
<receiver android:name="com.compName.appName.helpers.MyParsePushReciever"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.compName.appName" />
</intent-filter>
</receiver>
</application
This is the init methods for Parse in my Applications onCreate Method:
Parse.initialize(this, app_id, client_id);
PushService.startServiceIfRequired(this);
ParseInstallation.getCurrentInstallation().saveInBackground();
Here is my Receiver class's onPushReceived method:
#Override
protected void onPushReceive(Context context, Intent intent) {
Log.i("hereeeeeeeeee === ", "on push recieve");
}
I am never able to see that Log. OnPushReceive never gets called. Is there something I am missing?
Check your manifest and gradle file, I think the package names are wrong.
I heard about parse.com is going to be off forever
and yes its down officially.
http://parse.com/
EDIT
As parse announced their shutdown recently, GCM is the only best option though it won’t comes with an admin interface.
You can follow this awesome tutorial for this.
http://www.androidhive.info/2016/02/android-push-notifications-using-gcm-php-mysql-realtime-chat-app-part-1/
I figured it out.
I had changed my package a long time ago. I had made changes to my manifest, but not in my gradle file.
Shout out to Taylor Courtney for continuing in helping me figure it out. He's the real MVP.
I want to handle received sms that contains network configurations(OMA OTA). I have already developed android application that catches typical sms from inbox. Network configuration is not a typical sms. How can I get it? What is a Broadcast Action for that?
I was trying this:
<receiver android:name="ru.tenet.pdureceiver.SMSReceiver" >
<intent-filter android:priority="1" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
As I understood, android.provider.Telephony.SMS_RECEIVED is not enough.
Well, I've found a solution. The action is:
android.provider.Telephony.WAP_PUSH_RECEIVED
And also there must be a mimeType defined for wap message.
For example:
<intent-filter android:priority="1" >
<action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />
<data android:mimeType="application/vnd.wap.connectivity-wbxml" />
</intent-filter>
How can I read NFC tag in background via service? I already can read it in activity(I've found some source codes but I don't really understand how it works) but I can't find anything about reading it in Service or Runnable.
Thanks for help
Finally i figured out how to solve it. I have to use these intent filters in AndroidManifest.xml to properly run my activity.
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>