android.intent.action.CAMERA_BUTTON not broadcasting on Desire Z (Froyo)? - camera

I have hard time intercepting HW camera button on Desire Z (Froyo). I wrote a sample that runs fine on G1 (1.6) but not on aforementioned phone.
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.company" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".CameraReceiverTestActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:enabled="true" android:exported="true"
android:name=".CameraButtonReceiver">
<intent-filter android:priority="999">
<action android:name="android.intent.action.CAMERA_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
And CameraButtonReceiver.java
package net.company;
public class CameraButtonReceiver extends BroadcastReceiver {
static {
Log.w("CBR", "onReceive clazz init");
}
#Override
public void onReceive(Context context, Intent intent) {
Log.w("CBR", "onReceive camera");
abortBroadcast();
}
}
On G1 (1.6) I see both messages as soon as press the camera button and default camera app is suppressed. However, on Desire Z (Froyo) no such thing happens. After playing with priority, code/xml declarations I dare to say this phone sends this broadcast with some other name.

There is no requirement for a device manufacturer to send any broadcast when the CAMERA button is clicked, from my reading of the Compatibility Definition Document. It might only be used by the foreground activity on the Desire Z. I don't have a Z and so cannot confirm your tests.
Since the vast majority of Android devices do not have a CAMERA button at all, you will need to ensure that your app works well without such a button, and that you advise users that the CAMERA button may or may not work with your app depending upon device.

Related

Not able to run when injecting dependencies with Hilt into Android Classes

I'm in the process of making an application using Hilt. But my question is, am I only able to run my app through AndroidManifest.xml? I'd like to run it through another class, but it keeps giving me a blank page.
My Classes:
Application class using #HiltAndroidApp
#HiltAndroidApp
class ExampleApplication : Application()
Activity class using #AndroidEntryPoint
#AndroidEntryPoint
class ExampleActivity : ComponentActivity() {
#RequiresApi(Build.VERSION_CODES.N)
override fun onCreate(instance: Bundle?) {
super.onCreate(instance)
setContent {
AppTheme {
Surface() {
......
Manifest.xml
(This is the only way I can run the class, ExampleActivity).
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:name=".ui.ExampleApplication"
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.App"
tools:targetApi="31">
<activity
android:name=".ExampleActivity"
android:exported="true"
android:label="#string/app_name"
android:theme="#style/Theme.App">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
So, I've tried calling my application from another class, but I can't call ExampleActivity.kt alone, so I tried calling two classes, but it keeps giving me a blank page.
Here's what I've tried:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AppTheme {
ExampleApplication()
ExampleActivity()
}
}
}
}
It gives a blank screen.
I will create another class and make it my start class, where I will then call ExampleApplication and ExampleActivity.
How am I supposed to call two classes using Hilt dependencies from another class?
Of course, I have updated the manifest.xml so that it says .MainActivity.
First of all, why do you need Hilt? What are you trying to Inject and where?
ExampleApplication() is just a place where you configure app-wide settings, you are never supposed to call it from somewhere else, so you don't need that line.
Furthermore, Which activity are you trying to start? MainActivity or ExampleActivity()? Calling ExampleActivity within MainActivity won't have any effect.
SetContent { ... } is the place where you create the UI.
If you want to open another activity from MainActivity then you need to implement navigation or use Intents.

How to add an service accessibility Android that registre Alert Dialog

I would Like to listen to Alert Dialog, and i have adding an exemple but it dont work, and i cant follow the starting and capturing the event like Key Up ..etc by using Log.d.
I confirm that the Accessibility Service has Enabled, but i would like to to assure that is executing
here is my code
public class MyService extends AccessibilityService {
public static String TAG = "USD";
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Log.i(TAG, "onAccessibilityEvent: gettting");
String text = event.getText().toString();
if (event.getClassName().equals("android.app.AlertDialog")) {
Log.i(TAG, " Getting USSD"+text);
Toast.makeText(this, text, Toast.LENGTH_LONG).show();
}
}
and the Manifest code
<service android:name=".MyService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
android:label=""
android:exported="false">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="#xml/accessibility_service_config" />
</service>
and the config XML
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:packageNames="com.android.phone"
android:accessibilityEventTypes="typeWindowStateChanged|typeWindowContentChanged"
android:accessibilityFlags="flagDefault"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="0"
android:canRetrieveWindowContent="true"
android:canRequestFilterKeyEvents="true"
android:settingsActivity="com.example.android.accessibility.ServiceSettingsActivity"
/>

Trouble opening BranchIo deep links on Android with react navigation

I've been trying to integrate Branch into my React Native project. I can successfully create Branch Universal Object. When I click on it, it opens the app, but the only params that the branch listener picks up are:
{"+clicked_branch_link": false, "+is_first_session": false}
Here is the relevant portion of the AndroidManifest.xml:
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="branchfoodisgood" android:host="open" />
<data android:scheme="https" android:host="fig.app.link" />
<data android:scheme="http" android:host="fig.app.link" />
<data android:scheme="https" android:host="fig.test-app.link" />
<data android:scheme="http" android:host="fig.test-app.link" />
</intent-filter>
These links open on iOS with the correct data.
Interestingly when the app is no open, the link works, but when it is previously opened it does not recognize the link.
In order to work around this - I had to modify the code from the react-native branch docs.
// Override onNewIntent for Branch.io
#Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
/**
* Issue: The documentation provided
* (https://help.branch.io/developers-hub/docs/react-native#android) was said to
* include the followign lines:
*
* if (intent != null &&
* intent.hasExtra("branch_force_new_session") &&
* intent.getBooleanExtra("branch_force_new_session", false))
* {
* RNBranchModule.onNewIntent(intent);
* }
*
* But this was causing an issue with opening the PDP from a deep link when the
* session was already in progress
* So I remove that code and always force a new branch seesion when a link is
* opened
*
* See issue here:
* https://github.com/BranchMetrics/react-native-branch-deep-linking-attribution/issues/707
*
*/
RNBranchModule.onNewIntent(intent);
}
There is a corresponding issue here discussing this with the maintainers.

Foreground Service Not Updating Sensors Data In Background

I am new in Android Development, I've created an application with API version 29 using Kotlin. My main activity is launching a Foreground Service which is doing the following tasks.
Getting Location using the FusedLocationProviderClient.
Getting Sensor Data (Accelerometer and Gyroscope)
Showing the above information in a Notification
The application is supposed to get the Location and Sensors information in the background and update the Notification.
The Application is currently updating the Sensors and Location data when the Main Activity application is running. Once the Main Activity is closed, the Location data gets updated in the Notification but the Sensor data is not being updated. I've read some QnA sessions (including this) but I'm unable to figure out the issue.
Code To Launch Service:
val serviceIntent = Intent(this, MyBackgroundService::class.java);
serviceIntent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
startForegroundService(serviceIntent);
Permissions & Features in Manifest:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
<uses-feature android:name="android.hardware.sensor.gyroscope" android:required="true" />
Foreground Service in Manifest:
<service android:name=".MyBackgroundService"
android:enabled="true"
android:exported="true"
android:foregroundServiceType="location"
android:icon="#drawable/logo"
android:process=":MyBackgroundServiceProcess"/>
I am wondering if there is any foregroundServiceType to continuously get the Sensor values when the Main Activity is closed.

How Can I Use BroadcastReceiver on API 26 and Higher?

I'm developing an Android App. Users can chat each other. I fetch the messages on PushReceiver class. App opened or closed I mean foreground or background; the code block working from API 19 to API 26 but not working higher than API 26. I try to debug onReceive function but it's not call on Android O.
I want to say again. My code block working API 25 and lower versions.
I'm using pushy.me service.
My BroadcastReceiver Class:
public class PushReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String notificationTitle = "Title";
String notificationText = "Text";
Bundle bundle = intent.getExtras();
JSONObject jsonObject = new JSONObject();
for (String key : bundle.keySet()) {
try {
jsonObject.put(key, wrap(bundle.get(key)));
} catch (Exception e) {
e.printStackTrace();
}
}
try {
notificationText = jsonObject.get("body").toString();
notificationTitle = jsonObject.get("title").toString();
} catch (Exception e) {}
// Prepare a notification with vibration, sound and lights
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setAutoCancel(true)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle(notificationTitle)
.setContentText(notificationText)
.setLights(Color.RED, 1000, 1000)
.setVibrate(new long[]{0, 400, 250, 400})
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));
// Automatically configure a Notification Channel for devices running Android O+
Pushy.setNotificationChannel(builder, context);
// Get an instance of the NotificationManager service
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
// Build the notification and display it
notificationManager.notify(1, builder.build());
}
}
My Manifest:
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
...
<receiver
android:name=".Notification.PushReceiver"
android:exported="false">
<intent-filter>
<!-- Do not modify this -->
<action android:name="pushy.me" />
</intent-filter>
</receiver> <!-- Pushy Update Receiver -->
<!-- Do not modify - internal BroadcastReceiver that restarts the listener service -->
<receiver
android:name="me.pushy.sdk.receivers.PushyUpdateReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver> <!-- Pushy Boot Receiver -->
<!-- Do not modify - internal BroadcastReceiver that restarts the listener service -->
<receiver
android:name="me.pushy.sdk.receivers.PushyBootReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver> <!-- Pushy Socket Service -->
<!-- Do not modify - internal service -->
<service android:name="me.pushy.sdk.services.PushySocketService" /> <!-- Pushy Job Service (added in Pushy SDK 1.0.35) -->
<!-- Do not modify - internal service -->
<service
android:name="me.pushy.sdk.services.PushyJobService"
android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" />
Edit: pushy.me Android Demo here
The latest Pushy Android SDK has added support for Android O power saving optimizations (App Standby / deprecation of Service), please update by following the instructions on this page:
https://pushy.me/docs/android/get-sdk
Also, make sure to add the following new JobService declaration to your AndroidManifest.xml, under the <application> tag:
<!-- Pushy Job Service (added in Pushy SDK 1.0.35) -->
<!-- Do not modify - internal service -->
<service android:name="me.pushy.sdk.services.PushyJobService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true" />