How do I fix Android Image Capture App Crashes - java

I'm not sure what is going on. I click the button to take the image and my app closes.
I'm attempting to make an app to capture and use an image. I haven't even been able to capture the image.
I get the following message in log cat:
FATAL EXCEPTION: main
Process: com.example.fixmyphysics, PID: 23526
java.lang.IllegalArgumentException: Missing android.support.FILE_PROVIDER_PATHS meta-data
at androidx.core.content.FileProvider.parsePathStrategy(FileProvider.java:613)
at androidx.core.content.FileProvider.getPathStrategy(FileProvider.java:579)
at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:417)
at com.example.fixmyphysics.MainActivity.dispatchPictureTakerAction(MainActivity.java:67)
at com.example.fixmyphysics.MainActivity.access$000(MainActivity.java:27)
at com.example.fixmyphysics.MainActivity$1.onClick(MainActivity.java:44)
at android.view.View.performClick(View.java:7356)
at android.widget.TextView.performClick(TextView.java:14230)
at android.view.View.performClickInternal(View.java:7322)
at android.view.View.access$3200(View.java:846)
at android.view.View$PerformClick.run(View.java:27804)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7073)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
MainActivity.java
package com.example.fixmyphysics;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;
import android.Manifest;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import static android.os.Environment.getExternalStoragePublicDirectory;
public class MainActivity extends AppCompatActivity {
Button picture_btn;
ImageView display;
String pathToFile;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
picture_btn = findViewById(R.id.capture_image);
if (Build.VERSION.SDK_INT >=23){
requestPermissions(new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 2);
}
picture_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dispatchPictureTakerAction();
}
});
display = findViewById(R.id.imageView4);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == RESULT_OK) {
Bitmap imageBitmap = BitmapFactory.decodeFile(pathToFile);
display.setImageBitmap(imageBitmap);
}
}
private void dispatchPictureTakerAction(){
Intent takePic = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePic.resolveActivity(getPackageManager()) !=null){
File photoFile = null;
photoFile = createImageFile();
if (photoFile != null){
pathToFile = photoFile.getAbsolutePath();
Uri photoURI = FileProvider.getUriForFile(MainActivity.this, "com.fixmyphysics.FileProvider", photoFile);
takePic.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePic, 1);
}
}
}
private File createImageFile() {
String name = new SimpleDateFormat("yyyyMMdd__HHmmss").format(new Date());
File storageDir = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File image = null;
try {
image = File.createTempFile(name,".jpg", storageDir);
} catch (IOException e){
Log.d("mylog", "Excep : " + e.toString());
}
return image;
}
}
AndroidMainifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fixmyphysics">
<uses-feature android:name="android.hardware.camera" android:required="true" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths">
</meta-data>
</provider>
</application>
</manifest>

Try this one.
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />`enter code here`

Related

why can't i get my call recording app to work?

I'm trying to implement an app that allows me to record the audio of calls, activating the service via a toggle button. I can't figure out what is wrong with my code as once I set the toggle button to ON and initiate the call, there is no file saved.
I don't understand if the problem is in saving (maybe I'm looking for the file in the wrong directory?), Or in the fact that it doesn't actually record.
I'm using AndroidStudio 4.0 and i'm trying my app on my Samsung S9.
Thanks in andvance for helping !
RecordService.java
package com.example.registrachiamate;
import android.app.MediaRouteButton;
import android.app.Service;
import android.content.Intent;
import android.media.MediaRecorder;
import android.os.Environment;
import android.os.IBinder;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.text.format.DateFormat;
import java.io.File;
import java.io.IOException;
import java.util.Date;
public class RecordService extends Service {
private MediaRecorder rec;
private File file;
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
//return super.onStartCommand(intent, flags, startId);
file= Environment.getExternalStorageDirectory();
Date date=new Date();
CharSequence sdf= DateFormat.format("MM-dd-yy-hh-mm--ss",date.getTime());
rec=new MediaRecorder();
rec.setAudioSource(MediaRecorder.AudioSource.MIC);
rec.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
rec.setOutputFile(file.getAbsolutePath()+"/"+sdf+"rec.3gp");
rec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
TelephonyManager manager=(TelephonyManager) getApplicationContext().getSystemService(getApplicationContext().TELEPHONY_SERVICE);
assert manager != null;
manager.listen(new PhoneStateListener(){
#Override
public void onCallStateChanged(int state, String phoneNumber) {
//super.onCallStateChanged(state, phoneNumber) {
if (TelephonyManager.CALL_STATE_IDLE==state){
rec.stop();
rec.reset();
rec.release();
stopSelf();
}else if(TelephonyManager.CALL_STATE_OFFHOOK==state && rec==null){
try {
rec.prepare();
} catch (IOException e) {
e.printStackTrace();
}
rec.start();
}
}
},PhoneStateListener.LISTEN_CALL_STATE);
return START_STICKY;
}
}
ActivityButton1.java
package com.example.registrachiamate;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import android.widget.ToggleButton;
import androidx.appcompat.app.AppCompatActivity;
public class ActivityButton1 extends AppCompatActivity {
ToggleButton startandoff;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.button1);
startandoff=(ToggleButton)findViewById(R.id.toggleButton);
}
public void tooglebutton(View view)
{
boolean checked=((ToggleButton)view).isChecked();
if (checked){
Intent intent=new Intent(this,RecordService.class);
startService(intent);
Toast.makeText(getApplicationContext(),"Call Record STARTED",Toast.LENGTH_SHORT).show();
}else {
Intent intent=new Intent(this,RecordService.class);
stopService(intent);
Toast.makeText(getApplicationContext(),"Call Record STOPPED",Toast.LENGTH_SHORT).show();
}
}
}
AndroidManifest.xml, if i put the RecordService, in it stops running
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.registrachiamate">
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<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"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
<action android:name="android.intent.action.PHONE_STATE"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ActivityButton1"></activity>
<activity android:name=".ActivityButton2"></activity>
<activity android:name=".ActivityButton3"></activity>
<activity android:name=".ActivityButton4"></activity>
<activity android:name=".RecordService"></activity>
</application>
</manifest>

onActivityResult is not getting called in MainActivity.Java

I am trying to make an app which shows a user selected image which can be set by double-clicking on the button. The app does ask me for an image (which is good) but I don't know how to set it on ImageView if this onActivityResult is not getting called.
MainActivity:
package com.forever.bobby.cheater20;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import com.tomerrosenfeld.customanalogclockview.CustomAnalogClock;
public class MainActivity extends AppCompatActivity {
private static final int PICK_IMAGE = 100;
Button hiddenOnClickListener;
ImageView img;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = findViewById(R.id.imageView);
CustomAnalogClock customAnalogClock = (CustomAnalogClock) findViewById(R.id.analog_clock);
customAnalogClock.setAutoUpdate(true);
hiddenOnClickListener = (Button) findViewById(R.id.touchButtonHidden);
hiddenOnClickListener.setOnClickListener(new DoubleClickListener() {
#Override
public void onSingleClick(View v) {
Log.e ("mPressesOnce -_-","..");
}
#Override
public void onDoubleClick(View v) {
Log.e ("mPressesTwice -_-","..");
openGallery();
}
});
}
private void openGallery () {
Intent gallery = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, 0);
}
#Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode,data);
Log.e ("SHould Be Steeted","");
if (requestCode == 0) {
Uri imgUri;
imgUri = data.getData();
// img.setImageURI(imgUri);
}
}
}
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.forever.bobby.cheater20">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Any Kind of help is appreciated as I am a newbie
With android sdk >= 23, some permissions e.g. WRITE_EXTERNAL_STORE, READ_EXTERNAL_STORE, etc. you must request it in java code.
Therefore, when user starts using feature need permission, android will show a dialog and user can grant or cancel a permission. You can read more about it on developer.android.com.

Sharing Image Using Intent on whats app getting error sharing failed

I am loading single jpg image from drawable folder set file provider permission in manifest but when i share image on whatsapp i got error sharing failed please try again.When i share text it works fine but when i tried to share image it gives me error.Here is following files
Fullscreenadapter.java
package com.mobdev.birthdaycakesquotes;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Environment;
import android.support.v4.app.ShareCompat;
import android.support.v4.content.FileProvider;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class Fullscreenadapter extends PagerAdapter {
private Integer[] Image;
private int _resource;
private Activity _activity;
private LayoutInflater inflater;
private String images;
TextView t1,t2;
public Fullscreenadapter(Activity activity,
Integer[] image) {
this._activity = activity;
this.Image=image;
}
#Override
public int getCount() {
return this.Image.length;
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == ((RelativeLayout) object);
}
#Override
public Object instantiateItem(ViewGroup container, final int position) {
final ImageView imgDisplay,shareimage;
inflater = (LayoutInflater) _activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View viewLayout = inflater.inflate(R.layout.fullscreenlayoutdesign,
container,
false);
imgDisplay = (ImageView) viewLayout.findViewById(R.id.show);
shareimage=(ImageView)viewLayout.findViewById(R.id.share);
t1=(TextView)viewLayout.findViewById(R.id.currentposition);
t2=(TextView)viewLayout.findViewById(R.id.totalimage);
imgDisplay.setImageResource(Image[position]);
t1.setText(String.valueOf(position));
t2.setText(String.valueOf(Image.length));
images=createImageOnSDCard(R.drawable.sw);
shareimage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Uri path = FileProvider.getUriForFile(_activity,
"com.mobdev.birthdaycakesquotes",new File(images));
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "This is one image I'm
sharing.");
shareIntent.putExtra(Intent.EXTRA_STREAM, path);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setType("image/*");
_activity.startActivity(Intent.createChooser(shareIntent,
"Share..."));
}
});
((ViewPager) container).addView(viewLayout);
return viewLayout;
}
private String createImageOnSDCard(int resID) {
Bitmap bitmap = BitmapFactory.decodeResource(Resources.getSystem(), resID);
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/" + resID + ".jpg";
File file = new File(path);
try {
OutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
return file.getPath();
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((RelativeLayout) object);
}
}
AndroidManifestfile
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mobdev.birthdaycakesquotes">
<application
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
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>
<activity
android:name=".HomePage"
android:label="#string/title_activity_home_page"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" />
<activity android:name=".Details_activity"></activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.mobdev.birthdaycakesquotes"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
</application>
file_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="." />
</paths>
private void shareImage(Uri imagePath) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, imagePath);
//sharingIntent.setPackage("com.whatsapp"); for whatsapp only
startActivity(Intent.createChooser(sharingIntent, "Share Image Using"));// for all generic options
}
Finaly in your manifest Add this without fail
<activity
android:name=".YourActivity"
android:icon="#drawable/share_this"
android:label="#string/shared_activity" >
<intent-filter>
<action android:name="android.intent.action.SEND" /> <!-- Send
action required to display activity in share list -->
<category android:name="android.intent.category.DEFAULT" /> <!--
Make activity default to launch -->
<!-- Mime type i.e. what can be shared with this activity only image and text -->
<data android:mimeType="image/*" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>
This will owrk
ArrayList<Uri> uriArrayList = new ArrayList<>();
uriArrayList.add(getUriFromFile(your file path))
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.setType("image/*");
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, myFilesUriList);
startActivity(intent);
public Uri getUriFromFile(File theSrcPath) {
Uri requirdUri = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
requirdUri = FileProvider.getUriForFile(theCtx,
theCtx.getApplicationContext().getPackageName() + PROVIDER_FILE_EXTENSION,
theSrcPath);
} else {
requirdUri = Uri.fromFile(theSrcPath);
}
}

Android Permission not Applying

Hope You all having a good day, I am learning android and i'm creating an application that scans for Wifi networks. The code makes sense and i seem to have the permissions correctly yet no permissions are being requested at all. Could you help me to figure out why aren't the permissions being granted? Am I missing anything ? Here is my code:
main activity.java:
package com.example.x.wifilocator;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.List;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private StringBuilder sb = new StringBuilder();
private TextView tv;
List<ScanResult> scanList;
final private int REQUEST_CODE_ASK_PERMISSIONS = 123;
#RequiresApi(api = Build.VERSION_CODES.M)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv= (TextView)findViewById(R.id.txtWifiNetworks);
checkpermission();
}
#RequiresApi(api = Build.VERSION_CODES.M)
private void checkpermission() {
int hasWiFi = checkSelfPermission(Manifest.permission.ACCESS_WIFI_STATE);
if (hasWiFi != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[] {Manifest.permission.ACCESS_WIFI_STATE},
REQUEST_CODE_ASK_PERMISSIONS);
Toast.makeText(this,"No Permission",Toast.LENGTH_LONG);
}
getWifiNetworksList();
}
private void getWifiNetworksList(){
IntentFilter filter = new IntentFilter();
filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
final WifiManager wifiManager =
(WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);;
registerReceiver(new BroadcastReceiver(){
#SuppressLint("UseValueOf") #Override
public void onReceive(Context context, Intent intent) {
sb = new StringBuilder();
scanList = wifiManager.getScanResults();
sb.append("\n Number Of Wifi connections :" + " " +scanList.size()+"\n\n");
for(int i = 0; i < scanList.size(); i++){
sb.append(new Integer(i+1).toString() + ". ");
sb.append((scanList.get(i)).toString());
sb.append("\n\n");
}
tv.setText(sb);
}
},filter);
wifiManager.startScan();
}
}
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<!--Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Thanks in advance for your efforts.

Java.lang.securityException: Permission Denial: starting Intent

I'm constantly getting a security exception when trying to launch a different activity other than my MainActivity, code works fine when i'm launching my MainActivity but throws an exception when I try to launch any other activity other than MainActivity, I've been looking for answers and got a solution to put -android:exported="true"- in my Manifest, however this doesn't help the problem i'm facing, any help so far will be highly appreciated.
Manifest file for launching MainActivity - (Which works)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.infamuspips.cess">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:exported="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".registration"
android:label="#string/app_name"></activity>
<activity
android:name=".reg_name"
android:label="#string/app_name"></activity>
<activity
android:name=".reg_securityquestions"
android:label="#string/app_name"></activity>
<activity
android:name=".reg_id"
android:label="#string/app_name"></activity>
<activity
android:name=".reg_cellnumber"
android:label="#string/app_name"></activity>
<activity
android:name=".reg_email"
android:label="#string/app_name"></activity>
<activity
android:name=".reg_password"
android:label="#string/app_name"></activity>
<activity
android:name=".Maindrawer"
android:label="#string/title_activity_maindrawer"
android:theme="#style/AppTheme"></activity>
</application>
</manifest>
.
Manifest file for launching registration Activity - (Which don't work)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.infamuspips.cess">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:exported="true"
android:theme="#style/AppTheme">
<activity android:name=".registration">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name"></activity>
<activity
android:name=".reg_name"
android:label="#string/app_name"></activity>
<activity
android:name=".reg_securityquestions"
android:label="#string/app_name"></activity>
<activity
android:name=".reg_id"
android:label="#string/app_name"></activity>
<activity
android:name=".reg_cellnumber"
android:label="#string/app_name"></activity>
<activity
android:name=".reg_email"
android:label="#string/app_name"></activity>
<activity
android:name=".reg_password"
android:label="#string/app_name"></activity>
<activity
android:name=".Maindrawer"
android:label="#string/title_activity_maindrawer"
android:theme="#style/AppTheme"></activity>
</application>
</manifest>
.
Here's my MainActivity Class
package com.infamuspips.cess;
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.test.suitebuilder.annotation.Suppress;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.InvalidParameterSpecException;
import java.util.ArrayList;
import java.util.List;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.SecretKeySpec;
import javax.net.ssl.HttpsURLConnection;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "Encryption";
EditText editText,username,password;
Button button;
TextView cancel,forgot_password;
static String Username = null;
static String PassWord = null;
static String GetUsername = null;
static String GetPassword = null;
SecretKey secretKey;
String cipherText, decryptedText;
KeyGenerator keyGen;
Cipher aesCipher;
FileOutputStream fos;
byte[] byteDataToEncrypt, byteCipherText, byteDecryptedText;
TextWatcher textwatcher = new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String User = username.getText().toString();
String Pass = password.getText().toString();
if (!User.isEmpty() && !Pass.isEmpty()) {
button.setEnabled(true);
} else {
button.setEnabled(false);
}
}
#Override
public void afterTextChanged(Editable s) {
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
editText = (EditText) findViewById(R.id.editText);
username.addTextChangedListener(textwatcher);
password.addTextChangedListener(textwatcher);
button = (Button) findViewById(R.id.logIn);
cancel = (TextView) findViewById(R.id.LoginCancel);
forgot_password = (TextView) findViewById(R.id.forgot_password);
//Set Clickable attributes
cancel.setClickable(true);
button.setEnabled(false);
editText.setEnabled(false);
//Call Operation Methods
username.requestFocus();
//Cancel();
//Forgot_Password();
Log_In();
}
private void Cancel(){
cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),registration.class);
startActivity(i);
}
});
}
private void Forgot_Password(){
forgot_password.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
class PerformBackGround extends AsyncTask<Void, Void, String>{
private ProgressDialog mDialog;
public PerformBackGround() {
super();
}
#Override
protected void onPreExecute() {
super.onPreExecute();
mDialog = new ProgressDialog(MainActivity.this);
mDialog.setMessage("Please wait");
mDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mDialog.setProgress(0);
mDialog.setMax(10);
mDialog.setCancelable(false);
mDialog.show();
}
#Override
protected String doInBackground(Void... params) {
try{
String link = "http://*************************";
URL url = new URL(link);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String result = bufferedReader.readLine();
return result;
}catch (Exception e){
return "Exception" + e.getMessage();
}
}
#Override
protected void onPostExecute(String result) {
String jsonStr = result;
String response;
if (jsonStr != null){
try{
JSONObject jsonObj = new JSONObject(jsonStr);
String User = jsonObj.get("name").toString();
String Password = jsonObj.get("surname").toString();
mDialog.cancel();
if (User.equals(Username) && Password.equals(PassWord)){
//String name = jsonObj.get("name").toString();
//String Surname = jsonObj.get("surname").toString();
response = jsonObj.get("surname").toString();
getResponse(response);
Intent i = new Intent(getApplicationContext(),Maindrawer.class);
startActivity(i);
}else{
response = "invalid";
getResponse(response);
}
}catch (Exception e){
mDialog.cancel();
e.printStackTrace();
response = "unable";
getResponse(response);
}
}else{
mDialog.cancel();
response = "unconnect";
getResponse(response);
}
}
}
private void Log_In(){
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//PerformBackGround bg = new PerformBackGround();
username = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
String user = username.getText().toString();
String pass = password.getText().toString();
Username = user;
PassWord = pass;
//addmodules addm =new addmodules();
//addm.execute();
Toast.makeText(MainActivity.this, md5(username.getText().toString()), Toast.LENGTH_SHORT).show();
Intent i = new Intent(getApplicationContext(),Maindrawer.class);
startActivity(i);
username.getText().clear();
password.getText().clear();
}
});
}
public String md5(String text) {
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(text.getBytes());
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuffer hexString = new StringBuffer();
for (int i=0; i<messageDigest.length; i++)
hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
}
}
Here's my registration Activity - (Which doesn't launch & throws an exception
)
package com.infamuspips.cess;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
/**
* Created by Rebone on 4/24/2016.
*/
public class registration extends AppCompatActivity {
EditText up, firstname, MidName, lastName,Email,id,password, confirmpassword;
Button logIn, Register;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.registration);
up = (EditText) findViewById(R.id.editText1);
logIn = (Button) findViewById(R.id.reg_login);
Register = (Button) findViewById(R.id.reg_register);
up.setEnabled(false);
Register.setEnabled(true);
LogIn();
Register();
}
public void LogIn() {
logIn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), MainActivity.class);
startActivity(i);
}
});
}
public void Register() {
Register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String initial = "Nothing";
//Modified
Intent a = new Intent(v.getContext(),reg_name.class);
//Intent a = new Intent(v.getContext(),reg_password.class);
a.putExtra("Results", initial);
startActivity(a);
}
});
}
}
-
And here's the full stack trace
08-09 13:59:52.444 220-10439/? W/ActivityManager: mDVFSLock.acquire()
08-09 13:59:52.444 220-10439/? W/ActivityManager: Permission denied: checkComponentPermission() owningUid=10118
08-09 13:59:52.444 220-10439/? W/ActivityManager: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.infamuspips.cess/.registration } from null (pid=13769, uid=2000) not exported from uid 10118
08-09 13:59:52.460 220-10439/? W/System.err: at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:2498)
08-09 13:59:52.460 220-10439/? W/System.err: at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:3095)
08-09 13:59:52.460 220-10439/? W/System.err: at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:2298)
08-09 13:59:52.460 220-10439/? W/System.err: at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:147)
08-09 13:59:52.460 220-10439/? W/System.err: at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:1603)
08-09 13:59:52.460 220-10439/? W/System.err: at android.os.Binder.execTransact(Binder.java:338)
08-09 13:59:52.460 220-10439/? W/System.err: at dalvik.system.NativeStart.run(Native Method)
Replace
<activity android:name=".registration">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
with
<activity android:name="com.infamuspips.cess.registration">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
Clean and rebuild your project

Categories

Resources