Android: ActivityNotFound Exception - android

Basically the error is in Manifest file I think.
Here is the code for MainActivity.java
private void setInitialScreen( int visibility ) {
Button choose_picture = (Button) findViewById(R.id.choose_picture);
choose_picture.setVisibility(visibility);
choose_picture.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.addCategory("choose_file");
Log.d("mainactivity", intent.getCategories().toString());
startActivityForResult(intent, 0);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(data.hasCategory("choose_file") && resultCode == RESULT_OK) {
Uri uri = data.getData();
setPhotoEditScreen(0, uri);
}
}
private void setPhotoEditScreen( int visibility, Uri uri ) {
View screen_image_editing = findViewById(R.id.screen_image_editing);
screen_image_editing.setVisibility(visibility);
ImageView main_image = (ImageView) findViewById(R.id.main_image);
main_image.setImageURI(uri);
}
and this is the manifest entry
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter >
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="choose_file"/>
</intent-filter>
</activity>
Screenshot of Logcat
https://www.dropbox.com/s/w0hi3g7n3i966t6/Screenshot%202014-04-14%2010.33.17.jpg

<intent-filter >
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="choose_file"/>
</intent-filter>
Please do remove the following lines from manifest.xml and try it out , I think since it has two intent filters there might be a problem and in the android name and have you included the package name in the
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.splash_1"
Like this

Related

Cannot found image when pickup from my app

i have write an app like camera on android. But when pick an imagefrom my app, it have error can not found image.
imvpick.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent pickIntent = new Intent("inline-data");
if (pickIntent != null) {
pickIntent.putExtra("data", BitmapFactory.decodeResource(getResources(), R.drawable.picker));
setResult(RESULT_OK, pickIntent);
finish();
}
}
});
and in manifest
<activity android:name=".CameraActivity" android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

create a thread into setOnClickListener

I have an Intent into setOnClickListener that it open a list of contacts into a new activity,now,
when I test this example at AVD it is ok, but when I test
on a mobile phone as soon as I touch button I get closing message.
why ?!
Is need a Thread ?
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_PICK,Uri.parse("content://contacts/"));
startActivityForResult(intent, 1);
}});
My Manifest.xml
<activity
android:name="com.example.ex21.ShoMyList"
android:label="Picker">
<intent-filter>
<action android:name="Piker"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<data android:path="contacts" android:scheme="content"></data>
</intent-filter>
</activity>
<activity
android:name="com.example.ex21.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>
use :
Intent intent = new Intent(Intent.ACTION_PICK, Uri.parse("content://picker/contacts/"));
or
Intent intent= new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
I think your uri is incorrect.

deviceManger.lockNow() is Not Working on some Device

I am working on Phone Lock from this Reference. Working well on my Samsung Tab 2. But when I run the Same Code On Nexus 2. It does not work .I have posted some Code below.
It Logs "DeviceAdminSample" "Admin enable FAILED!". Any help will be Appreciated !!
Is there any Restriction on Nexus?
onCreate()
{
deviceManger = (DevicePolicyManager)getSystemService(
Context.DEVICE_POLICY_SERVICE);
activityManager = (ActivityManager)getSystemService(
Context.ACTIVITY_SERVICE);
compName = new ComponentName(this, MyAdmin.class);
}
private void EnableSetting() {
// TODO Auto-generated method stub
Intent intent = new Intent(DevicePolicyManager
.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
compName);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
"Additional text explaining why this needs to be added.");
startActivityForResult(intent, RESULT_ENABLE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case RESULT_ENABLE:
if (resultCode == Activity.RESULT_OK) {
Log.i("DeviceAdminSample", "Admin enabled!");
} else {
Log.i("DeviceAdminSample", "Admin enable FAILED!");
}
}
Thanks.
Code for main Activity
public class LockerTest extends Activity {
protected static final int REQUEST_ENABLE = 0;
DevicePolicyManager devicePolicyManager;
ComponentName adminComponent;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.btn);
button.setOnClickListener(btnListener);
}
Button.OnClickListener btnListener = new Button.OnClickListener() {
public void onClick(View v) {
adminComponent = new ComponentName(LockerTest.this, Darclass.class);
devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
if (!devicePolicyManager.isAdminActive(adminComponent)) {
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, adminComponent);
startActivityForResult(intent, REQUEST_ENABLE);
} else {
devicePolicyManager.lockNow();
}
}
};
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (REQUEST_ENABLE == requestCode) {
super.onActivityResult(requestCode, resultCode, data);
}
}
}
Create a new class - Darclass - code
import android.app.admin.DeviceAdminReceiver;
public class Darclass extends DeviceAdminReceiver{
}
Create a folder 'xml' in 'res'. Then create my_admin.xml file in 'xml' folder. Code for my_admin.xml. Note add this receiver after and before
<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>
Finally add the receiver given bellow to your AndroidManifest.xml
<receiver
android:name=".Darclass"
android:permission="android.permission.BIND_DEVICE_ADMIN" >
<meta-data
android:name="android.app.device_admin"
android:resource="#xml/my_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
It should work on your device.
I had this same problem. It was because my ... block was outside of my block in AndroidManifest.xml. Worked perfectly when I moved the ... block, as shown here:
<activity
android:name=".Main"
android:label="#string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="MyDeviceAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin" android:resource="#xml/device_admin_xml" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
<action android:name="android.app.action.ACTION_DEVICE_ADMIN_DISABLE_REQUESTED" />
<action android:name="android.app.action.ACTION_DEVICE_ADMIN_DISABLED" />
</intent-filter>
</receiver>

Unable to implement QR code Reader in my android app

I am trying to implement a QR code reader in my android app. I have followed these steps:
Created a sample library project from the zxing.zip , /android and /core
Added the created library to my app
My code is as below :
public class main extends Activity {
/** Called when the activity is first created. */
Button scanButton;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
scanButton = (Button) findViewById(R.id.button1);
scanButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(
"com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
The scanner doesn't start and I get this error:
05-08 14:12:03.313: ERROR/AndroidRuntime(718): Caused by: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity in loader dalvik.system.PathClassLoader[/data/app/com.scanner.demo-2.apk]
The manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.scanner.demo" android:versionCode="1" android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".main" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Why do you put this in your Manifest?
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
...
</activity>
Are you calling internal activity or the App from Zxing?
This is quite confused. You seem to be wanting to integrate by Intent, which is what the first half does. But then you seem to have copied our Manifest. Why? Please remove that. It's not needed, causes your error, and if you leave it in, interferes with our app.
This is all you need: https://code.google.com/p/zxing/wiki/ScanningViaIntent

Getting android.content.ActivityNotFoundException with Zxing

I have followed the following tutorial : http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/
But even after editing android manifest xml as told there I am getting the following error:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN pkg=com.google.zxing.client.android (has extras) }
My Code :
public class BarCodeScannerActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button ok;
ok=(Button) findViewById(R.id.b1);
ok.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("Helllllllloooooooo");
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE","QR_CODE_MODE");
startActivityForResult(intent, 0);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
System.out.println("onActivityResult________resultCode________ "+resultCode);
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
System.out.println("contentsssssssssssssssssssssss" + contents);
Toast.makeText(getApplicationContext(),"Congratulations!!!... Product Code"+ contents + "On Scanning This Item..." ,Toast.LENGTH_LONG).show();
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
System.out.println("Formaattttttttttttttt " + format);
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
}
And mainfest file:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".BarCodeScannerActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.CAMERA" />
Hi
Now i am getting a strange problem of attached screen shot once i updated my manifest as follows:
<activity android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
![enter image description here][1]
<activity android:name=".ScanItemActivity"
android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
</activity>
I mean it says ""Sorry, the Android camera encountered a problem. You may need to
restart the device."
Nothing is there in logcat.
This is quite confused. You don't need to change your manifest at all if you are integrating by Intent, so remove anything you changed just for the integration.
The app is not installed, and you are not handling this properly. You must catch ActivityNotFoundException, or determine ahead of time that the app to handle the Intent is installed.
But, there is no need for any of this complexity. See http://code.google.com/p/zxing/wiki/ScanningViaIntent . You can use IntentIntegrator, which does all of this for you correctly, in a few lines of code.

Categories

Resources