Voice to text: No Activity found to handle Intent - android

I am trying to use google search to text engine but it is not possible and get error :
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.speech.action.RECOGNIZE_SPEECH (has extras)
Can you help me?
Here is my MainActivity.java code
public class MainActivity extends Activity {
private static final int REQUEST_CODE = 1234;
Button Start;
TextView Speech;
Dialog match_text_dialog;
ListView textlist;
ArrayList<String> matches_text;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Start = (Button)findViewById(R.id.start_reg)
Speech = (TextView)findViewById(R.id.speech);
Start.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if(isConnected()){
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
startActivityForResult(intent, REQUEST_CODE);
}
else{
Toast.makeText(getApplicationContext(), "Plese Connect to Internet", Toast.LENGTH_LONG).show();
}}
});
}
public boolean isConnected()
{
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo net = cm.getActiveNetworkInfo();
if (net!=null && net.isAvailable() && net.isConnected()) {
return true;
} else {
return false;
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
match_text_dialog = new Dialog(MainActivity.this);
match_text_dialog.setContentView(R.layout.dialog_matches_frag);
match_text_dialog.setTitle("Select Matching Text");
textlist = (ListView)match_text_dialog.findViewById(R.id.list);
matches_text = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, matches_text);
textlist.setAdapter(adapter);
textlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Speech.setText("You have said " +matches_text.get(position));
match_text_dialog.hide();
}
});
match_text_dialog.show();
}
super.onActivityResult(requestCode, resultCode, data);
}
}
and this is AndroidManifest.xml code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.learn2crack.speech"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.learn2crack.speech.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Related

Creating new activity gives error "Performing pause of activity that is not resumed"

I have created several activities via Intent's in the past, yet this error baffles me.
This is a simple tutorial given on Developer.Android's website for creating a new Activity
Problem:
The error is thrown before onPause() and after calling startActivityForResult() all in the same Activtiy
Error:
E/ActivityThread: Performing pause of activity that is not resumed: {wrap302.nmu.assignment_6_task_2_server/wrap302.nmu.assignment_6_task_2_server.MainActivity}
java.lang.RuntimeException: Performing pause of activity that is not resumed: {wrap302.nmu.assignment_6_task_2_server/wrap302.nmu.assignment_6_task_2_server.MainActivity}
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3398)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3386)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3361)
at android.app.ActivityThread.-wrap13(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1374)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5471)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Minimal Working Example:
public class MainActivity extends Activity {
public static String isHost = "isHost";
private Context mContext;
private Button btnHostGame;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
setContentView(R.layout.activity_main);
btnHostGame = (Button) findViewById(R.id.btnHostGame);
btnHostGame.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startGameActivity(true);
}
});
}
private void startGameActivity(boolean isHosting) {
Intent intent = new Intent(mContext, GameConnector.class);
intent.putExtra(isHost, isHosting);
startActivityForResult(intent, 0); //Exception occurs after this method
}
#Override
protected void onResume() {
super.onResume();
getActionBar().hide();
}
// Exception occurs before this method is called
#Override
protected void onPause() {
super.onPause();
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Toast.makeText(mContext, "Did you win?", Toast.LENGTH_SHORT).show();
}
}
This is quite strange to me, any advice?
UPDATE
AndroidManifest request
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="wrap302.nmu.assignment_6_task_2_server">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<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.NoActionBar">
<activity android:name=".MainActivity"
android:label="#string/title_game">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".GameConnector"
android:label="#string/title_gameconnector">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".Game"
android:label="#string/title_game">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
yes, GameConnector does get created without a problem.
However, the Exception is thrown before the GameConnector.onCreate method is called.
UPDATE 2
GameConnector code request
public class GameConnector extends Activity implements FragmentFinishListener{
public static String GameType = "GameType", GameConnect = "GameConnect";
public static String PlayerName = "PlayerName";
private FragmentManager fragmentManager;
private Fragment gameTypeFragment;
private Intent gameIntent;
private boolean isHosting;
private Context mContext;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gameconnector);
mContext = this;
gameIntent = getIntent();
if (gameIntent.hasExtra(MainActivity.isHost))
isHosting = gameIntent.getBooleanExtra(MainActivity.isHost, false);
fragmentManager = getFragmentManager();
gameTypeFragment = (isHosting)
? new FragmentHostGame().setOnFragmentFinishListener(this)
: new FragmentJoinGame().setOnFragmentFinishListener(this);
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.fragmentContainer, gameTypeFragment, GameType);
fragmentTransaction.commit();
}
#Override
public void finished(Bundle bundle) {
GameConnection gameConnection = null;
if (bundle != null){
if (bundle.containsKey(GameConnect))
gameConnection = (GameConnection) bundle.getSerializable(GameConnect);
}
fragmentManager.beginTransaction().remove(gameTypeFragment).commit();
startGame(isHosting, gameConnection);
}
private void startGame(boolean isHosting, GameConnection gameConnection) {
Intent intent = new Intent(mContext, Game.class);
intent.putExtra(MainActivity.isHost, isHosting);
intent.putExtra(GameConnect, gameConnection);
startActivityForResult(intent, 0);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null){
switch (requestCode){
case 0:{
if (resultCode == 0){
finishActivity(resultCode);
}
else {
setResult(resultCode, data);
finishActivity(1);
}
break;
}
}
}
setResult(resultCode, null);
finishActivity(1);
}
}

phone call is not happenning in my android app?

While making a call from the app, it is not working. I have added the permission in android manifest, but it is still not working. Please see my code and help me soon.
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:999999999"));
if (ActivityCompat.checkSelfPermission(menu.this,
Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
startActivity(callIntent);
}
});
This code should work:
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "Your Phone_number"));
startActivity(intent);
Permission in Manifest:
<uses-permission android:name="android.permission.CALL_PHONE" />
but i highly recommend using ACTION_DIAL instead. It opens up the dialer screen with the number entered instead. This gives the user more flexibility. Also you don't need to have the CALL_PHONE permission with this one.
Here is an update:
With CALL_PHONE permission
Main Class
public class MainActivity extends AppCompatActivity {
private final int CALL_PHONE = 1;
private Button dialBtn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dialBtn = (Button) findViewById(R.id.dial_button);
//In android 6 we need to ask for permissions:
if (ActivityCompat.checkSelfPermission(getApplicationContext(),
Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.CALL_PHONE}, CALL_PHONE);
} else {
Toast.makeText(getApplicationContext(), "We need permissions to dial.", Toast.LENGTH_LONG).show();
}
} else {
setupView();
}
}
private void setupView() {
dialBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:999999999"));
// We have to implement this part because ... yeah permissions in android.....
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(), "We need permissions to dial.", Toast.LENGTH_LONG).show();
return;
}
startActivity(callIntent);
}
});
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
switch (requestCode) {
case CALL_PHONE:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
setupView();
} else {
Toast.makeText(getApplicationContext(), "We need permissions to dial.", Toast.LENGTH_LONG).show();
}
break;
}
}
My manifest:
<uses-permission android:name="android.permission.CALL_PHONE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Without the permission check and only using ACTION_DIAL
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button dialBtn = (Button) findViewById(R.id.dial_button);
dialBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:999999999"));
startActivity(callIntent);
}
});
}
}
The last one is so much easier. Android permission checks are a pain in the ass.
I just made my own class. It's easier for the next time to also provide the error Stack trace. But for what I can see in your code is that your using menu.this I don't know for sure because u didn't provide enough information but I think this causes the error.
I hope I helped u out.

App doesn't find any bluetooth devices

Hey guys I am working on an app which should connect to bluetooth devices. But at the moment I'm struggling with the problem that it doesn't find any bluetooth devices in my app but in the bluetooth settings it finds some. (my device runs android 6.x)
My code:
public class MainActivity extends AppCompatActivity {
private ProgressDialog progressDialogBluetoothDiscovery;
private ListView bluetoothDevices;
private ArrayList<String> bluetoothNearbyDevices;
private BluetoothAdapter mBluetoothAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
bluetoothDevices = (ListView) findViewById(R.id.bluetoothDevicesList);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothDevice.ACTION_FOUND);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
registerReceiver(bluetoothBroadcast, filter);
bluetoothNearbyDevices = new ArrayList<>();
final FloatingActionButton searchDevices = (FloatingActionButton) findViewById(R.id.search_devices);
searchDevices.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
searchDevices();
}
});
}
#Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(bluetoothBroadcast);
}
private void searchDevices() {
if (mBluetoothAdapter == null) {
Toast.makeText(MainActivity.this, getResources().getString(R.string.bluetooth_not_supported), Toast.LENGTH_LONG).show();
return;
} else {
if (!mBluetoothAdapter.isEnabled()) {
Snackbar.make(findViewById(R.id.coordinatorLayout), getResources().getString(R.string.bluetooth_not_enabled), Snackbar.LENGTH_LONG).setAction(getResources().getString(R.string.activate_bluetooth), new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, MainActivity.CONTEXT_INCLUDE_CODE);
}
}).show();
} else {
scanForDevices();
}
}
}
private void scanForDevices() {
mBluetoothAdapter.startDiscovery();
}
private final BroadcastReceiver bluetoothBroadcast = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_ON) {
scanForDevices();
}
} else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
progressDialogBluetoothDiscovery = ProgressDialog.show(MainActivity.this, getResources().getString(R.string.bluetooth_discovery_title), getResources().getString(R.string.bluetooth_discovery_message), true);
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
progressDialogBluetoothDiscovery.dismiss();
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, bluetoothNearbyDevices);
bluetoothDevices.setAdapter(arrayAdapter);
} else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String deviceName = device.getName();
String deviceHardwareAddress = device.getAddress(); // MAC address
Toast.makeText(MainActivity.this, deviceName, Toast.LENGTH_LONG).show();
bluetoothNearbyDevices.add(deviceName);
}
}
};
}
And my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.package">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
</manifest>
So do you have any Idea why it doesn't find any device in my app?
What version of Android are you running this on? If it is Android 6.x, I believe you need to add the ACCESS_COURSE_LOCATION permission to your manifest.
Below is how run time Permissions work Android 6.0 Marshmallow i.e:
> API level 23
For example:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
switch (ContextCompat.checkSelfPermission(getBaseContext(), Manifest.permission.ACCESS_COARSE_LOCATION)) {
case PackageManager.PERMISSION_DENIED:
((TextView) new AlertDialog.Builder(this)
.setTitle("Runtime Permissions up ahead")
.setMessage("To find nearby bluetooth devices please click Allow on the runtime permissions popup." )
.setNeutralButton("Okay", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
if (ContextCompat.checkSelfPermission(getBaseContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(DeviceListActivity.this,
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
REQUEST_ACCESS_COARSE_LOCATION);
}
}
})
.show()
.findViewById(android.R.id.message))
.setMovementMethod(LinkMovementMethod.getInstance());
break;
case PackageManager.PERMISSION_GRANTED:
break;
}
}

Android : Video Intent Opening Error : Source not found

I am trying to use the intent to select a video which I want to play using videoplayer. I am not able to get the intent working instead i am getting the Source Not Found error.
Thanks for your help.
This is my code :
Manifest
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher">
<activity
android:name="SurfaceActivity"
android:label="#string/app_name"
android:configChanges="orientation|screenSize"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
Code:
public class SurfaceActivity extends Activity implements TextureView.SurfaceTextureListener, OnPreparedListener, MediaController.MediaPlayerControl
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
loadVideo = (Button) findViewById(R.id.Load);
// surface.setSurfaceTextureListener(this);
loadVideo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Video File to Play"), 0);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == 0)
{
if (resultCode == RESULT_OK)
{
Uri sourceUri = data.getData();
String source = getPath(sourceUri);
//startPlayback(source);
startPlaying(source);
}
}
}
}

Why does android device administration not work properly

I am setting two buttons on the screen. Whenever I press the first button it will disable the camera. ( as an admin )
I have set manifest ;
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.firstapplication.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- This is where we register our receiver -->
<receiver
android:name=".DemoDeviceAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN" >
<intent-filter>
<!-- This action is required -->
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
<!-- This is required this receiver to become device admin component. -->
<meta-data
android:name="android.app.device_admin"
android:resource="#xml/device_admin_sample" />
</receiver>
</application>
I have wrote code as ;
public class MainActivity extends Activity {
static final int ACTIVATION_REQUEST = 47; // identifies our request id
DevicePolicyManager devicePolicyManager;
ComponentName demoDeviceAdmin;
#Override
protected void onCreate(Bundle savedInstanceState) {
// ...
// Initialize Device Policy Manager service and our receiver class
devicePolicyManager = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
demoDeviceAdmin = new ComponentName(this, DemoDeviceAdminReceiver.class);
}
/* begin, camera management block */
static boolean click = false ;
private OnClickListener setCamera = new OnClickListener() {
public void onClick(View v) {
if ( click == false ) {
startCamera();
click = true ;
}
else {
stopCamera();
click = false ;
}
activate () ; // activate device policy manager
}
};
private void startCamera(){
if(getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){
camera.unlock();
} else {
;
}
}
#SuppressLint("NewApi") private void stopCamera(){
devicePolicyManager. setCameraDisabled(demoDeviceAdmin, true);
}
/* end, camera management block */
private OnClickListener closeApplication = new OnClickListener() {
public void onClick(View v) {
finish ();
}
};
void initializeDPM ( ) {
if (!devicePolicyManager.isAdminActive(demoDeviceAdmin)) {
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
demoDeviceAdmin);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
"Additional text explaining why this needs to be added.");
startActivityForResult(intent, ACTIVATION_REQUEST);
} else {
devicePolicyManager.lockNow();
}
}
public void activate ( ) {
// Activate device administration
Intent intent = new Intent(
DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
demoDeviceAdmin);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
"told me to do this");
startActivityForResult(intent, ACTIVATION_REQUEST);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case ACTIVATION_REQUEST:
if (resultCode == Activity.RESULT_OK) {
// Has become the device administrator.
} else {
//Canceled or failed.
}
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
}
My admin class
public class DemoDeviceAdminReceiver extends DeviceAdminReceiver{
#Override
public void onEnabled(Context context, Intent intent) {
super.onEnabled(context, intent);
}
#Override
public void onDisabled(Context context, Intent intent) {
super.onDisabled(context, intent);
}
}
my device_admin_sample is;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<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>
</LinearLayout>
Why I could not close the camera as an admin ?

Categories

Resources