Android app issue:
I have MainActivity that when you press a button it opens the camera (an OCR) via Intent and startActivity. The problem is when I press the button in my mobile the first time after the installation, it gets blocked.
Then, after the first time, it works perfect...
By the way, when I try to execute the app in the android emulator it gives me only one error: "error opening trace file: No such file or directory" I don't know if this error is related with my problem in the mobile.
Here is the intent of MainActivity
Button2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
try {
Intent i = new Intent(getApplicationContext(), CaptureActivity.class);
startActivityForResult(i, REQUEST_CODE);
} catch (Exception e) {
}
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) {
if (data.hasExtra("ocrResult")) {
EditText.setText(data.getExtras().getString("ocrResult"));
} else if (resultCode == RESULT_CANCELED) {
}
}
}
And here you have the code of the OCR that sends the result to MainActivity
public void onClick(View v) {
finish();
}
public void finish() {
Intent data = new Intent();
data.putExtra("ocrResult", ocrResultView.getText());
setResult(RESULT_OK, data);
super.finish();
}
Finally, the manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.sfsu.cs.orange.ocr"
android:installLocation="auto"
android:versionName="0.5.13"
android:versionCode="32"
>
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="13"/>
<supports-screens android:xlargeScreens="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.flash" android:required="false" />
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.screen.landscape"/>
<application android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<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=".CaptureActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden"
>
</activity>
<activity android:name="edu.sfsu.cs.orange.ocr.PreferencesActivity"> </activity>
</application>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</manifest>
Thank you very much!!
Related
I want to ask users to agree with the disclaimer that I have provided in my application, and then if they agreed, next time they are using the app, we just re-show them the disclaimer for a few seconds without asking to click on anything and redirect them to the application. The best way I could have come up with it was, using a custom permission and however I did add permission commands to my manifest I could not figure out how to actually activate the permission in my code:
import java.util.jar.Manifest;
public class Language extends Activity {
Button engBut, fraBut;
// public static int j;
public void click (View view){
// j=1;
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
}
public void fraClick (View view){
// j=2;
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_language);
ImageView logo = (ImageView) findViewById(R.id.logo);
ImageView montfortLogo = (ImageView) findViewById(R.id.montfortLogo);
montfortLogo.setImageResource(R.drawable.k);
logo.setImageResource(R.drawable.j);
engBut = (Button) findViewById(R.id.engBut);
engBut.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(Language.this);
builder.setCancelable(true);
builder.setTitle("DISCLAIMER");
builder.setMessage(R.string.result_disclaimer);
builder.setNegativeButton("Get me out of here.", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
});
builder.setPositiveButton("I agree.", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
intent.setAction("com.techideas4you.pharamacy.MyAction");
intent.addCategory("android.intent.category.DEFAULT");
startActivity(intent);
}
});
builder.show();
}
});
fraBut = (Button) findViewById(R.id.fraBut);
Log.i("Locale", String.valueOf(Locale.getDefault()));
}
}
This was my first page code.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.ex"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />
<permission android:name="testDisclaimer" android:label="DISCLAIMER"
android:description="#string/result_disclaimer"/>
<uses-permission android:name="testDisclaimer"/>
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:label="#string/app_name">
</activity>
<activity
android:name=".ActivityQuestion"
android:icon="#drawable/home"
android:label="Home"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".ActivityResult"
android:icon="#drawable/home"
android:label="Home"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity android:name=".Language">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter >
<action android:name="com.techideas4you.pharamacy.MyAction"
/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
and this is my manifest if anybody could help me out here I really appreciate it.
You have to add android:protectionLevel="dangerous" to the declaration of your permission else it will be granted automatically and users will not be presented with a dialog although you call requestPermission().
<permission android:name="your.package.name.permission.testDisclaimer" android:label="DISCLAIMER"
android:description="#string/result_disclaimer"
android:protectionLevel="dangerous"/>
<uses-permission android:name="your.package.name.permission.testDisclaimer"/>
In order to have the runtime show the disclaimer, you have to call
requestPermissions(new String[]{"your.package.name.permission.testDisclaimer"}, 42);
The result (whether user agreed) will be transmitted to you in onRequestPermissionsResult()
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults)
{
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 42 && grantResults != null){
Toast.makeText(this, "Permission " + permissions[0] + (grantResults[0] == PERMISSION_GRANTED ? "" : " NOT ") + " granted! ", Toast.LENGTH_LONG).show();
}
}
Please note that by using the permission system, you also have to cope with the fact that users will NOT be shown the permission-request-disguised-as-disclaimer if they
[...] turned down the permission request in the past and chose the
Don't ask again option in the permission request system dialog [...]
(quoted from documentation).
So maybe simply writing a flag to SharedPreferences will do the job just as well.
This is my code for reference. I have added the run time permission code and system granting the permission but again it gives an error:
Failed due to non declaration of following android.permission.SYSTEM_ALERT_WINDOW permission in Manifest file
public boolean checkDrawOverlayPermission()
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
{
return true;
}
if (!Settings.canDrawOverlays(this))
{
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, REQUEST_CODE);
return false;
}
else
{
return true;
}
}
#Override
#TargetApi(Build.VERSION_CODES.M)
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == REQUEST_CODE)
{
if (Settings.canDrawOverlays(this))
{
//startService(new Intent(this, PowerButtonService.class));
//Toast.makeText(this, "permission granted", Toast.LENGTH_SHORT).show();
if(!checkPermission())
{
requestPermission();
}
else
{
//Toast.makeText(this, "Phone State Permission Already Granted", Toast.LENGTH_SHORT).show();
//callBeacon();
}
}
}
}
Manifest File :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.adsl.beaconapp">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<!-- Declaration that this app is usable on phones with Bluetooth Low Energy. -->
<uses-feature
android:name="android.hardware.bluetooth_le"
android:required="true" />
<!-- Declaration permission for using internet -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<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:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/app_id" />
<!-- <activity android:name="com.facebook.LoginActivity" /> -->
<activity
android:name="com.beaconstreamsdk.com.MainActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" />
<service
android:name="com.beaconstreamsdk.com.service.BeaconService"
android:enabled="true"
android:exported="false" />
<service
android:name="com.beaconstreamsdk.com.service.FloatingHeadService"
android:enabled="true"
android:exported="false" />
<service
android:name="com.beaconstreamsdk.com.service.ConnectionService"
android:enabled="true"
android:exported="false" />
<activity
android:name="com.beaconstreamsdk.com.SignUpActivity"
android:screenOrientation="portrait" />
<activity android:name=".Main2Activity" />
<activity android:name=".BeaconStreamActivity"></activity>
</application>
</manifest>
onActivityResult :
#Override
#TargetApi(Build.VERSION_CODES.M)
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == REQUEST_CODE)
{
if (Settings.canDrawOverlays(this))
{
//startService(new Intent(this, PowerButtonService.class));
//Toast.makeText(this, "permission granted", Toast.LENGTH_SHORT).show();
if(!checkPermission())
{
requestPermission();
}
else
{
Toast.makeText(this, "Phone State Permission Already Granted", Toast.LENGTH_SHORT).show();
//callBeacon();
}
}
}
}
Please try this way. May be you are facing condition problem,
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M)
{
if (!Settings.canDrawOverlays(this))
{
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, REQUEST_CODE);
return false;
}
else
{
return true;
}
}else{
return true;
}
I capture photo and save into my Gallery. Everything works perfect when I capture an image and save. But if the camera is on and if I press the back button without taking a picture then the application stops.
How I can solve this issue?
This is my code:
public class ImportCard extends Activity {
private static final int CAMERA_PIC_REQUEST = 1111;
ImageButton importimage;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_import_card);
ImageButton importimage = (ImageButton) findViewById(R.id.importimage);
importimage.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_PIC_REQUEST);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
//2
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
//3
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
//4
File file = new File(Environment.getExternalStorageDirectory()+File.separator + "image.jpg");
try {
file.createNewFile();
FileOutputStream fo = new FileOutputStream(file);
//5
fo.write(bytes.toByteArray());
fo.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Android Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapcard"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera"
android:required="true" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/vcard"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.mapcard.Splash"
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.example.mapcard.Main"
android:label="#string/app_name" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.mapcard.NewCard"
android:label="#string/title_activity_new_card" >
</activity>
<activity
android:name="com.example.mapcard.ImportCard"
android:label="#string/title_activity_import_card">
</activity>
<activity
android:name="com.example.mapcard.CardBox"
android:label="#string/title_activity_card_box" >
</activity>
<activity
android:name="com.example.mapcard.QRCode"
android:label="#string/title_activity_new_card" >
</activity>
<activity
android:name="com.example.mapcard.Template"
android:label="#string/title_template" >
</activity>
<activity
android:name="com.example.mapcard.DisplayCard"
android:label="#string/title_display_card" >
</activity>
<activity
android:name="com.example.mapcard.GoogleMap"
android:label="#string/title_activity_google" >
</activity>
<activity
android:name="com.example.mapcard.ViewCard"
android:label="#string/title_view_card" >
</activity>
<activity
android:name="com.example.mapcard.QRScan"
android:label="#string/title_activity_import_card" >
</activity>
<activity
android:name="com.example.mapcard.ViewTemplates"
android:label="#string/title_view_templates" >
</activity>
<activity
android:name="com.example.mapcard.SendEmail"
android:label="#string/title_send_email" >
</activity>
</application>
Error in my LogCat:
java.lang.RuntimeException: Failure delivering result
Error on my device:
Unfortunately, App has stopped
You are checking only requestCode. You should check the value of resultCode also. When the user has successfully performed the action, the resultCode will be equal to RESULT_OK. If the user presses the back button then the resultCode will be RESULT_CANCELED. So your code must be modified like this.
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST && resultCode == RESULT_OK) {
//2
Add
android:noHistory="false"
in AndroidManifest.xml for that activity
In onActivityResult you should check whether thumbnail is null, and if so just return.
Edit: like this
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
...
Bundle extras = data.getExtras();
if (extras == null || extras.get("data") == null) return;
Bitmap thumbnail = (Bitmap) extras.get("data");
...
}
}
This is totally weird and I've searched through the forums.
In my main class I have a button onClick will launch the contacts application as shown below. When I click the button, he contacts list is shown but as soon as I tap on a contact a security exception is thrown.
public void selectContacts(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case PICK_CONTACT:
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
while (c.moveToNext()) {
String id = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
String phoneNumber = getPhoneNumber(id);
listOfContacts.add(phoneNumber);
}
} else {
System.out.println("User didn't pick a contact");
finish();
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
I've checked the manifest and have tried all combinations of placing the uses-permission tag, within the application, activity etc. But nothing works. Here's my manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.company.letsmeet"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<uses-permision android:name="android.permission.SEND_SMS" />
<uses-permision android:name="android.permission.RECEIVE_SMS" />
<uses-permision android:name="android.permission.INTERNET" />
<uses-permision android:name="android.permission.READ_CONTACTS" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".LetsmeetActivity"
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>
</manifest>
The security exception :
05-04 11:26:39.950: E/AndroidRuntime(3861): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.contacts/contacts/7 }} to activity {in.company.letsmeet/in.company.letsmeet.LetsmeetActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.SemcContactsProvider2 uri content://com.android.contacts/contacts/7 from pid=3861, uid=10093 requires android.permission.READ_CONTACTS
Any help will be greatly appreciated. I'm trying this on Android 2.1 Sony experia S10 mini.
So guess what, I added the READ_CONTACTS permission in the Manifest GUI and it works. God I wasted an entire day on this. Hope others don't have to.
Try out below code.That may be helpful to you -
public class PickDemo extends Activity {
private static final int PICK_REQUEST=1337;
private static Uri CONTENT_URI=null;
static {
int sdk=new Integer(Build.VERSION.SDK).intValue();
if (sdk>=5) {
try {
Class<?> clazz=Class.forName("android.provider.ContactsContract$Contacts");
CONTENT_URI=(Uri)clazz.getField("CONTENT_URI").get(clazz);
}
catch (Throwable t) {
Log.e("PickDemo", "Exception when determining CONTENT_URI", t);
}
}
else {
CONTENT_URI=Contacts.People.CONTENT_URI;
}
}
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (CONTENT_URI==null) {
Toast
.makeText(this, "We are experiencing technical difficulties...",
Toast.LENGTH_LONG)
.show();
finish();
return;
}
setContentView(R.layout.main);
Button btn=(Button)findViewById(R.id.pick);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent i=new Intent(Intent.ACTION_PICK, CONTENT_URI);
startActivityForResult(i, PICK_REQUEST);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode==PICK_REQUEST) {
if (resultCode==RESULT_OK) {
startActivity(new Intent(Intent.ACTION_VIEW,
data.getData()));
}
}
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest android:versionCode="1"
android:versionName="1.0"
package="com.commonsware.android.contacts.pick"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="3"
android:targetSdkVersion="6" />
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="false" />
<application android:icon="#drawable/cw"
android:label="#string/app_name">
<activity android:label="#string/app_name"
android:name=".PickDemo">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And, just refer Commonsware's example. Hope this helps you.
KitActivity:
/** in KitActivity, handler invoked after successful transmission **/
private final Handler txHandle = new Handler() {
#Override
public void handleMessage(Message msg) {
boolean success = msg.getData().getBoolean("success");
dismissDialog(DIALOG_TX_PROGRESS);
if(success) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putInt("previous_scale", mScaleSpn.getSelectedItemPosition());
editor.commit();
//clearFields();
//showDialog(DIALOG_ETX);
KitActivity.this.setResult(0);
KitActivity.this.finish();
} else {
removeDialog(DIALOG_FAIL);
showDialog(DIALOG_FAIL);
}
}
};
MainActivity:
/** in the MainActivity **/
public void startCreateKit() {
Intent i = new Intent(MainActivity.this, KitActivity.class);
startActivityForResult(i,0);
}
protected void onActivityResult(int reqCode, int resCode) {
if(reqCode==0) {
if(resCode==0) {
//we good, perform sync
showDialog(DIALOG_TX_PROGRESS);
Toast.makeText(this, "Performing Auto Sync", Toast.LENGTH_LONG).show();
updateKits();
} else {
//uh oh
}
}
}
createKitBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Toast.makeText(context, "NEW KIT", Toast.LENGTH_SHORT).show();
startCreateKit();
}
});
onActivityResult is never called in MainActivity. this is pretty much by the book. what's the issue?
stuff i've tried:
- using Activity.RESULT_OK for the result code (which translates to -1);
- removing the setResult() and finish() calls from the handler and calling an outside method to invoke them.
i don't see anything wrong. here's the manifest, nothing awry here:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.conceptualsystems.kitmobile"
android:versionCode="8"
android:versionName="#string/version">
<application android:label="#string/app_name" android:icon="#drawable/icon" android:debuggable="true">
<activity android:name="MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="ShipActivity"
android:label="Ship Kits"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation">
</activity>
<activity android:name="KitActivity"
android:label="Kit Entry"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation">
</activity>
<activity android:name="ColorActivity"
android:label="Color Selection"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation">
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
what gives?
in the activity you start (KitActivity.class) on success you do this
Intent intent = this.getIntent();
intent.putExtra("SOMETHING", "EXTRAS");
this.setResult(RESULT_OK, intent);
finish();
else you put RESULT_CANCELED instead of RESULT_OK
replaced:
protected void onActivityResult(int reqCode, int resCode)
with:
protected void onActivityResult(int reqCode, int resCode, Intent intent)
amazing what happens when you review the documentation... -_-