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.
Related
#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 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>
I'm calling a Contact Picker from an activity named AddFriendActivity. Once a contact is picked, it always returns to the MainActivity rather than the calling activity.
I have checked the android manifest and I can't see any tags that would cause it to prefer MainActivity on resumption. I've extracted (what I think is) the relevant code below.
AndroidManifest.xml
<activity
android:name="x.MainActivity"
android:label="#string/activity_main_title" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="x.start.StartActivity"
android:label="#string/start_activity_title"
android:noHistory="true" >
</activity>
<activity
android:name="x.policies.PoliciesActivity"
android:label="#string/activity_policies_title" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="x" />
<activity
android:name="x.AddFriendActivity"
android:label="#string/title_activity_add_friend"
android:parentActivityName="x.friendster.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="MainActivity" />
</activity>
Code for starting the contact picker from AddFriendActivity
btnContacts.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
Intent contactpicker = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
startActivityForResult(contactpicker, 1);
Log.e("contactpicker", "meh start");
}
});
Not sure if this is relevant, but here's the code that calls the AddFriendActivity from a fragment ChatPanel in MainActivity
btnAddFriend.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
Intent intent = new Intent(getActivity(), AddFriendActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
}
});
Any idea why this is happening? I've probably missed something simple...
remove line intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
from your OnClickListener and see if it works.
Cheers
I'm feeling stupid.This is very clear but I can not solve my problem.So excuse me for my question.
My problem is in about intenfilter.This is application tag of my manifest file:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".AlakyTestActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="reza"
android:name=".A2" >
<intent-filter >
<action android:name="MAIN" />
<category android:name="LAUNCHER" />
</intent-filter>
</activity>
</application>
And this is my button click listener:
b1 = (Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent2 = new Intent();
intent2.setAction("MAIN");
intent2.addCategory("LAUNCHER");
startActivity(intent2);
}
});
I think that all things is good but when I run my code and click on b1,I get this erroe:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=MAIN cat=[LAUNCHER] }
Edit:
This is A2:
public class A2 extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main2);
}
}
Please help me.
You should set the android:name of the second activity to the (package name).(the class)
for example, lets say the second activity class is 'com.my.app.reza' you should add you the manifest:
<activity
android:label="#string/app_name"
android:name=".reza" >
<intent-filter >
<action android:name="com.my.app.REZA" />
<category android:name="android.intent.category.DEFUALT" />
</intent-filter>
</activity>
and you should start the activity like that:
Intent intent = new Intent("com.my.app.REZA");
startActivity(intent);
NOTE that it isn't the best way to do it, you shouldn't mess to much with package name I'd recommend you to do it the following way:
<activity
android:label="#string/app_name"
android:name=".reza" />
and start it like that:
startActivity(new Intent( this.getContext() , reza.class );
Please use like that:
Intent intent2 = new Intent(context,A2.class);
startActivity(intent2);
android:name=".A2" ,you must have "A2" activity class implement!
Modify to android:name=".A2", not android:name="A2"!
You don't need to specify category if you just need to call A2 inside your app. And you should set an unique action name, for example it can be a hash string:
...
Intent intent2 = new Intent("a202bfa923069ee8e119205e3468ee131ceafda37");
startActivity(intent2);
Note that action name uses same rule as package name.
<intent-filter>
<action android:name="com.blacky.basictutorial.TutorialTwo" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Try to use this in your second activity and call by the following code:
startActivity(new Intent("com.blacky.basictutorial.TutorialTwo"));
Hope this will work for you.
How can I start an Activity without using an Intent? The only rule I have got is
if( var == true ) startActivity();
but startActivity(); needs an Intent as a parameter.
Just create a new intent for the activity you want to start. depending on where you are you will need the app context thought.
Intent i = new Intent(getApplicationContext(), YourActivity.class);
startActivity(i);
Here's how to navigate to a second Activity (another page) using an Intent.
public void onClick(View v)
{
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);
}
Also, don't forget to adjust the AndroidManifest.xml for each Activity.
<application android:label="#string/app_name" android:icon="#drawable/ic_launcher">
<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>
</activity>
<activity android:name="SecondActivity"
android:label="#string/second_label">
<intent-filter>
<action android:name="android.intent.action.SECOND" /> //should be namespace of your company I guess
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>