android: lock uninstall app using device admin - android

please help . . I build app, but i want to when user try to uninstall mp app, it's require password. I try this but it doesn't work:
In myActivity:
AdminReceiver a = new AdminReceiver();
a.onDisableRequested(getApplicationContext(), getIntent());
AdminReceiver :
public class AdminReceiver extends DeviceAdminReceiver{
static DevicePolicyManager dpm;
static ComponentName devAdminReceiver;
public CharSequence onDisableRequested(final Context context, Intent intent) {
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startMain); //switch to the home screen, not totally necessary
lockPhone(context, "pass");
//Log.i(TAG, "DEVICE ADMINISTRATION DISABLE REQUESTED & LOCKED PHONE");
return "haha. i locked your phone.";
}
public static boolean lockPhone(Context context, String password){
devAdminReceiver = new ComponentName(context, AdminReceiver.class);
dpm = (DevicePolicyManager)context.getSystemService(Context.DEVICE_POLICY_SERVICE);
boolean pwChange = dpm.resetPassword(password, 0);
dpm.lockNow();
return pwChange;
}
And in AndroidManifest:
<receiver android:name=".app.AdminReceiver"
android:label="#string/app_name"
android:description="#string/hello_world"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin"
android:resource="#xml/deviceadmin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
and last in xml/deviceadmin:
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
</uses-policies>
</device-admin>
actually i really confused, how it works. Please help me i really need it for my final project

That is not possible in Android without firmware modifications.
Refer AOSP code for further managing policy
OR
IN AndroidL push deviceower.xml which will make ur app device owner hence u can apply the policy but prerequisites is device should be rroted

Related

Xamarin | Android | COSU Error

I am attempting to create a COSU device. It will be hardware sold by my company that runs a single application developed by us. I have looked through many tutorials in an attempt to set up a proof of concept for this.
I currently have the following.
In my AndroidManaifest.xml
Then later...
<application android:allowBackup="true" android:label="#string/app_name" android:keepScreenOn="true" >
<receiver android:name="DeviceAdmin"
android:label="#string/sample_device_admin"
android:description="#string/sample_device_admin_description"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
<device-admin>
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
</uses-policies>
</device-admin>
</receiver>
<uses-permission android:name="android.permission.MANAGE_DEVICE_ADMINS" />
<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>
</application>
In device_admin_receiver.xml
<?xml version="1.0" encoding="utf-8"?>
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
</uses-policies>
</device-admin>
DeviceAdmin.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.App.Admin;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace CB.App
{
public class DeviceAdmin : DeviceAdminReceiver
{
}
}
And finally the OnCreate of MainActivity.cs
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Window.DecorView.SystemUiVisibility = (StatusBarVisibility)flags;
// Setup the collection and register implementations
IServiceCollection coll = new ServiceCollection();
RegisterDependencies(coll);
// Build the global services
ServiceRegistrationHelper.RegisterCoreServices(coll);
// Register the provide with the GlobalServices
GlobalServices.RegisterServiceProvider(coll.BuildServiceProvider(new ServiceProviderOptions()));
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
DevicePolicyManager myDevicePolicyManager = (DevicePolicyManager)this.GetSystemService(Activity.DevicePolicyService);
// get this app package name
ComponentName mDPM = new ComponentName(this, typeof(DeviceAdmin).Name);
if( myDevicePolicyManager.IsDeviceOwnerApp(this.PackageName))
{
//myDevicePolicyManager.ClearDeviceOwnerApp(this.PackageName);
String[] packages = { this.PackageName };
myDevicePolicyManager.SetLockTaskPackages(mDPM, packages);
StartLockTask();
SetUpClock();
DisplayHome();
}
else
{
Toast.MakeText(this.ApplicationContext, "Not Owner", ToastLength.Long).Show();
}
}
In the ADB Shell I ran the command dpm set-device-owner com.companyname.productname/.DeviceAdmin and received Success: Device owner set to package componentinfo{com.companyname.productname/com.companyname.productname.DeviceAdmin} Active admin set to component {com.companyname.productname/com.companyname.productename.DeviceAdmin}
It builds and deploys but when it gets to the line
myDevicePolicyManager.SetLockTaskPackages(mDPM, packages);
It throws the error Java.Lang.SecurityException: No active admin ComponentInfo(com.lathem.cumberland/DeviceAdmin
What am I missing?
Remove the <device-admin> section from your receiver, this should be referenced via a separate xml resource, either via hard-coding the meta-data section in the receiver's manifest section or via class attributes:
[BroadcastReceiver(
Name = "com.sushihangover.cosu.DeviceAdminReceiver",
Label = "StackOverflow",
Permission = "android.permission.BIND_DEVICE_ADMIN",
Exported = true
)]
[MetaData("android.app.device_admin", Resource = "#xml/device_admin_receiver")]
[IntentFilter(new[] {
"android.intent.action.DEVICE_ADMIN_ENABLE",
"android.intent.action.PROFILE_PROVISIONING_COMPLETE",
"android.intent.action.BOOT_COMPLETED"
})]
public class MyDeviceAdminReceiver : DeviceAdminReceiver {}
Use the Java class name, not the C# name:
ComponentName mDPM = new ComponentName(this, Java.Lang.Class.FromType(typeof(DeviceAdminReceiver)));
Note: Based upon my use of the Java name for my DeviceAdminReceiver subclass, the dpm set-device-owner would be:
adb shell dpm set-device-owner com.sushihangover.cosu/com.sushihangover.cosu.DeviceAdminReceiver

Delaying App Boot Up Until Internet is Ready

I am building an application that is supposed to launch at start-up. It is based around a WebView. Unfortunately, I typically receive an ERR_NAME_NOT_RESOLVED or similar when the app is first launched. I presume this is because the device has not properly performed all tasks/setup necessary to properly connect to the Internet. I have referenced this question which seems to pose a similar problem however, it appears the accepted answer is unsuitable for more recent versions of Android. Additionally, I am not looking for when the user activates Wi-Fi or mobile data, but rather when the device itself is ready to access webpages.
My initial idea was to create a Splash Screen to delay the app. I referenced this post and added a call to wait() (MainActivity contains the WebView).
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.Set;
public class LaunchActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launch);
SharedPreferences preferences = getSharedPreferences("config", MODE_PRIVATE);
final SharedPreferences.Editor editor = preferences.edit();
startLockTask();
editor.putBoolean("IsLocked", true);
editor.commit();
if(preferences.getBoolean("configured", false)) {
try {
wait(3000);
} catch (InterruptedException ex) {
System.out.print("Interrupted");
}
Intent i = new Intent(LaunchActivity.this, MainActivity.class);
startActivity(i);
finish();
} else {
Intent i = new Intent(LaunchActivity.this, Setup.class);
i.putExtra("Auth", true);
startActivity(i);
finish();
}
}
}
This, however, results in java.lang.RuntimeException: Unable to start activity ComponentInfo{midamcorp.com.cargoview/midamcorp.com.cargoview.LaunchActivity}: java.lang.IllegalMonitorStateException: object not locked by thread before wait().
My manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="midamcorp.com.cargoview">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<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"
android:lockTaskMode="if_whitelisted"
android:screenOrientation="portrait"></activity>
<receiver android:name=".BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity android:name=".Setup" />
<activity
android:name=".LaunchActivity"
android:lockTaskMode="if_whitelisted"
android:theme="#style/SplashTheme"
android:screenOrientation="portrait">
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Login"
android:label="#string/title_activity_login"></activity>
</application>
</manifest>
BootReceiver:
public class BootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context c, Intent i) {
final AlarmManager manager = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);
if (i.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
Intent launch = new Intent(c, LaunchActivity.class);
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
c.startActivity(launch);
}
}
}
What is the best practice for this in current Android development?
Thanks.
On latest OS, when your device is booted, you can schedule a JobScheduler to which will be triggered when internet connection is available. When the JobScheduler is triggered, you can start your activity as follows:
#Override
public boolean onStartJob(final JobParameters params) {
Intent launch = new Intent(c, LaunchActivity.class);
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
c.startActivity(launch);
return true;
}
You can find the tutorial to schedule a job here

Lock or turn off the screen programmatically

I want to turn off / lock the screen of my device programmatically.
For the moment, when I try :
DevicePolicyManager mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
mDPM.lockNow();
I have this error :
java.lang.SecurityException: No active admin owned by uid 10176 for policy #3
This is my AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="opteamit.com.belami" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature android:name="android.hardware.location.gps" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application...
What is wrong ?
Well something with high necessity can't finished with two lines of code, lock off screen required device admin. you may follow this :
private void lock() {
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
if (pm.isScreenOn()) {
DevicePolicyManager policy = (DevicePolicyManager)
getSystemService(Context.DEVICE_POLICY_SERVICE);
try {
policy.lockNow();
} catch (SecurityException ex) {
Toast.makeText(
this,
"must enable device administrator",
Toast.LENGTH_LONG).show();
ComponentName admin = new ComponentName(context, AdminReceiver.class);
Intent intent = new Intent(
DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN).putExtra(
DevicePolicyManager.EXTRA_DEVICE_ADMIN, admin);
context.startActivity(intent);
}
}
}
and AdminReceiverClass:
public class AdminReceiver extends DeviceAdminReceiver {
public static final String ACTION_DISABLED = "device_admin_action_disabled";
public static final String ACTION_ENABLED = "device_admin_action_enabled";
#Override
public void onDisabled(Context context, Intent intent) {
super.onDisabled(context, intent);
LocalBroadcastManager.getInstance(context).sendBroadcast(
new Intent(ACTION_DISABLED));
}
#Override
public void onEnabled(Context context, Intent intent) {
super.onEnabled(context, intent);
LocalBroadcastManager.getInstance(context).sendBroadcast(
new Intent(ACTION_ENABLED));
}
}
also we need declares the security policies used in metadata so for examples with Path android:resource="#xml/device_admin_sample" :
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
<expire-password />
<encrypted-storage />
<disable-camera />
</uses-policies>
</device-admin>
in our case we just need :
<?xml version="1.0" encoding="utf-8"?>
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<force-lock />
</uses-policies>
</device-admin>`
Now declare it in our manifist.xml :
<receiver
android:name=".AdminReceiver"
android:label="#string/device_admin"
android:description="#string/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>`
Hope it will Help you.
See user6490462 answer below.
private void lock() {
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
if (pm.isScreenOn()) {
DevicePolicyManager policy = (DevicePolicyManager)
getSystemService(Context.DEVICE_POLICY_SERVICE);
try {
policy.lockNow();
} catch (SecurityException ex) {
Toast.makeText(
this,
"must enable device administrator",
Toast.LENGTH_LONG).show();
ComponentName admin = new ComponentName(context, AdminReceiver.class);
Intent intent = new Intent(
DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN).putExtra(
DevicePolicyManager.EXTRA_DEVICE_ADMIN, admin);
context.startActivity(intent);
}
}
}
For those of us who landed here from google and weren't able to get the admin request to popup, I ended up solving it by making sure that I started the activity from a currently running Activity (thus, calls would not need the context. in front of them. While some may have had luck with intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) from a service, I had to move the call into an Activity.
ComponentName admin = new ComponentName(context, AdminReceiver.class);
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN)
.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, admin);
startActivity(intent);
This worked for me after following user6490462's instructions but I had to tweak the Intent slightly
Even with these changes, for some reason I could not get the activity window to pop up to approve the device admin privilege's. But when I went into Biometrics and security -> Other security settings -> Device admin apps I could see my app there waiting to have its admin privilege's approved.
ComponentName admin = new ComponentName(getApplicationContext(), AdminReceiver.class);
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, admin);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
"Allow this app to turn screen off");
startActivity(intent);

Cannot enable administrator component

I am trying to set the lock task packages but IsAdminActive is returning false.
To set the device owner and active admin I used the command dpm set-device-owner PinningTest.PinningTest/.AdminReceiverTest from the adb shell. This completed successfully.
My MainActivity:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
DevicePolicyManager devicePolicyManager = (DevicePolicyManager)GetSystemService(Context.DevicePolicyService);
ComponentName testDeviceAdmin = new ComponentName(this, Java.Lang.Class.FromType(typeof(AdminReceiverTest)).Name);
if (devicePolicyManager.IsAdminActive(testDeviceAdmin))
{
devicePolicyManager.SetLockTaskPackages(testDeviceAdmin, new string[] { PackageName });
}
}
My AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="PinningTest.PinningTest"
android:versionCode="1" android:versionName="1.0"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" />
<uses-permission android:name="android.permission.BIND_DEVICE_ADMIN" />
<application android:label="PinningTest">
<receiver android:name=".AdminReceiverTest"
android:label="#string/ApplicationName"
android:description="#string/ApplicationName"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin" android:resource="#xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
</application>
</manifest>
AdminReceiverTest.cs:
namespace PinningTest
{
class AdminReceiverTest : DeviceAdminReceiver
{
}
}
I was following the tutorial here and have also looked at various others but I haven't been able to find a complete Xamarin example.
Any help is appreciated.
Many thanks.
I originally had the same issue, but I've just got this working by using the following
[BroadcastReceiver(Name = "com.sceneskope.survey.DeviceAdminReceiver", Enabled = true, Exported = true, Permission = "android.permission.BIND_DEVICE_ADMIN")]
[MetaData("android.app.device_admin", Resource = "#xml/device_admin_receiver")]
[IntentFilter(new[] { "android.app.action.DEVICE_ADMIN_ENABLED" })]
public class DeviceAdminReceiver : Android.App.Admin.DeviceAdminReceiver
{
}
And setting the device owner using
.\adb.exe shell dpm set-device-owner com.afwsamples.testdpc/.DeviceAdminReceiver
That appears to solve my problems, so I guess this was down to issues with the names when putting in the manifest manually.
It looks like your manual manifest entries are not taking into account the auto-generated class names (Md5-based) that Xamarin.Android generates to avoid namespace collisions.
Since DeviceAdminReceiver is a subclass of BroadcastReceiver, use the [BroadcastReceiver] class attribute to override the auto-generated class names in your manifest:
[BroadcastReceiver(Name = "com.sushihangover.deviceownerapp.adminreceiver", Enabled = true, Exported = true)]
[IntentFilter(new[] { "android.app.action.DEVICE_ADMIN_ENABLED" })]
public class AdminReceiverTest : DeviceAdminReceiver
{
public override void OnReceive(Context context, Intent intent)
{
base.OnReceive(context, intent);
}
}
Thus in your manifest, the following is auto-generated:
<receiver android:enabled="true" android:exported="true" android:name="com.sushihangover.deviceownerapp.adminreceiver">
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>

How to launch an Android app without "android.intent.category.LAUNCHER"

I want to know how to launch an Android app without:
android.intent.category.LAUNCHER
Here is my AndroidManifest.xml:
<intent-filter>
<action android:name = "android.intent.action.MAIN" />
<category android:name = "android.intent.category.LAUNCHER" />
</intent-filter>
If removing line 3, the app will not be in the launcher. The question is: where and how can I launch this app in other way?
You'll need to use a BroadcastReceiver.
public class SafetyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
ActivityManager as = (ActivityManager) context
.getSystemService(Activity.ACTIVITY_SERVICE);
if (IsNavigationRunning(as)) {
Intent i = new Intent(context, VoiceActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
Manifest:
<application
android:icon="#drawable/fot"
android:label="#string/app_name" >
<activity
android:name="com.Safety.VoiceActivity"
android:launchMode="singleTop"
android:theme="#style/Theme.CompletelyTransparentWindow" >
</activity>
<receiver
android:name="com.Safety.SafetyReceiver"
android:process=":goodprocess" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
This is an example that starts when a text is received.
This would be better if you want to launch a custom activity, for example on a button press:
Button btn = (Button)findViewById(R.id.xBtn);
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
Intent intent = new Intent("it.prassel.vimsmediaplayer");
intent.setComponent(ComponentName
.unflattenFromString("it.prassel.vimsmediaplayer/it.prassel.vimsmediaplayer.MainActivity"));
intent.addCategory("android.intent.category.LAUNCHER");
startActivity(intent);
}
});
And this is the manifest associated with your custom activity:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.prassel.vimsmediaplayer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-feature android:glEsVersion="0x00020000" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="it.prassel.vimsmediaplayer.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="it.prassel.vimsmediaplayer" />
</intent-filter>
</activity>
</application>
</manifest>
Where
Intent intent = new Intent("it.prassel.vimsmediaplayer");
corresponds to the line
<action android:name="it.prassel.vimsmediaplayer" />
And
intent.setComponent(ComponentName
.unflattenFromString("it.prassel.vimsmediaplayer/it.prassel.vimsmediaplayer.MainActivity"))
corresponds to the 2 lines
package="it.prassel.vimsmediaplayer" the part before /
android:name="it.prassel.vimsmediaplayer.MainActivity" the part after /
Your custom activity will not appear neither in the Menu nor in the Recent Apps, it will be completely anonymous. Pay attention, if you wish to be the only one who can acced to your app, to give the intent-filter a meaningful name
I want to know how to launch an Android app without: android.intent.category.LAUNCHER
In Android, an Activity should be started by an Intent. Intents can start an Activity with startActivity(Intent myIntent), example:
Intent myIntent= new Intent(context, target_class.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
You must replace "myIntent", "context" (usually a "this") and the "target_class" with your variables, in order for this to work.
So, whenever you need your activity, call the Intent, ans the OS will resolve for the Activity
you can specify in your class.
For example on clicking of a button you want to go to some activity. so just write this code:
Button btn = (Button)findViewById(R.id.xBtn);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intnt = new Intent();
intnt.setAction(android.intent.action.MAIN);
intnt.setCategory(android.intent.category.LAUNCHER);
startActivity(intnt);
}
});

Categories

Resources