Moving a file from one computer into other computer - java

I am a really really new developer. I am currently work a BLE stuff with my friend, but we always have an issue to move my project into his computer, and his project move to my computer.
He does not like to use GitHub at all, me too actually, so we want to just use flash drive to transfer the project folder.(this is the way I found from stackoverflow.com)
I always have errors, and this transfer folder way never work as we respect.
Most of question from "Cannot resolve symbol 'R' such as:
setContentView(R.layout.activity_main);
I already look up online, and most of people just say "clean project", but it does not work at all.
Some of people said, activity_main.xml has problem, but I cant find the problem.
MainActivity.java
package test.research.sjsu.beaconbroadcast;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.bluetooth.le.AdvertiseCallback;
import android.bluetooth.le.AdvertiseData;
import android.bluetooth.le.AdvertiseSettings;
import android.bluetooth.le.BluetoothLeAdvertiser;
import android.content.Context;
import android.os.Bundle;
import android.os.ParcelUuid;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import java.util.UUID;
public class MainActivity extends AppCompatActivity {
BluetoothManager mBluetoothManager;
BluetoothAdapter mBluetoothAdapter;
BluetoothLeAdvertiser mBluetoothLeAdvertiser;
AdvertiseData mAdvertiseData;
AdvertiseData.Builder mAdvertiseDataBuilder = new AdvertiseData.Builder();
byte[] Data = new byte[4];
ParcelUuid mServiceDataUUID;
AdvertiseSettings mAdvertiseSettings;
AdvertiseSettings.Builder mAdvertiseSettingBuilder = new AdvertiseSettings.Builder();
Button BroadcastButton;
Button StopBroadcastButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = mBluetoothManager.getAdapter();
mBluetoothLeAdvertiser = mBluetoothAdapter.getBluetoothLeAdvertiser();
Data = hexStringToByteArray("abcdefgh");
mServiceDataUUID = ParcelUuid.fromString(UUID.randomUUID().toString());
mAdvertiseDataBuilder.setIncludeDeviceName(true);
mAdvertiseDataBuilder.setIncludeTxPowerLevel(true);
mAdvertiseData = mAdvertiseDataBuilder.build();
mAdvertiseDataBuilder.addServiceData(mServiceDataUUID,Data);
mAdvertiseSettingBuilder.setAdvertiseMode(1);
mAdvertiseSettingBuilder.setTimeout(0);
mAdvertiseSettingBuilder.setTxPowerLevel(2);
mAdvertiseSettingBuilder.setConnectable(true);
mAdvertiseSettings = mAdvertiseSettingBuilder.build();
BroadcastButton = (Button) findViewById(R.id.BroadcastButton);
BroadcastButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startAdvertise();
}
});
StopBroadcastButton = (Button) findViewById(R.id.StopBraodcastButton);
StopBroadcastButton.setVisibility(View.INVISIBLE);
StopBroadcastButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
stopAdvertise();
}
});
}
Here is my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.research.sjsu.beaconbroadcast">
android:versionCode="1"
android:versionName="1.0"
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
<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>
Sometime there are other red lines, but now the R problem just make me crazy.

Related

Android studio - some of the interpolator animations not working

I am trying to apply animations to my project, when I set the interpolator to:
alpha.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/bounce_interpolator">
<alpha android:fromAlpha="0"
android:toAlpha="1"
android:duration="4000"
/>
</set>
SplashActivity.java:
package com.example.animationtesting;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
public class SplashActivity extends AppCompatActivity {
ImageView imageView;
TextView textView;
Animation alpha;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
imageView = findViewById(R.id.imageView);
textView = findViewById(R.id.textView);
alpha = AnimationUtils.loadAnimation(this,R.anim.alpha);
imageView.setAnimation(alpha);
textView.setAnimation(alpha);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(SplashActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
},4000);
}
}
Android Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AnimationTesting"
tools:targetApi="31">
<activity
android:name=".SplashActivity"
android:exported="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
The code is working fine when I set the interpolator as bounce_interpolator, accelerate_interpolator, anticipate_overshoot_interpolator but when I set the interpolator to other options like fade_in, fade_out,slide_out_right my app crashes. I don't get why this is happening.
First I thought your app crashed because you try to put the animation on two different xml-objects, but then I replicated the entire thing using this guide and for me, everything is working. (Although I did it using Kotlin).
I'm sorry, the only solution I could provide was this URL to the guide, but if you have any more questions, feel free to ask!

Missing permissions required by FusedLocationClient

I'm working on getting an app to get GPS location from a phone. I have added permissions to the XML for ACCESS_COURSE_LOCATION but it is still saying that I need permissions for that, even though the permission is already in the XML.
Here's my code:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.location.Location;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.tasks.OnSuccessListener;
public final class MainActivity extends AppCompatActivity {
public static final String TAG = "Kindness";
private FusedLocationProviderClient mFusedLocationClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(
this);
mFusedLocationClient.getLastLocation().addOnSuccessListener(this,
new OnSuccessListener<Location>() {
#Override
public void onSuccess(Location location) {
if (location != null) {
}
}
});
}
}
And here's the XML:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.byui.cit.kindness">
<uses-permission android:name="android.permisison.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/appName"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name="edu.byui.cit.kindness.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
This is likely because location permissions are considered "dangerous" permissions by Android, and when your application's target SDK is 23 or greater, you are required to ask for "dangerous" permissions at runtime. Just adding them to the manifest does not work.
ActivityCompat.requestPermissions(this,
arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION),
REQUEST_CODE);

androidstudio mediaplayer can't find my file

I'm trying to create an application that has a button. If you press that button, a song called Test.mp3 will play. I copied the song with the exact name and file type to the directory, but it always show that the file was not found. I have tried plenty of things including copying the song to different directories, and changing directories, but no luck. here is what i have right now:
package com.example.lenovo.myapplication69;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.io.File;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
Button bt;
MediaPlayer mediaPlayer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt = (Button) findViewById(R.id.button);
bt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC),"Test.mp3");
String media_path = String.valueOf(f);
Toast.makeText(getApplicationContext(),media_path,Toast.LENGTH_LONG).show();
Uri uri = Uri.parse(media_path);
try {
mediaPlayer.setDataSource(getApplicationContext(),uri);
mediaPlayer.prepare();
mediaPlayer.start();
Toast.makeText(getApplicationContext(),"Playback started",Toast.LENGTH_LONG).show();
bt.setEnabled(false);
} catch (IOException e) {
Toast.makeText(getApplicationContext(),"error ",Toast.LENGTH_LONG).show();
e.printStackTrace();
}
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
bt.setEnabled(true);
mediaPlayer.release();
mediaPlayer = null;
Toast.makeText(getApplicationContext(),"Playback finished", Toast.LENGTH_LONG).show();
}
});
}
});
}
}
and here is what I have in my android manifest. Yeah I know a lot of useless permissions, but whatever.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lenovo.myapplication69">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.READ"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
<uses-permission android:name="android.permission.READ_PHONE_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>

SMS Broadcast Receiver not working

Alright, I have tried every solution on Stack and nothing works.My current method registers the "SmsListener" receiver from the MainActivity. All I'm trying to do is initialize the onReceive method. There are no errors; It simply isn't picking up a broadcast. What am I doing wrong? Pasting the applicable code here. Anything else that may be needed please just ask.
Update:
Here is a similar unresolved issue
Listen Android incoming SMS when Google Hangout or other app receives it
I am testing under Android 6.0.1. Target Sdk version is 22. Min Sdk is 19. It's worth noting that I just tested my original code on an LG Optimus GPro with Android 4.4.2 and it worked. It still isn't working on my Nexus with Android 6.0.1.
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.biapps.makin_biscuits">
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<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" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"/>
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action `android:name="android.service.notification.NotificationListenerService" />`
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ContactsList">
<intent-filter>
<category android:name="android.intent.category.ALTERNATIVE" />
</intent-filter>
</activity>
<receiver
android:name=".SmsListener"
android:priority="999"
android:enabled="true"
android:exported="true">
</receiver>
<receiver
android:name=".IncomingCallReceiver"
android:enabled="true"
android:exported="true">
</receiver>
</application>
Main Activity
package com.biapps.makin_biscuits;
import android.service.notification.NotificationListenerService;
import android.app.NotificationManager;
import android.content.Context;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
//set object labels and states here
private ImageButton icon;
private AudioManager am;
private ImageButton people;
private ImageButton ring;
private NotificationManager nm;
private NotificationListenerService nls;
IncomingCallReceiver broadCastReceiver = new IncomingCallReceiver();
SmsListener smsReceiver = new SmsListener();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
icon = (ImageButton) findViewById(R.id.icon);
icon.setOnClickListener(imgButtonHandler);
people = (ImageButton) findViewById(R.id.people);
//people.setOnClickListener(peopleButtonHandler);
ring = (ImageButton) findViewById(R.id.ring);
}
int buttonstate = 0;
public View.OnClickListener imgButtonHandler = new View.OnClickListener() {
public void onClick(View v) {
if (buttonstate == 0) {
icon.setImageResource(R.drawable.buttonup);
buttonstate = 1;
am.setRingerMode(0);
registerReceiver(broadCastReceiver, new IntentFilter(
"android.intent.action.PHONE_STATE"));
registerReceiver(smsReceiver, new IntentFilter(
"android.intent.action.DATA_SMS_RECEIVED"));
registerReceiver(smsReceiver, new IntentFilter(
"android.provider.Telephony.SMS_RECEIVED"));
registerReceiver(smsReceiver, new IntentFilter(
"android.provider.Telephony.DATA_SMS_RECEIVED"));
Toast.makeText(getApplicationContext(),"Diving!", `Toast.LENGTH_SHORT)`
.show();
} else {
icon.setImageResource(R.drawable.button);
buttonstate = 0;
am.setRingerMode(2);
unregisterReceiver(broadCastReceiver);
unregisterReceiver(smsReceiver);
Toast.makeText(getApplicationContext(),"Surfacing!", Toast.LENGTH_SHORT)
.show();
}
}
};}
SmsListener
package com.biapps.makin_biscuits;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.provider.Telephony;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;
import android.telephony.TelephonyManager;
public class SmsListener extends BroadcastReceiver {
private static final String TAG = "SmsListener";
public static final String SMS_BUNDLE = "pdus";
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "ON SMS RECEIVE BROADCAST", Toast.LENGTH_LONG).show();
Log.i(TAG, "SmsListener - onReceiveCalled");
}}
Try following way with highest reading priority value,
<receiver android:name=".SmsListener"
android:enabled="true"
android:exported="true"
android:permission="android.permission.READ_SMS">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
This will surely solve out your problem.
Update from below comment,
Since you are checking on Android version 6.0.1 just follow these steps,
Go to Settings,
Go to Apps
Select your Application
Choose Permissions Option
Enable SMS permission
After spending more than an hour I found that RECEIVE_SMS permission is required.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.RECEIVE_SMS},
MY_PERMISSIONS_REQUEST_SMS_RECEIVE);
Prioirty is not required to be set. This should work.
Found a solution.
First make another app your default SMS app.
Then: Google Hangout --> Settings (Disable merged conversations) --> SMS (Disable SMS)
You are registering broadcast your in your Activity, so it won't work if your app is in background. you can remove this from your Activity and you can register it in Manifest.
ex:
<receiver android:name=".SmsListener">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
Along with this add permission to recieve sms.
Try this, and it will work

Unfortunately, app has stopped

Unfortunately, app has stopped. The purpose of the app is to display a web page when it is launched. I have researched this problem, and tried changing code in the manifest file. I have been unsuccessful at eliminating this message.
MainActivity.java
package com.example.testb1;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
import android.net.Uri;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState)
{
Intent getmobilepages = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("http://www.mcohio.org/government/auditor/mobile_app/home.cfm");
getmobilepages.setData(uri);
startActivity(getmobilepages);
}
}
testb1 Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testb1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.testb1.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.getmobilepages" />
</intent-filter>
</activity>
</application>
</manifest>
Edit: I tried running your code and was completely wrong. You are just missing the line:
super.onCreate(savedInstanceState);
At the start of your oncreate method. Add that in and it should compile just fine.
Make sure to post your logcat in the future, the error is identified clearly there.
You have not called super you will get SuperNotCalled Exception. You need to set you layout. Better to start another activity on button click.
Add internet permission in manifest
<uses-permission android:name="android.permission.INTERNET"/>
MainActivty
public class MainActivity extends Activity {
Button b;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// call super
setContentView(R.layout.activity_main);
// set your layout
b = (Button) findViewById(R.id.button1);
//get button id
b.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// do something
Intent getmobilepages = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("http://www.mcohio.org/government/auditor/mobile_app/home.cfm");
getmobilepages.setData(uri);
startActivity(getmobilepages);
}
});
}
}

Categories