Creating an Android Lock Screen App. - java

How to create a lock-screen app that acts as a lock for android mobile. I did find one, But it was poorly constructed code wise and if I pressed the physical home key, it unlocked, making the application pointless.
I did come across a forum stating some method of blocking home button functionality was removed in Android 4.x
Yet, I have an awesome idea for a lock-screen but no ground to get started. If anyone has any knowledge on the subject, I'd love to hear it.
Thanks all :-)

Yes, it is possible. This is a simple lock screen Source Code from GitHub
Creating an app that works like a lock is no big deal but as you said for Home key issue, I would suggest you go on and develop the App as much as you need and the only final area you would get stuck is the home key control so, try to find some tricky way to get the control of home key and make it as an app launcher for your lock app. It is not very complicated but kinda tricky though. I will post you, if I can find any Home-key access source codes
PS:
Here is the tutorial for accessing Home Key
I found the home key override somewhere. Add these lines in the App Manifest.
Following two lines will do the magic
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
and override this method in your activity
#Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
}
#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;
}
Keep in mind that I didn't test these codes or methods, just tried to help you (you might find some drawbacks).
PS: based on the votes I can guarantee that my suggestion is working and you can develop such app with the above help :)

Related

How understand, what link from webview is YouTube link, to open it in YouTube app?lication

I want, when user click on web view link,it's open YouTube app. How i can parse this link,i.e what algorithm should i use,to know,whether it link on youtube video (exact video, not channel or simple YouTube site). Because you can have,for example youtube.com,or youtu.be,so it not so obvious solution of this problem. Probably i should use regex,but i am not sure, what it right way. May be somebody decompile youtube app and asee sources of this app to know,how it understand,what it correct youtube video link. Thanks everybody for any help.
Read about Deeplinks. They are declared on your apps Manifest and they can intercept any kind of links, hosts or URL schemas.
<intent-filter>
...
<data android:scheme="https" android:host="www.youtube.com" />
<data android:scheme="app" android:host="open.my.app" />
</intent-filter>
Official documentation
If you need to intercept links in your WebView then you can add some logic in your shouldOverrideUrlLoading:
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Uri uri = Uri.parse(url);
if(url.equals("www.youtube.com/xxxx")) {
launchYoutubeApp(url) ;
return true;
}
if(uri.getHost().contains("youtube")) {
view.loadUrl(url);
return true;
}
//add here any condition you need in order of preference
return false;
}

Dynamic API KEY for Google Maps on Android

We are developing an Android application that uses google maps.
Right now, for development purposes, we're using the key like this:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
And
<string name="google_maps_key">KEY_HERE</string>
For deploying purposes, we will implement a "Bring Your Own Key" approach where each client that buys the product, also put his key to be used.
I know it's weird and somewhat unnecessary, but it is a process from a big company and this decision comes from "the top".
Is there any way that we can have dynamic keys? Like putting a key into a service and consuming it in the app or something like that?
Appreciate any help.
This is not possible in Google API V2 according to the documentation
the API key has to be assigned using the Manifest file.
https://developers.google.com/maps/documentation/android/start#adding_the_api_key_to_your_application
But its possible for MapView.
If you are instantiating a MapView directly from the code, you should pass the Maps API Key in the MapView constructor.
Code:
#Override
protected void onCreate(.....) {
super.onCreate(....);
mMapView = new MapView(this, YOUR_MAP_API_KEY); //pass key to MapView Constructor here
setContentView(mMapView);
// ....
}

TextRecognizer.isOperational() API always returns false

This question has been asked severally and only suggestions are made. Ill comprehend every suggestion hopefully.
the dependency is defined in the manifest
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<meta-data
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="ocr" />
and added on the app level
compile 'com.google.android.gms:play-services-vision:9.8.0'
The test device has sufficient storage which is greater than 10% of the internal and also has a very good internet connection. Permissions are also clearly defined
We start the TextRecognizer to detect text and we get our null response:
TextRecognizer textRecognizer = new TextRecognizer.Builder(getContext()).build();
if (!textRecognizer.isOperational()) {
Log.w("Main Activity", "Dependencies are not yet available");
Toast.makeText(getContext(), "Cannot Detect", Toast.LENGTH_LONG).show();
if(((MainActivity) getActivity()).hasLowStorage()) {
Toast.makeText(getContext(), "Low Storage", Toast.LENGTH_LONG).show();
Log.w("Custom_Storage", "Low Storage");
}
}
Most suggestions are to use a lower dependency compile 'com.google.android.gms:play-services:7.8+' but it doesn't work for everyone. After publishing the app, some users cant use the app.
The suggestions are not solving the problem.
Similar questions:
TextRecognizer isOperational API always returns false and
detector.isOperational() always false on android
TextRecognizer API is required to download few dependency files. Usually it is done at the time of installation but sometimes it take longer time. App will automatically download those files. Wait some time to download those files. Until download is complete TextRecognizer.isOperational will return false. After the doanlowd is completed TextRecognizer.isOperational will return true.
Even I had the same problem. I just created a new project and copied and installed dll again. Now it is working.

AccessibilityEvent.getPackageName() returns null

I am registering an AccessibilityService to listen for app changes. It works on all the phones I've tested but on the Galaxy A3 with Android 5.0 is failing because AccessibilityEvent.getPackageName() is returning null. The packageName should be set, as it is a regular app, downloaded from Google play, being interacted with.
Does anyone know why is this and how to fix it?
Below the relevant parts of my code.
<service
android:name=".presentation.view.services.LockService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<meta-data
android:name="android.accessibilityservice"
android:resource="#xml/accessibility_service_config"/>
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService"/>
</intent-filter>
</service>
#Override
public void onServiceConnected() {
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
info.notificationTimeout = 100;
this.setServiceInfo(info);
}
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
event.getPackageName() // returns NULL;
}
As the documentation doesn't specifically explain this, I'll try to provide something that I've came up with after playing around with the AccessibilityService. I'm writing this just in case others are banging their heads because event.getPackageName() always returns null, but don't take my word for granted.
From the documentation of accessibility service, I see that you can set the attribute android:packageNames="#strings/blah_blah", where blah_blah is a comma separated list of package names that our service will observe.
In case we specify this attribute, we will get notified only for those specific packages and event.getPackageName() will return the proper package name.
If we leave this attribute unset or we specifically set this to null we will be notified of all events that occur, but we'll lose the ability to identify whichever specific package "generated" the accessibility event.
As this AccessibilityServiceInfo property can be dynamically set, you could in theory fetch a list of currently installed packages and set that as the packageNames that your service will monitor.
#Override
protected void onServiceConnected() {
super.onServiceConnected();
AccessibilityServiceInfo info = getServiceInfo();
// your other assignments
info.packageNames = new String[]{...};
setServiceInfo(info);
}

detector.isOperational() always false on android

I'm using the new google plays service: Barcode detector, for this porposue I'm following this tutorial : https://search-codelabs.appspot.com/codelabs/bar-codes
But when I run the application on my real device(Asus Nexus 7), the text view of the app always is showing me "Couldn't set up the detector" and i don't know how to make it work >< ...
Here some code for fast debugging:
public class DecoderBar extends Activity implements View.OnClickListener{
private TextView txt;
private ImageView img;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_decoder);
Button b = (Button) findViewById(R.id.button);
txt = (TextView) findViewById(R.id.txtContent);
img = (ImageView) findViewById(R.id.imgview);
b.setOnClickListener(this);
}
// [...]
#Override
public void onClick(View v) {
Bitmap myBitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.popi);
img.setImageBitmap(myBitmap);
BarcodeDetector detector = new BarcodeDetector.Builder(getApplicationContext())
.setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE)
.build();
if(!detector.isOperational()){
// Always show this message, so, never is operational!
txt.setText("Could not set up the detector!");
return;
}
Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
SparseArray<Barcode> barcodes = detector.detect(frame);
Barcode thisCode = barcodes.valueAt(0);
txt.setText(thisCode.rawValue);
}
}
It looks like the first time barcode detector is used on each device, some download is done by Google Play Services. Here is the link:
https://developers.google.com/vision/multi-tracker-tutorial
And this is the excerpt:
The first time that an app using barcode and/or face APIs is installed
on a device, GMS will download a libraries to the device in order to
do barcode and face detection. Usually this is done by the installer
before the app is run for the first time.
I had this problem now. You can't update the Google Play Services. After I used the same as on the tutorial it works.
compile 'com.google.android.gms:play-services:7.8+'
Here is what was my case.
I was using BarcodeDetector for decoding QR codes from imported images. On 4 my testing devices it was working fine. On one was not reading anything from bitmap. I thought this might be incompatibility with android 5.0 but this was not the case. After hours of investigation I finally noticed that detector.isOperational(); returns false. The reason was:
The first time that an app using barcode and/or face APIs is installed on a device, GMS will download a libraries to the device in order to do barcode and face detection. Usually this is done by the installer before the app is run for the first time.
I had wi-fi off on that testing device. After turning it on and relaunching app, detector became operational and started decoding bitmaps.
To use the API, it's necessary to have internet connection, I had connection to my ADSL but not resolved DNS. Fixing that problem make my app works
Sometimes detector dependencies are downloaded when the app runs for the first time and not when the app installs. I too faced the same issue, the problem is either your network connection is weak or you don't have enough storage for download say 10% of the total space though it does not take that much space but downloads from Google Play Services does require good amount of storage and don't forget to clear cache(Simple check try to update any application from playstore). Refer this Github thread for more information.
Check your storage! make sure it is over 10%
That fixed my problem, and I answered it here too...
https://stackoverflow.com/a/43229272/6914806
you must not forget this:
add this to your AndroidManifest.xml
<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">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="ocr"/>

Categories

Resources