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.
Related
I am only new to android this is my first application.
I am making progress on an app that fires when the NFC reader detects a TAG that contains NDEF messages, specifically when a URL is detect matching my domain.
I would like to add a splashscreen that fires triggered by the Android INTENT of but then passes the original INTENT to the mainactivity for further processing, I have made a start but not sure how to marry up the manifest and code to do what I am after.
MANIFEST.XML
<activity
android:name=".SplashScreenActivity"
android:theme="#style/Theme.MyApp.SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" android:theme="#style/Theme.MyApp.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="http"
android:host="<my custom domain>"/>
</intent-filter>
</activity>
Any help on how I should structure my Manifest to deal with this scenario, the SplashScreenActivity I could use the intent filters here to ensure that it is triggered, but then I create a new intent which means losing the NDEF extras.
public class SplashScreenActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
finish();
}
}
I would like to be able to "just pass" the whole original INTENT to the mainactivity but I am unsure how to do this.
Here is the code that extracts the NDEF messages from the INTENT any ideas appreciated.
private void readFromIntent(Intent intent) {
String action = intent.getAction();
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)
|| NfcAdapter.ACTION_TECH_DISCOVERED.equals(action) ||
NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
logViewModel.insert(new LogEntry("READFROMINTENT ACTUALLY FIRED", "Action " + intent.getExtras()));
if (rawMsgs != null) {
msgs = new NdefMessage[rawMsgs.length];
for (int i = 0; i < rawMsgs.length; i++) {
msgs[i] = (NdefMessage) rawMsgs[i];
}
getNdefRecords(msgs);
addLinkToDbFromRecord(records);
}
//buildTagViews(msgs);
}
}
So I managed to solve this by doing the following.
I moved my intent filters from MainActivity to the .splashscreen actvity changed the category of mainactivity to DEFAULT, and allowed splashscreen activity to remain the LAUNCHER
<activity
android:name=".MainActivity"
android:theme="#style/Theme..NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.myap.app.SplashScreenActivity"
android:theme="#style/Theme.myapp.SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="http"
android:host="my domain"/>
</intent-filter>
</activity>
In my splashscreen activity i used the following code to copy the extras from the original intent, set the action to the expected action the mainactivity was designed to handle and used this to start the main activity
public class SplashScreenActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent startMainActivity = new Intent(SplashScreenActivity.this, MainActivity.class);
startMainActivity.putExtras(getIntent());
startMainActivity.setAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
startActivity(startMainActivity);
finish();
}
}
I want to change my default dialer app and searched for some articles.
But when I'm in the test, I encounter problem my real phone(Android 6.0) doesn't show the pop window.
InRealPhoneTest.png
So I'm attempting to test in a virtual machine(android 6.0), it works perfectly.
InVirtualMachineTest.png
below are my codes:
Application.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.slb.test1">
<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:label="#string/app_name"
android:directBootAware="true"
android:excludeFromRecents="true"
android:launchMode="singleInstance"
android:process=":interim"
android:resizeableActivity="true"
android:screenOrientation="nosensor">
<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.VIEW"/>
<action android:name="android.intent.action.DIAL"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="tel"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.DIAL"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
MainApplication.java
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_CODE_SET_DEFAULT_DIALER = 289;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void ViewClick(View view){
try {
Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER);
intent=intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, getPackageName());
startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_DIALER);
}catch (Exception e){
e.printStackTrace();
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
if(requestCode==REQUEST_CODE_SET_DEFAULT_DIALER){
if(resultCode==RESULT_OK){
Toast.makeText(this,"accept",Toast.LENGTH_SHORT).show();
}else if(resultCode==RESULT_CANCELED){
Toast.makeText(this,"cancel",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(this,"unknown",Toast.LENGTH_SHORT).show();
}
}
}}
My purpose wants to change the default app dialer through InCallService service class, I'm just testing the pop window.
when I process program in a virtual machine of android 6.0, I can choose whether to accept or cancel in a popout. however, when I process program in a real phone that version is android 6.0, the phone doesn't appear the popout.
So, I can't understand why it doesn't work on the real phone. can you tell me something about it?. your answer will be appreciated.
#Override
public void onClick(View v) {
Intent intent = new Intent("com.example.ui05.ACTION_START");
intent.addCategory("com.example.ui05.MY_CATEGORY");
startActivity(intent);
}
the relevant Manifest is:
<activity android:name=".SecondActivity" >
<intent-filter>
<action android:name="com.example.ui05.ACTION_START" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.CATEGORY" />
</intent-filter>
</activity>
#Override
public void onClick(View v) {
Intent intent = new Intent("com.example.ui05.ACTION_START");
startActivity(intent);
}
the relevent manifest is:
<activity android:name=".SecondActivity" >
<intent-filter>
<action android:name="com.example.ui05.ACTION_START" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
why the first situation would give an Exception :
android.content.ActivityNotFoundException: No Activity found to handle
Intent { act=com.example.ui05.ACTION_START cat=[com.example.ui05.MY_CATEGORY] }
The second situation is OK.
Your intent filter doesn't include the category for the category you're specifying in the intent. Change your intent filter category specifying android.intent.category.CATEGORY to com.example.ui05.MY_CATEGORY and it should work.
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
After attempting to perform a search and failing, I am trying to launch an activity to display results from a search, but the app crashes when it gets to the point of the intent:
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
Intent mapIntent = new Intent(SearchActivity.this, MapResults.class);
mapIntent.putExtra("query", query);
startActivity(mapIntent);
}
here is the class it is supposed to launch:
public class MapResults extends MapActivity implements OnGestureListener, OnDoubleTapListener {
/** Called when the activity is first created. */
public String query;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = getIntent();
query = intent.getStringExtra("query");
Toast.makeText(this, "The query: " + query, Toast.LENGTH_LONG).show();
}
#Override
public boolean isRouteDisplayed() {
return false;
}
and the manifest file:
<activity android:name=".SplashScreen"
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=".Main">
<intent-filter>
<action android:name="com.example.android.test.Main" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity" />
</activity>
<activity android:name=".SearchActivity"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity" />
<meta-data android:name="android.app.searchable"
android:resource="#layout/searchable"/>
</activity>
<activity android:name=".MapResults">
<intent-filter>
<action android:name="com.example.android.test.MapResults"
android:label="#string/map_results_title"/>
</intent-filter>
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity" />
</activity>
I know that in the MapResults class it is not launching a map at the moment, its just displaying text, but this is just while I am trying to receive the data from the intent.
Any idea, cause I'm stuck!
In your MapResults class, the line :
Toast.makeText(this, "The query: " + query, Toast.LENGTH_LONG).show();
will create a NullPointerException as you are concatenating a null String. Your data member query is null at this point, you should have something like this :
query = intent.getStringExtra( "query" );
Toast.makeText(this, "The query: " + query, Toast.LENGTH_LONG).show();
Otherwise, your mechanism to transfer data using intents seems alright to me.
Regards,
Stéphane
The only problem, that I can see in the code is your intent variable is null, so it crashes on intent.getAction()
up: haven't noticed MapActivity code - if variable query is not initialized at the moment of Toast - yes, it's a second problem
<intent-filter>
<action android:name="com.example.android.test.Main" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
can you change DEFAULT to LAUNCHER?
just try it