I am working on an app In this, I have to send the current status of the android devices in 30-30 seconds through my app which I have done. But the problem I am facing is the app is not starting after boot complete this problem is related to some of android devices.
MY Code is:
public class BootCompletedReceiver extends BroadcastReceiver {
private static final String TAG = "BootCompletedReceiver";
#Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG,"action : "+intent.getAction());
if (Objects.requireNonNull(intent.getAction()).equals(Intent.ACTION_BOOT_COMPLETED)){
Log.d(TAG,"receive boot completes : "+intent.getAction());
#SuppressLint("StaticFieldLeak")
AsyncTask task = new AsyncTask() {
#Override
protected Object doInBackground(Object[] objects) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
#RequiresApi(api = Build.VERSION_CODES.O)
#Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
context.startForegroundService(new Intent(context, StatUpdateService.class));
}
};
task.execute();
}
}
}
Manifests file:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<......./>
<receiver
android:name=".receiver.BootCompletedReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
List item
On Some of the android devices, This Code is working and My app is starting after boot complete, but on the Some of the android devices, it's not working.
Android does not auto-start any application until you manually launch it at least once. After that, the applications will automatically start on each Android boot.
Add android.permission.RECEIVE_BOOT_COMPLETED permission in your manifest.
When Android finishes booting and is ready to start the home activity, the home event is sent and qualifying applications identify themselves as bootable candidates. The system sends out the android.intent.category.HOME and android.intent.category.DEFAULT intents when it's done initializing.
<?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.test.app">
<!-- add this -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:theme="#style/app_theme_red">
<!-- main -->
<activity
android:name=".ui.activity.MainActivity"
android:exported="true">
<!-- main filter -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<!-- add this -->
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- boot receiver -->
<receiver android:name=".BootReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
Related
We are not access share url from firebase using "https://firebase.google.com/docs/dynamic-links/android/receive"
FirebaseDynamicLinks.getInstance()
.getDynamicLink(getIntent())
.addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
#Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
// Get deep link from result (may be null if no link is found)
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
Log.e("deepLink",""+deepLink.toString());
}
// Handle the deep link. For example, open the linked
// content, or apply promotional credit to the user's
// account.
// ...
// ...
}
})
.addOnFailureListener(this, new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.w(TAG, "getDynamicLink:onFailure", e);
}
});
this method of firebase is allways return null in "onSuccess".
first you need to make sure you URI is formulated like
https://your_subdomain.page.link/?link=your_deep_link&apn=package_name[&amv=minimum_version][&afl=fallback_link]
method getDynamicLink returns null if a dynamic link is not previously captured or is in the Uri, the above link format is not necessarily to be like that but it should match to the intent filters you have previously defined.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".EntryChoiceActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".java.MainActivity"
android:exported="true">
<!-- [START link_intent_filter] -->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="link"
android:scheme="your_subdomain.page.link"/>
</intent-filter>
</activity>
</application>
</manifest>
also you should add query parameters to the link field in the firebase console, https://your_subdomain.page.link/?link=your_deep_link&apn=package_name[&amv=minimum_version][&afl=fallback_link] and deep link remain short https://your_subdomain.page.link/example now to reproduce an adb test for a intent filters like:
<activity
android:name=".ui.activities.MyActivity"
android:label="#string/title_activity"
android:screenOrientation="portrait">
<!-- ATTENTION: This intent was auto-generated. Follow instructions at
https://g.co/AppIndexing/AndroidStudio to publish your Android app deep links. -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- ATTENTION: This data URL was auto-generated. We recommend that you use the HTTP scheme.
TODO: Change the host or pathPrefix as necessary. -->
<data
android:host="link"
android:scheme="your_subdomain.page.link" />
</intent-filter>
</activity>
use:
adb shell am start -W -a android.intent.action.VIEW -d "your_subdomain.page.link://link?key=category_parent_id\&value=92\&title=test" com.app_name.android
Hope this help thanks.
I have an android project for first time installation.
It is related with my firm agreement pages. It comes after google agreement pages.
I tried some technics for doing it. For example,I set it as a system application. However, it is cleaned when backup and reset operation.
Does anybody know how to run it?
on AndroidManifest.xml
<application
android:theme="#android:style/Theme.NoTitleBar"
android:allowBackup="true"
android:icon="#drawable/launcher"
android:label="#string/appname" >
<activity
android:name="xxxagreement.MainActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter android:priority="3">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
on MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
protected void onResume() {
Intent i = new Intent();
i.setAction(AGREEGATE_STARTED);
sendBroadcast(i);
TextView t = (TextView)findViewById(R.id.textView1);
t.setSelected(true);
...
super.onResume();
}
Event Log prints:
Session 'app': Error Launching activity
Your application doesn't have any launcher activity. Replace these lines
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
with
<category android:name="android.intent.category.LAUNCHER" />
I configured Parse API in my app and everything works except push notifications. I tried to send them from the site but they don't arrive in app.
I did everything as written in documentation, but I'm not able to receive notification pushes.
I was able to receive one and when I pressed it app crashed. Now I tried to change something but even with reversing I cannot receive them anymore. How can I resolve my problem?
EDIT: Since some users may be interested, here's the parts of the code I used for push notifications:
Main Class (not MainActivity though):
public class InstantsApplication extends Application {
public void onCreate() {
super.onCreate();
// Hidden
Parse.initialize(this, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
}
}
AndroidManifest (permissions not here included, trust me I have put them):
<!-- PARSE -->
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</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" />
<!--
IMPORTANT: Change "com.parse.tutorials.pushnotifications" to match your app's package name.
-->
<!-- I have hidden package name root for this question -->
<category android:name="com.xxxxxxxx.instants" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.ParsePushBroadcastReceiver" 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>
</application>
I met this problem before, that because you use the newest Parse api.
There are just a few changes you need to make.
First, to fix the error directly caused by issuing the push from the Parse backend you need to declare a notification icon for the Parse push in your Manifest.
<meta-data android:name="com.parse.push.notification_icon"
android:resource="#drawable/ic_launcher"/>
use before the closing application-Tag.
Issuing another push from the backend now will give you a push notification as you expect. So far so good. Clicking the push will result in an app crash again. To fix this you need to remove the now deprecated call PushService.setDefaultPushCallback(...) and add your own Receiver class. I did this in the *.util package just as the following:
public class Receiver extends ParsePushBroadcastReceiver {
#Override
public void onPushOpen(Context context, Intent intent) {
Intent i = new Intent(context, MainActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
Next, change the default Parse receiver to the one just created: - Go to your Manifest file.
<receiver
android:name="your.package.name.utils.Receiver"
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>
I am working on a research project for my university. The app will never be put on the market and only used for research.
I have made a homescreen app by using the Google Homescreen sample code.
In there, I have made an activity that is a lockscreen.
While in there, the user should not be able to get out of the lock by pressing Home, Back, etc.
The Back-Button seems to be disabled, but the Home-Button is not.
I have tried several solutions from the internet and stackoverflow, which are all not working.
Here is the important code:
(Notice: Logcat shows "Button pressed: 4" for the Back-Button but nothing for the home button!)
In my Lock-Screen Activity:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.v(TAG, "BUTTON PRESSED: " + new Integer(keyCode).toString());
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
return true;
} else if ((keyCode == KeyEvent.KEYCODE_CALL)) {
return true;
}
else if ((keyCode == KeyEvent.KEYCODE_HOME)){
return true;
}
return super.onKeyDown(keyCode, event);
}
#Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
It seems like the onAttachedToWindow() Method is not working since Android Version 4.
How can I disable the homebutton?
EDIT: Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.home" >
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<permission android:name="android.permission.WRITE_SECURE_SETTINGS" >
</permission>
<application
android:icon="#drawable/ic_launcher_home"
android:label="#string/home_title" >
<service android:name=".MyService" >
</service>
<activity
android:name="Home"
android:launchMode="singleInstance"
android:stateNotNeeded="true"
android:theme="#style/Theme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<receiver android:name=".ScreenReceiver" >
<intent-filter>
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.SCREEN_OFF" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
</activity>
<activity
android:name="Wallpaper"
android:icon="#drawable/bg_android_icon"
android:label="Wallpaper" >
<intent-filter>
<action android:name="android.intent.action.SET_WALLPAPER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".LockPage" >
<intent-filter>
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.SCREEN_OFF" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.MAIN" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
</intent-filter>
</activity>
</application>
</manifest>
This may come a bit late, I have been on a somewhat similar situation. My problem was that I didn't want users to leave the call screen during phone calls but I couldn't prevent it, so instead I simply brought it back front every time they left it.
In your case you could simply bring your app back to front on pause:
#Override
protected void onPause() {
super.onPause();
// Close and reopen app or bringToFront()
}
So leaving would automatically open the app again. You should try either reopening your activity or bringing it to front and see what works best. Reopening may be unnoticeable if you remove all animations and add FLAG_ACTIVITY_NO_ANIMATION.
It seems like the Home Button press is not forwarded to the app in a homescreen application.
Therefore I made a normal app, put my broadcastReceiver and my service in and now I can disable the homebutton and the backbutton.
Still the recent Apps button can be used to jump out of my lockscreen. You can flood it with dummy entries which might work.
Hope that helps someone!
#Override
public void onAttachedToWindow()
{
super.onAttachedToWindow();
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
}
And now handle the key event like this,
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_HOME)
{
Log.i("Home Button","Clicked");
}
if(keyCode==KeyEvent.KEYCODE_BACK)
{
finish();
}
return false;
}
This is not possible without changing the Android source: [Mentioned here][1].
Also this would break the Android Activity Cycle, which is not recommended.
this code works in my application
#Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
I am trying to make my app print something to log when screen is turned on but it doesn't work as I expected.
Here is what I have in my Manifest file
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity ...>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="PhoneBroadcastReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.SCREEN_ON"></action>
</intent-filter>
</receiver>
</application>
and my receiver looks like
public class PhoneBroadcastReceiver extends BroadcastReceiver {
public PhoneBroadcastReceiver()
{
}
#Override
public void onReceive(Context _context, Intent _intent) {
// TODO Auto-generated method stub
String a = _intent.getAction();
MessageHandler.log("Received action: " + a); // just a wrapper for printing to a log
}
}
but it prints nothing to the log. I keep pressing my Android power button and the screen turns on / turns off but my message doesn't appear in the log. What am I missing? It looks the same as in examples I found on the web.
You cannot listen for ACTION_SCREEN_ON broadcasts via a BroadcastReceiver registered in the manifest. You have to register it via registerReceiver() from a running component. There are fairly few broadcasts with this trait (ACTION_SCREEN_OFF, ACTION_BATTERY_CHANGED, and perhaps ACTION_USER_PRESENT).
ACTION_SCREEN_ON won't work if registered via manifest file. You need to register it dynamically.
maybe you forget to register the service on
<application> tag:
<service android:name=".YourService" />