I use the Library:
https://github.com/lvillani/android-cropimage
for adding crop activity in my project.I import this library and add in my project now I am writing this code :
String mPackage = "com.android.camera";
String mClass = ".CropImage";
intent.setComponent(new ComponentName(mPackage,mPackage+mClass));
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
It gives error :
Unable to find explicit activity class {com.android.camera/com.android.camera.CropImage}; have you declared this activity in your AndroidManifest.xml?
I tried to write in AndroidManifest.xml in my project ass well but still the same error.
Step #1: Add an <activity> element to your manifest pointing to com.android.camera.CropImage
Step #2: Use new Intent(this, com.android.camera.CropImage.class) to create your Intent
Step #3: There should be no step #3 AFAIK
Add activity like this in your android manifest file,
...
....
</activity>
<!-- Declare the bundled CropImage Activity -->
<activity android:name="com.android.camera.CropImage"/>
</application>
</manifest>
Documentation indeed helps :) link
Related
I am currently developing an android app and needed a function that starts a phone call so I added this code.
public void dialPhoneNumber(String phoneNumber) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + phoneNumber));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
.. it seems to work perfectly in older android versions but when I test it in android 11 it doesn't function at all I tried action_call and added the permission <uses-permission android:name="android.permission.CALL_PHONE" /> still doesn't work.
Your problem lies in the line of code intent.resolveActivity(getPackageManager()). When you call resolveActivity, you will get a warning like this:
Consider adding a declaration to your manifest when calling this method; see https://g.co/dev/packagevisibility for details
Check the document under PackageManager, you will see this note:
Note: If your app targets Android 11 (API level 30) or higher, the methods in this class each return a filtered list of apps. Learn more about how to manage package visibility.
So what does that mean?
In android 11, Google added package visibility policy. Apps now have tighter control over viewing other apps. Your application will not be able to view or access applications outside of your application.
What do you need to do?
All you need to do is add below line of code to AndroidManifest.xml:
<manifest>
<queries>
<!-- Specific intents you query for -->
<intent>
<action android:name="android.intent.action.DIAL" />
</intent>
</queries>
</manifest>
More information:
Package visibility in Android 11
Package visibility filtering on Android
I have 2 product flavor. Let's say the example like this:
productFlavors {
free {
applicationId 'com.free.android'
}
premium {
applicationId 'com.premium.android'
}
My problem is when i use
Intent resultIntent = new Intent(this, ExpiryListActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(ExpiryListActivity.class);
stackBuilder.addNextIntent(resultIntent);
The problem happened when stackBuilder.addParentStack(ExpiryListActivity.class)
The first app which used the productFlavor free doesn't cause android.content.pm.PackageManager$NameNotFoundException error.
But the second app which used the productFlavor premium it causes android.content.pm.PackageManager$NameNotFoundException.
Then i read the docs that stackBuilder.addParentStack(<Class>) Add the activity parent chain as specified by manifest . How to solve this problem?
TL;DR
change your metadata as
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="originalPackageName.ui.MainActivity" />
The basic problem is that gradle is expanding the package name for the parent activity class that you wrote in the metadata.
In case of your free product flavor it tries to find a class at location com.free.android.ui.MainActivity
And in case of your paid flavor it tries to find a class at location com.premium.android.ui.MainActivity
But gradle actually does not restructure the packages when you mention different applicationId's for your product flavors and the class is still located at originalPackageName.ui.MainActivity and hence the NameNotFoundException
where originalPackageName is a placeholder for the package name you started your project with.
Looks like i found it. On AndroidManifest.xml
<activity
android:name=".ui.ExpiryListActivity"
android:label="#string/voucher_expiry_list"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar.Slidable" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity" />
</activity>
I replace the meta-data name by:
<activity
android:name=".ui.ExpiryListActivity"
android:label="#string/voucher_expiry_list"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar.Slidable" >
<meta-data
android:name=".ui.ExpiryListActivity"
android:value=".ui.MainActivity" />
</activity>
It works, but when pressing back it cannot return to MainActivity. But, I know if this is not the best solution. Please let me know if there is another better solution.
NB: This seems only happened on Android Lollipop (5.0)
I know that this question was already write, and it's that why , i post my question because it's very strange...
I just want to go to an other activity since OnPostExecute() of my AsyncTask.
So i saw that this line works :
this.context.startActivity(new Intent(this.context, com.ListCrossingPoint.ListCrossingPoint.class));
Where this.context is the context of the start activity , which is in the constructor of the asyntask and com.ListCrossingPoint.ListCrossingPoint.class is the class reach, which is in other package.
And thinking that it's will work well , i have this error :
03-11 14:59:22.304: E/AndroidRuntime(1041): FATAL EXCEPTION: main
03-11 14:59:22.304: E/AndroidRuntime(1041): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.main/com.ListCrossingPoint.ListCrossingPoint};
have you declared this activity in your AndroidManifest.xml?
03-11 14:59:22.304: E/AndroidRuntime(1041): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1541)
03-11 14:59:22.304: E/AndroidRuntime(1041): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
...
So , i went to see if my activity was declare and , yess, it declared, so i don't understand ..
<activity android:name="com.listcrossingpoint.ListCrossingPoint" android:label="#string/menu_point_list"
android:configChanges="orientation" android:screenOrientation="landscape" />
you have a typo in
com.ListCrossingPoint.ListCrossingPoint.class
that mismatch with the entry in the Manifest. It should be
com.listCrossingPoint.ListCrossingPoint.class
you have the capital L in the Intent constructor, but it is lower case in the AndroidManifest.xml
Woohoo Its an issue of Spell Mistake. What you have defined in AndroidManifest.xml is
<activity android:name="com.listcrossingpoint.ListCrossingPoint" android:label="#string/menu_point_list"
android:configChanges="orientation" android:screenOrientation="landscape" />
And you are calling
this.context.startActivity(new Intent(this.context, com.ListCrossingPoint.ListCrossingPoint.class));
this in Intent. Its a problem of Package Name.
Change this ListCrossingPoint to listcrossingpoint.
Can you rename your package to listcrossingpoint with lowercase?, you mustn't use uppercase to package names.
You can use refactor/rename in eclipse to do it. (Alt+Shift+R)
I assume it is due to the wrong spelling:
in startActivity() you call
"com.ListCrossingPoint.ListCrossingPoint.class"
in the Manifest you have
"com.listcrossingpoint.ListCrossingPoint"
(upper and lower case L)
i resolved my problem. I renamed the package com.listpoint , like this , there is no ambiguity and i verify all reference and it's work. Thank everybody =)
I have just opened my code from a few weeks off and now it doesn't seem to work. I have a splash screen on open, which then moves to the home screen. The splash screen works, but when trying to move to the home page it falls over saying No Class Def Found. What does this mean and how can i fix it?
It says the problem is found with the below code which is in the splash screen class:
public void run()
{
//Finish the splash activity so it can't be returned to.
SplashScreen.this.finish();
// Create an Intent that will start the main activity.
Intent mainIntent = new Intent(SplashScreen.this, HomeScreen.class);
SplashScreen.this.startActivity(mainIntent);
}
please place HomeScreen in manifest file
<activity android:name=".HomeScreen"
android:label="#string/app_name">
</activity>
So what happened was I updated the Android SDK and apparently there have been a few problems with this, one being changing lib to libs. What I did was removed the activity and re-added. Thanks arcastro.
So if anyone has this problem from 16->17, check the activity's in the manifest file, and the lib folder
does not compile. Indeed: even in 1.5, this api, getIntent(), is already listed as deprecated.
The error message I get complains that getIntent() does not return a String, but setCurrentTab() expects a string.
If I guess and change the line to read:
"tabHost.setCurrentTab(1); // was setCurrentTab(getIntent())",
then it compiles, builds, but does not run. I get the "stopped unexpectedly" error message from the emulator. I cannot even get Log.d to output, so it seems that it stops 'unexpectedly' very early.
So the first and main question is: what is the correct fix to "tabHost.setCurrentTab(getIntent())" in the final line of OnCreate() in http://developer.android.com/resources/tutorials/views/hello-tabwidget.html?
The second and simpler question is: did I guess right in replacing 'mTabHost' with tabHost in the one place where that occurs?
Here's the problems and fixes for that particular tutorial:
Step 2: When creating your activities, if you do not create them through the manifest then you'll need to add them to the manifest manually.
Add these lines to AndroidManifest.xml:
<activity android:name=".AlbumsActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
</activity>
<activity android:name=".ArtistsActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
</activity>
<activity android:name=".SongsActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
</activity>
Step 3: You are only instructed to create the ic_tab_artists.xml file. You'll need to create one for ic_tab_songs.xml and ic_tab_albums.xml as well. You can just duplicate the ic_tab_artists.xml (or change the HelloTabView.java tab specs to use the artists.xml file for each tab).
Step 4: The third to last line under /res/layout/main has a typo (a ; instead of a :)
android:padding="5dp" />
</LinearLayout>
</TabHost>
Step 6: There is a typo that uses calls mTabHost instead of tabHost. Change it.
As already cited the getIntent() function on the last line isn't appropriate. I just call the tab based on it's id. eg:
tabHost.setCurrentTabByTag("albums");
At the Informal Android Meetup, I was able to confirm that my first guess was in the ballpark: the line as printed in the tutorial really is wrong, it should be replaced with something like, "tabHost.setCurrentTab(0); // was setCurrentTab(getIntent())".
There was one other major omission I had to fix before I could get the HelloTabWidget Tutorial to run: Albums|Artists|SongsActivity all had to be added to the manifest, manifest.xml. Somehow, the tutorial instructions managed to omit mention of this requirement.