Android lock screen : activity started first when mobile on - android

I develop one apps mobile number lock, i want whenever mobile on,or restart or switch on ,or on from the top/left/right button placed on mobile in short whenever mobile screen on my lock activity call, i have no idea to how to call activity at time of mobile on please any one give some related example to start activity at first when mobile on. so my lock dispay to user and then enter number password and lock open ...thanks in advance..

Following is working for me :
enter code here :
public class BootReciever extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null) {
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
Intent s = new Intent(context,ViewPagerMainActivity.class);
s.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(s);
}
}
}
}
and in menifist file add follwing:
enter code here :
<receiver android:name=".BootReciever">
<intent-filter android:enabled="true" android:exported="true">
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>

There are multiple ways, to achieve this. One way is you can go through Broadcasting a message for your app, after the boot of your mobile. Try reading:
http://developer.android.com/reference/android/content/BroadcastReceiver.html
Also have look at this thread, this will solve your problem.
How to launch activity on BroadcastReceiver when boot complete on Android

Related

Android Hidden App start from dialer

We can hide the android app from launcher by editing manifest XML,but is there any code snippet or example by which we can hide the app and start it by entering some code like ##4444## like that.Any way to do this??
Thanks in advance.
To start your app from dialer you need to do three things:
1. Add receiver to your AdroidManifest.xml
<receiver android:name="com.example.HiddedReceiver">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
2. Create BroadcastReceiver as stated in xml. It will intercept EVERY calls number. You just need to scan it for your string and do apropiate action - in this case fire off an intent.
public class HiddenReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(android.intent.action.NEW_OUTGOING_CALL)) {
String resultData = getResultData();
if (resultData != null) {
if (resultData.contains("YOURCODE")) {
setResultData(null); // it wont continue calling that number
//HERE CREATE your intent
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
}
}
}
3. To get this working, you need to tell android you will be using this feature, and to grant permission to process calls from the user at install time.
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
i didnt test it, but this one works like a charm:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

How to lock uninstalling an application with a password? [duplicate]

First of all, I have researched a lot about my issue, but I could not find a proper solution so I am posting my query here. Hope to get a better solution to the issue:
I have a requirement where I need to ask for password to the user before user deletes my app from settings or from any other application like MyAppSharer. I have found one solution where I can successfully be able to call my activity when user clicks on Uninstall button. I have applied trick here, and calling service. In service, I run timer which runs every 1 second and in that one second, it checks for top most activity of running task. This is running perfectly as per expected.
Now, my issue is, this activity apppears on each of application user tries to uninstall. I need that the activity which I call, should only appear for my application when user tries to uninstall my application.
Here is my code:
public static final String PACKAGE_INSTALLER = "com.android.packageinstaller";
public static final String PACKAGE_INSTALLER_UNINSTALL_ACTIVITY = "com.android.packageinstaller.UninstallerActivity";
alarmTimer.scheduleAtFixedRate(new TimerTask() {
public void run() {
mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);;
ComponentName topActivity = mActivityManager.getRunningTasks(1).get(0).topActivity;
final String packageName = topActivity.getPackageName();
String className = topActivity.getClassName();
Log.v(TAG, "packageName:" + packageName);
Log.v(TAG, "className:" + className);
if (PACKAGE_INSTALLER.equals(packageName)
&& PACKAGE_INSTALLER_UNINSTALL_ACTIVITY.equals(className)) {
//Here I need to apply one condition where package name received to be matched with my package name. But I am not sure how to fetch package name of selected application for uninstalling
//To Cancel Existing UninstallerActivity and redirect user to home.
Intent homeIntent = new Intent();
homeIntent.setAction(Intent.ACTION_MAIN);
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
homeIntent.addCategory(Intent.CATEGORY_HOME);
startActivity(homeIntent);
//To open my activity
Intent loginActivity = new Intent(UninstallService.this, Act_Login.class);
loginActivity.putExtra(Constants.KEY_IS_FROM_SERVICE, true);
loginActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(loginActivity);
}
}
}, 0, 1000);
you should try something like the following :
1st - declare your broadcast recevier in the Manifest file , that will listen to QUERY_PACKAGE_RESTART :
<receiver android:name=".UninstallReceiver">
<intent-filter android:priority="999999">
<action android:name="android.intent.action.QUERY_PACKAGE_RESTART" />
<data android:scheme="package" />
</intent-filter>
</receiver>
2nd - your UnunstallIntentReceiver java class like the following :
public class UninstallReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
// fetching package names from extras
String[] packageNames = intent.getStringArrayExtra("android.intent.extra.PACKAGES");
if(packageNames!=null){
for(String packageName: packageNames){
if(packageName!=null && packageName.equals("application_package")){
// start your activity here and ask the user for the password
}
}
}
}
}
and please give me some feedback
Hope That Helps.
If this is a corporate requirement (if you want to block a regular user from uninstalling your app, no chance, thanks Google for protecting us from bad devs), you should create a device administrator application. This way, although the user still can delete the app, it's one extra step if you want to prevent accidental erasing.
Before deleting your app, if it's enabled as device admin, the user must first disable the app as administrator, and the app receives this broadcast.
In your XML, put
<activity android:name=".app.DeviceAdminSample"
android:label="#string/activity_sample_device_admin">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />
</intent-filter>
</activity>
<receiver android:name=".app.DeviceAdminSample$DeviceAdminSampleReceiver"
android:label="#string/sample_device_admin"
android:description="#string/sample_device_admin_description"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin"
android:resource="#xml/device_admin_sample" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
In the receiver, you have at least two methods worth noticing:
#Override
public CharSequence onDisableRequested(Context context, Intent intent) {
…
}
#Override
public void onDisabled(Context context, Intent intent) {
…
}
This way you know the user is potentially going to erase your app.
Complete guide for device administration is at https://developer.android.com/guide/topics/admin/device-admin.html
If you have root permissions make your app system (remove your apk-file from /data to /system directories). Then reboot device. After reboot your app is not available to delete by user (not superuser).
The only way i see, is to provide your own uninstaller as part of your app (= an activity that lists all apps and allows to uninstall them). Your service could then check if your app was the one that started the packageinstaller and if not redirect the user.
It is not possible (at least on the Android 4.4 I tested with) to grab the uninstaller activity data without root or being a system app. This is because the uninstaller is not called as an independent task, but as an activity on the stack of the starting task (which is the Settings app when uninstalling from settings, etc). You can only see the Task details of the calling task.
However there might be some really dirty possibility left, that i didn't test to the end: You could register the hidden interface IThumbnailReceiver [1] with the hidden three argument version of ActivityManager.getRunningTasks [2]. It seems like only the GET_TASKS permission is needed to grab a thumbnail (see [3]). It should be possible to find out which app is going to be removed from the app thumbnail... - But as this solution uses hidden APIs, there is no guarantee that it will work with older/newer/vendored Android versions.
https://github.com/omnirom/android_frameworks_base/blob/android-4.4/core/java/android/app/IThumbnailReceiver.aidl
https://github.com/omnirom/android_frameworks_base/blob/android-4.4/core/java/android/app/ActivityManager.java#L766
https://github.com/omnirom/android_frameworks_base/blob/android-4.4/services/java/com/android/server/am/ActivityManagerService.java#L6725

How do I access the user calls to mobile?

I want my application to be activated when the user make a specific call. Is there any way to take information which call is making by user in the same time ( not afterwords ) in order to activate the app at the right time ?
Ok i wrote this code for my case and it works:
public class OutgoingCallReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if(null == bundle) return;
String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
if( phonenumber.equals("11111111") ) {
Intent myactivity = new Intent(context, MyKeyboard.class);
myactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myactivity);
}
}
}
In the Manifest i add this:
<receiver
android:name=".OutgoingCallReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
I don't really know, but I think that's a really dangerous practice. It all depends on what you intend to do with your app. If it's a recording app, I think you can't even think of developping it, or don't post on the internet about it because it would be illegal in many countries. That's how I see and how I feel your question. About Android there is not 15k places to search, have a look at the android API.
http://developer.android.com/reference/android/provider/CallLog.Calls.html
This, for example, I don't know if it's a real time log, or if it's filled after the call is terminated. But you can search in that direction.

How I can receive hardware key events in sleep mode?

I'm writing an application that allows people in danger to call 911.
This is how it should work:
He (or she) feels danger.
He pushes the volume-down key three times.
My app calls 911.
But I'm facing the following problem: how can I receive a hardward key event in sleep mode?
I've searched Google and other search engines, but can't find anything related.
public class YourBoardcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_CAMERA_BUTTON.equals(intent.getAction())) {
Intent main = new Intent();//
}
}
}
And in your Manifest :
<receiver android:name="YourBoardcastReceiver">
<intent-filter>
<action android:name="android.intent.action.SCREEN_ON" />
</intent-filter>
</receiver>
The only way I think you could do that is with a BroadcastReceiver, but it seems that the volume buttons do not generate an Intent when the screen is off (see here). The closest thing you might be able to do is use the camera button to do something similar.
Perhaps it is better this way, anyway, though. I imagine it would annoy users if their phone called 911 while in their pocket because of the volume buttons, or the camera button too for that matter. Also, it's not something I would expect to happen.

How auto-run an app when I unlock the device

I want create an app that works like that:
When I take my device, I will unlock it and this app will be alredy opened. Then this app will show a compromise term of use the tablet. There will be two options, allow or refuse. If I choose allow, the app will finish; when I choose refuse, nothing happens until I choose allow.
Then, after I use my device, it will lock, then... I will unlock, and the app will be there again!
How can I put this app to auto-run when I unlock the device?
Add the receiver in menifest file
<receiver android:name=".ScreenReceiver">
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
Create a broadcast receiver which works to open app when phone is unlocked.
public class ScreenReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
System.out.println(intent.getAction());
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT))
{
Intent intent1 = new Intent(context,MainActivity.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent1);
}
}
Already asked, and answered: android unlock screen intent?
You'll need to listen for that intent and then you can launch your app.

Categories

Resources